<template>
  <view class="containers" >
	  <view class="header">
	   <view class="header_info">
		 <view class="header_info_icon" @click.native.stop.prevent="toBack" style="display: flex; justify-content: center; align-items: center;">
		 	<uni-icons  type="left" size="30" color="#c2d4de"  > </uni-icons>
		 </view>
				  <text class="header_text">付款信息</text>
	   </view>
	  </view>
	  
	  <view class="section" style="margin-top: 5%;">
	       <view class="form-item">
	         <text class="label">付款方式</text>
	         <l-radio :checked="clientInfo.payType === '全款'" label="全款" fontSize="1rem" style="transform: scale(0.7);">
				 <template #icon="{checked}">
				    <image v-show="checked" style="width:1.2rem; height:1.2rem;" src="/static/image/xuanzhong.png"></image>
				     <image v-show="!checked" style="width:1.2rem; height:1.2rem" src="/static/image/weixuanzhong.png"></image>
				 </template>
				 </l-radio>
	       </view>
	       <view class="form-item">
	         <text class="label">客户类型</text>
	         <l-radio-group  @change="onChange" class="radio-group" >
	             <l-radio :checked= "clientInfo.custType == 0?true:false" value="个人" label="个人" fontSize="1rem" style="margin-right: 1rem;  transform: scale(0.7);">
					 <template #icon="{checked}">
					    <image v-show="checked" style="width:1.2rem; height:1.2rem;" src="/static/image/xuanzhong.png"></image>
					     <image v-show="!checked" style="width:1.2rem; height:1.2rem" src="/static/image/weixuanzhong.png"></image>
					 </template>
					 </l-radio>
	             <l-radio :checked= "clientInfo.custType == 1?true:false" value="公司" label="公司"   fontSize="1rem" style="transform: scale(0.7);">
					 <template #icon="{checked}">
					    <image v-show="checked" style="width:1.2rem; height:1.2rem;" src="/static/image/xuanzhong.png"></image>
					     <image v-show="!checked" style="width:1.2rem; height:1.2rem" src="/static/image/weixuanzhong.png"></image>
					 </template>
					 </l-radio>
	         </l-radio-group>
	       </view>
	    </view>
	  
	  <view class="idCard-box">
	  	<view class="reverse">
	  		<image :src="clientInfo.certFront == ''?positiveImg:certFront"    @tap.prevent="uploadPositive">
	  		</image>
	  	</view>
	  	<view class="reverse">
	  		<image :src="clientInfo.certBack == ''?reverseImg:certBack" @tap.prevent="uploadReverse">
	  		</image>
	  	</view>
		<view class="reverse">
			<image :src="clientInfo.carPic == ''?carImg:carPic" @tap.prevent="uploadCarCert">
			</image>
		</view>
	  </view>
	  
    <!-- 客户基本信息 -->
    <view class="section">
    <view class="con_size">
		  <image src="/static/image/矩形 5315.png"  class='con_size_img' ></image>
		  客户基本信息
		  </view>
      <view class="form-item">
		 <text class="labels">*</text> 
        <text class="label">产品名称</text>
        <text class="value">{{ clientInfo.productName }}</text>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">经销商</text>
        <text class="value">{{ clientInfo.storeName }}</text>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">客户姓名</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange"  class="input" v-model="clientInfo.custName" placeholder="请输入客户姓名" />
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">居住地址</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.custAddress" placeholder="请输入居住地址" />
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">身份证号码</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.custCardNo" placeholder="请输入身份证号码" />
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">联系方式</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.custPhone" placeholder="请输入联系方式" />
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">销售端口</text>
        <l-radio-group class="radio-group" @change="handleDepartmentChange">
          <label class="radio-label" v-for="item in departments" :key="item">
            <l-radio :value="item"  :checked="clientInfo.salePort === item" >
			  <template #icon="{checked}">
			   <image v-show="checked" style="width:1.2rem; height:1.2rem;" src="/static/image/xuanzhong.png"></image>
			    <image v-show="!checked" style="width:1.2rem; height:1.2rem" src="/static/image/weixuanzhong.png"></image>
			</template>
			</l-radio>
            <text style="margin-left:0.2rem;">{{ item }}</text>
          </label>
        </l-radio-group>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">促销销售顾问</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.saleName" placeholder="请输入店铺销售顾问" />
      </view>
    </view>

    <!-- 车辆信息 -->
    <view class="section">
            <view class="con_size">
		  <image src="/static/image/矩形 5315.png"  class='con_size_img' ></image>车辆信息</view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">车牌车系</text>
        <picker class="picker" @change="bindCarBrandChange" :value="carBrandIndex" :range="carBrands">
          <view class="picker-text">{{ clientInfo.appOrderCarList[0].carSeries || '请选择车辆品牌 >' }}</view>
        </picker>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">车架号</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].vin" placeholder="请填写车架号" />
      </view>
	  
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">使用性质</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].useType" placeholder="请填写使用性质" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">是否新车</text>
		<l-radio-group  @change="onChanges" class="radio-group" >
		    <l-radio :checked= "clientInfo.appOrderCarList[0].newCar == 1?true:false" value="是" label="是" fontSize="1rem" style="margin-right: 1rem;  transform: scale(0.7);">
							 <template #icon="{checked}">
							    <image v-show="checked" style="width:1.2rem; height:1.2rem;" src="/static/image/xuanzhong.png"></image>
							     <image v-show="!checked" style="width:1.2rem; height:1.2rem" src="/static/image/weixuanzhong.png"></image>
							 </template>
							 </l-radio>
		    <l-radio :checked= "clientInfo.appOrderCarList[0].newCar == 0?true:false" value="否" label="否"   fontSize="1rem" style="transform: scale(0.7);">
							 <template #icon="{checked}">
							    <image v-show="checked" style="width:1.2rem; height:1.2rem;" src="/static/image/xuanzhong.png"></image>
							     <image v-show="!checked" style="width:1.2rem; height:1.2rem" src="/static/image/weixuanzhong.png"></image>
							 </template>
							 </l-radio>
		</l-radio-group>
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">车辆型号</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].carModel" placeholder="请选择车辆型号" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">车牌号</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].carNo" placeholder="请输入车牌号" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">发动机号</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].engineNo" placeholder="请输入发动机号" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">里程</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].mileage" placeholder="请输入里程" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">购车时间</text>
		<uni-datetime-picker  type="datetime" v-model="clientInfo.appOrderCarList[0].buyTime"   :clearIcon="false" :border="false">
		</uni-datetime-picker>
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">车辆购置价</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].buyMoney" placeholder="请输入车辆购置价" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">购置税</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderCarList[0].buyTax" placeholder="请输入购置税" />
	  </view>
    </view>
	<!-- 凭证信息 -->
	<view class="section">
	        <view class="con_size">
		  <image src="/static/image/矩形 5315.png"  class='con_size_img' ></image>凭证信息</view>
	 <view class="form-item">
	 		  <text class="labels">*</text> 
	   <text class="label">第一受益人</text>
	    <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].firstBeneficiary" placeholder="请输入第一受益人" />
	 </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">服务费</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].lenderMoney" placeholder="请输入服务费" />
	  </view>
	  <view class="form-item">
		  <text class="labels">*</text> 
	    <text class="label">生效时间</text>
		<uni-datetime-picker  type="datetime" v-model="clientInfo.appOrderVoucherList[0].effectiveTime"   :clearIcon="false" :border="false">
		</uni-datetime-picker>
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">失效时间</text>
		<uni-datetime-picker  type="datetime" v-model="clientInfo.appOrderVoucherList[0].endTime"   :clearIcon="false" :border="false">
		</uni-datetime-picker>
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">服务年限</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].serviceYear" placeholder="请输入服务年限" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">权益套餐</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].equityPackage" placeholder="请输入权益套餐" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">套餐费用</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].packageMoney" placeholder="请输入套餐费用" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">商业车损险编号</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].carInsuranceNo" placeholder="请输入商业车损险编号" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">上牌城市</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].registeredCity" placeholder="请输入上牌城市" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">保司名称</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].insuranceName" placeholder="请输入保司名称" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">受让人姓名</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].assigneeName" placeholder="请输入受让人姓名" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">受让人联系电话</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].assigneePhone" placeholder="请输入受让人联系电话" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">受让人身份证</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].assigneeCardNo" placeholder="请输入受让人身份证" />
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">付款时间</text>
	  <uni-datetime-picker  type="datetime" v-model="clientInfo.appOrderVoucherList[0].payTime"   :clearIcon="false" :border="false">
	  </uni-datetime-picker>
	  </view>
	  <view class="form-item">
	  		  <text class="labels">*</text> 
	    <text class="label">经销商地址</text>
	     <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderVoucherList[0].dealerAddress" placeholder="请输入经销商地址" />
	  </view>
	</view>
	
	<!-- 金融信息 -->
    <view class="section">
            <view class="con_size">
		  <image src="/static/image/矩形 5315.png"  class='con_size_img' ></image>金融信息</view>
     <view class="form-item">
     		  <text class="labels">*</text> 
       <text class="label">贷款机构</text>
        <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderFinanceList[0].lender" placeholder="请输入贷款机构" />
     </view>
      <view class="form-item">
      		  <text class="labels">*</text> 
        <text class="label">贷款金额</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderFinanceList[0].lenderMoney" placeholder="请输入贷款金额" />
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">贷款期限</text>
         <input adjust-position="false" @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.appOrderFinanceList[0].lenderYear" placeholder="请输入贷款期限" />
      </view>
    </view>


    <!-- 产品描述 -->
    <view class="section">
            <view class="con_size">
		  <image src="/static/image/矩形 5315.png"  class='con_size_img' ></image>产品信息</view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">产品名称</text>
        <text class="value">{{ clientInfo.productName }}</text>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">服务年龄</text>
        <picker class="picker" @change="bindServiceAgeChange" :value="serviceAgeIndex" :range="serviceAges">
          <view class="picker-text">{{ serviceAges[serviceAgeIndex] || '请选择服务年限 >' }}</view>
        </picker>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">销售金额</text>
			<input adjust-position="false"  @keyboardheightchange="keyboardheightchange" class="input" v-model="clientInfo.productMoney" placeholder="请输入销售金额" />
      </view>
    </view>

    <!-- 付款信息 -->
    <view class="section">
            <view class="con_size">
		  <image src="/static/image/矩形 5315.png"  class='con_size_img' ></image>付款信息</view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">收款方</text>
        <picker class="picker" @change="bindPayeeChange" :value="payeeIndex" :range="payees">
          <view class="picker-text">{{ this.clientInfo.payee || '请选择收款方 >' }}</view>
        </picker>
      </view>
      <view class="form-item">
		  <text class="labels">*</text> 
        <text class="label">付款时间</text>
        <uni-datetime-picker  type="datetime" v-model="clientInfo.payeeTime"   :clearIcon="false" :border="false">
		</uni-datetime-picker>
      </view>
	  
	  <view class="con_size">
		  <text class="labels">*</text> 
		  <text class="label">支付凭证</text>
	  	<uv-upload
	  			:fileList="fileList1"
	  			name="1"
	  			multiple 
	  			:maxCount="1"
	  			@afterRead="afterRead" 
	  			@delete="deletePic" 
	  		><image 
			src="/static/image/组件 5 – 1.png" 
			mode="widthFix" 
			style="width: 100px;height: 150px;"
		></image></uv-upload>
	  </view>
	  
    </view>

	<view class="sections">
		<view class="form-button">
			<button class=" button" @click="get_to" style="width: 60%;">提交去录单</button>
		</view>
	</view>
	
	
  </view>
</template>

<script>
	import {idCardInfo,carCert,upload,getChildListBatch,add,isToken} from '@/api.uts'
export default {
  data() {
    return {
		uploadConfig:{
		  // 上传地址
		  url:'https://gpt.aiym.run/contract/miniapp/file/upload',
		  // 文件字段名
		  name: 'file',
		  // 请求头
		  header: {},
		  // 附带的表单数据
		  formData: {
		  	'biz': 'cert'
		  },
		  // 是否开启实际上传
		  enabled: true
		},
      clientInfo: {
		     appOrderCarList: [
		      {
		        buyMoney: 0,
		        buyTax: 0,
		        buyTime: "",
		        carModel: "",
		        carNo: "",
		        carSeries: "",
		        carType: "",
		        createBy: "",
		        createTime: "",
		        engineNo: "",
		        id: "",
		        mileage: "",
		        newCar: 0,
		        orderFkId: "",
		        sysOrgCode: "",
		        updateBy: "",
		        updateTime: "",
		        useType: "",
		        vin: ""
		      }
		    ],
		    appOrderFinanceList: [
		      {
		        createBy: "",
		        createTime: "",
		        id: "",
		        lender: "",
		        lenderMone: 0,
		        lenderYear: "",
		        orderFkId: "",
		        sysOrgCode: "",
		        updateBy: "",
		        updateTime: ""
		      }
		    ],
		    appOrderVoucherList: [
		      {
		        assigneeCardNo: "",
		        assigneeName: "",
		        assigneePhone: "",
		        carInsuranceNo: "",
		        createBy: "",
		        createTime: "",
		        dealerAddress: "",
		        effectiveTime: "",
		        endTime: "",
		        equityPackage: "",
		        firstBeneficiary: "",
		        id: "",
		        insuranceName: "",
		        orderFkId: "",
		        packageMoney: 0,
		        payTime: "",
		        registeredCity: "",
		        serviceMoney: 0,
		        serviceYear: "",
		        sysOrgCode: "",
		        updateBy: "",
		        updateTime: ""
		      }
		    ],
		    busLicense: "",
		    carPic: "",
		    certBack: "",
		    certFront: "",
		    contractUrl: "",
		    createBy: "",
		    createTime: "",
		    custAddress: "",
		    custCardNo: "",
		    custName: "",
		    custPhone: "",
		    custType: 0,
		    id: "",
		    orderNum: "",
		    payType: '全款', // 默认选中全款
		    payVoucherUrl: "",
		    payee: "",
		    payeeTime: "",
		    productContractTemp: "",
		    productMone : null,
		    productName: "自动填写所选商品服务分类",
		    productServiceYear: 1,
		    saleName: "",
		    salePort: ''||"售前",
		    status: 0,
		    storeName: "自动填写所选择的门店",
		    sysOrgCode: "",
		    updateBy: "",
		    updateTime: ""
      },
	  fileList1:[],     
      departments: ['售前', '售后', '二网车'],
      carBrands: [],
      carBrandIndex: -1,
      serviceAges: ['1年', '2年', '3年'],
      serviceAgeIndex: -1,
      payees: [],
      payeeIndex: -1,
	   screenHeight: 0, //屏幕可视高度
	curHeight: 0, //页面需要的动态高
	  // 扫描
	  positiveImg: '/static/image/组件 4 – 1.png',//自己图片路径
	  certFront:'',
	  certBack:'',
	  // 反面身份证
	  reverseImg: '/static/image/组 71663.png', //自己图片路径
	  // 行车驾驶证
	  carImg: '/static/image/组件 2 – 1.png' //自己图片路径
    }
  },
  mounted() {
	  isToken();
  	this.clientInfo.storeName = getApp().storeName || "自动填写所选择的门店";
	this.clientInfo.productName = getApp().productName || "自动填写所选商品服务分类";
	this.clientInfo.appOrderVoucherList[0].dealerAddress = getApp().dealerAddress;
	this.clientInfo.productContractTemp = getApp().productUrl;
	for (var index = 0; index < getApp().allMsg.length; index++) {
		this.payees.push(getApp().allMsg[index].storeName);
	}
	this.clientInfo.payee = getApp().storeName;
	this.uploadConfig.header = {
			'X-Access-Token':uni.getStorageSync('token')
	}
	getChildListBatch().then((res)=>{
		this.carBrands = [];
		for (var index = 0; index < res.result.records.length; index++) {
			this.carBrands.push(res.result.records[index].name);
		}
	})
	
  },
  onLoad(options) {
      	//监听键盘事件
          uni.onKeyboardHeightChange(res => {
              if (res.height > 0) {
                  //键盘弹出 调整页面位置
                  this.curHeight = this.screenHeight - res.height
              } else {
                  // 键盘收起  恢复页面位置
                  this.curHeight = this.screenHeight
              }
          });
      },
      onUpload() {
          // 页面销毁时移除监听
          uni.offKeyboardHeightChange();
      },
  methods: {
	  keyboardheightchange(e){
		  this.changeBottomVal = e.detail.height + 'px'
	  },
	  // 凭证上传函数
	  deletePic(event) {
	  				this[`fileList${event.name}`].splice(event.index, 1)
	  			},
	  			// 新增图片
	  			async afterRead(event) {
	  				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
	  				let lists = [].concat(event.file)
	  				let fileListLen = this[`fileList${event.name}`].length
	  				lists.map((item) => {
	  					this[`fileList${event.name}`].push({
	  						...item,
	  						status: 'uploading',
	  						message: '上传中'
	  					})
	  				})
	  				for (let i = 0; i < lists.length; i++) {
	  					const result = await this.uploadFilePromise(lists[i].url)
	  					let item = this[`fileList${event.name}`][fileListLen]
	  					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
	  						status: 'success',
	  						message: '',
	  						url: result
	  					}))
	  					fileListLen++
	  				}
	  			},
	  			uploadFilePromise(url) {
					let token = uni.getStorageSync('token')
	  				return new Promise((resolve, reject) => {
	  					let a = uni.uploadFile({
	  						url: 'https://www.shengchuangyunkong.com/contract/miniapp/file/upload', // 仅为示例，非真实的接口地址
	  						filePath: url,
	  						name: 'file',
	  						formData: {
	  							biz: 'test'
	  						},
							header:{
								'X-Access-Token':token
							},
	  						success: (res) => {
								this.clientInfo.payVoucherUrl = JSON.parse(res.data).message;
	  							setTimeout(() => {
	  								resolve(res.data.data)
	  							}, 1000)
	  						}
	  					});
	  				})
	  			},
	  get_to(){
		  add(JSON.parse(JSON.stringify(this.clientInfo))).then((res)=>{
		  })
		uni.switchTab (
		{ url: '/pages/index/dingdan' }
		)
	  },
	  toBack(){
	  let canNavBack = getCurrentPages()
	  if( canNavBack && canNavBack.length>1) {  
	      uni.navigateBack() 
	  } else {  
	      history.back();  
	  } 
	  },
    handleDepartmentChange(e) {
      this.clientInfo.salePort = e;
    },
	// 修改车辆品牌
    bindCarBrandChange(e) {
      this.carBrandIndex = e.detail.value
	  this.clientInfo.appOrderCarList[0].carSeries = this.carBrands[this.carBrandIndex];
    },
	// 取服务年限
    bindServiceAgeChange(e) {
      this.serviceAgeIndex = e.detail.value
	  if(this.serviceAges[e.detail.value] == '1年'){
		  this.clientInfo.productServiceYear = 1;
	  }else if(this.serviceAges[e.detail.value] == '2年' ){
		  this.clientInfo.productServiceYear = 2;
	  }else{
		  this.clientInfo.productServiceYear = 3;
	  };
	  
    },
	// 选择收款方
    bindPayeeChange(e) {
      this.payeeIndex = e.detail.value
	  this.clientInfo.payee= this.payees[e.detail.value];

    },
	// 身份证正面上传
	uploadPositive() {
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: (res) => {
			let filePath = res.tempFilePaths[0];
			let token = uni.getStorageSync('token');
				this.uploadIdentify(token,'front',filePath,'sfz');
			}
		})
	},
	// 身份证反面上传
	uploadReverse() {
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: (res) => {
				let filePath = res.tempFilePaths[0];
				let token = uni.getStorageSync('token');
					this.uploadIdentify(token,'back',filePath,'sfz')
			}
		})
	},
	
	uploadCarCert() {
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: (res) => {
				let filePath = res.tempFilePaths[0];
				let token = uni.getStorageSync('token');
					this.uploadIdentify(token,'',filePath,'carCert')
			}
		})
	},
	// 上传识别
	uploadIdentify(token,side,filePath,type) {
		uni.uploadFile({
					url: 'https://www.shengchuangyunkong.com/contract/miniapp/file/upload', //仅为示例，非真实的接口地址
					filePath:filePath,
					name: 'file',
					formData: {
						'biz': 'cert'
					},
					header:{
						'X-Access-Token':token
					},
					success: (res) => {
						let image = JSON.parse(res.data).message;
						console.log(image);
					if(type == "sfz"){
						idCardInfo({'side':side,'url':JSON.parse(res.data).message}).then((res)=>{
												 if(res.success){
													 if(side == 'front'){
														 this.clientInfo.custName   =res.result.name;
														 this.clientInfo.appOrderVoucherList[0].firstBeneficiary = res.result.name;
														 this.clientInfo.custAddress= res.result.address;
														 this.clientInfo.custCardNo = res.result.idCard ;
														 this.clientInfo.certFront = image;
														 this.certFront=filePath;
													 }else {
														 this.clientInfo.certBack=image;
														 this.certBack=filePath;
													 }
													
												 }else{
													 uni.showToast({
													           title: "身份证识别错误，请重新上传!",
													           icon: 'error',
													           duration: 500,
													           success: (res) => {
													           },
													           fail: (res) => {
													           },
													         })
												 }
						}).catch(err => {
												console.log("catch: ", err);
												})
					}else if(type == 'carCert' ){
						// 处理车辆信息
						carCert({'url':JSON.parse(res.data).message}).then((res)=>{
							if(res.success){	
								console.log('车辆号',res)
								// 车牌车系
								this.clientInfo.appOrderCarList[0].carSeries = res.result.CarBrand;
								// 车架号
								this.clientInfo.appOrderCarList[0].vin = res.result.VinNo;
								this.clientInfo.carPic = image;
								this.carPic = filePath;
								// 发动机号
								this.clientInfo.appOrderCarList[0].engineNo = res.result.EngineNo;
								// 车辆型号
								this.clientInfo.appOrderCarList[0].carModel = res.result.CarModel;

							}else{
							 uni.showToast({
							   title: "识别错误，请重新上传!",
							   icon: 'error',
							   duration: 500,
							   success: (res) => {
							   },
							   fail: (res) => {
							   },
							 })
							}
						}).catch((err)=>{
							console.log("catch: ", err);
						})
						
					}
					
					},
					fail:(err)=>{
						console.log(err)
					}
				});
	},
	onChange(e){
		console.log(e);
		if(e == '个人'){
			this.clientInfo.custType = 0;
		}else{
			this.clientInfo.custType = 1;
		}
	},
	onChanges(e){
		if(e == '是'){
			this.clientInfo.appOrderCarList[0].newCar = 1;
		}else{
			this.clientInfo.appOrderCarList[0].newCar = 0;
		}
	}
  }
}
</script>

<style  scoped lang="scss">
.containers {
	height: 100%;
	width: 100%;
  background-color: #fff;
  	overflow-y:scroll;
  
}
.footer {
	position: fixed;
	bottom: 0;
	left: 0;
}

.container::-webkit-scrollbar {
    display: none;
}
.section {
  // margin-bottom: 30rpx;
  border-bottom: 1rpx solid #eee;
  margin: 0 1rem 0 1rem;
}

.sections{
	  margin: 0 1rem 1rem 1rem;
}
.form-item {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 0.1rem solid #f2f2f2;
  color: #767676;
}
.labels{
	color: red;
	display: flex;
	justify-content: center;
	align-items: center;
}
.label {
  font-size: 28rpx;
  color: #666;
  width: 200rpx;
}

.input {
  flex: 1;
  text-align: right;
  font-size: 28rpx;
  color: #737373;
}

.picker {
  flex: 1;
}

.picker-text {
  text-align: right;
  color: #737373;
  font-size: 0.8rem;
}

.radio-group {
  display: flex;
  flex: 1;
  justify-content: flex-end;
  flex-direction: row;
}

.radio-label {
padding: 0;
  margin-left: 10rpx;
  display: flex;
  flex-direction: row;
  font-size: 1rem;
  transform: scale(0.7);
}

.value {
  flex: 1;
  text-align: right;
  color: #737373;
  font-size: 0.8rem;
}
// .timePiker{
// 	display: flex;
// 	justify-content: center;
// 	align-items: center; 
// 	color: #3f3f3f;
// }

.idCard-box {
	margin-top: 10%;
		width: 100%;
		height: 50%;
		display: flex;
		flex-direction: row;
		/* background-color: red; */
       flex-wrap: wrap;
 
		.reverse {
			height: 30%;
			width: 40%;
			display: flex;
			align-items: center;
			justify-content: center;
            // background-color: blue;
			margin: 0 5% 0 5%;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
	
	/* 表单分区样式 */
	.con_size {
	  font-size: 1rem;
	  font-weight: bold;
	  margin: 1rem 0;
	  color: #000000;
	  display: flex;
	  flex-direction: row;
	  align-items: center;
	}
	
	.con_size_img{
		height: 100%;
		width: 2%;
		margin-right: 2%;
	}
	
	
	.form-button{
		width: 100%;
		height:100%;
		// background-color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.button{
		height: 100%;
		width: 100%;
		background-color: #044f7a;
		color: #ffffff;
		border-radius: 1rem;
	}
</style>