<template>
	<view class="center">
		<!-- 车辆信息 -->
		<view class="information">
			<view class="c-row">
				<text class="tit">货车信息</text>
				<view class="con-list">
					<image v-bind:src="opencar" class="open" opencarboolean @click="opencarclick"></image>
				</view>
			</view>
		</view>
		<view class="informations" v-if="opencarboolean == true" v-for="(item , index) in driverCarInfoList"
			:Key="index">
			<view class="c-row ">
				<text class="tit">车辆 -{{index+1}}</text>
				<view class="con-list">
					<image src="../../static/img/jiaoyi/shanchu@2x.png" class="eliminate" @click="carDel(index)" ></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">车牌号</text>
				<view class="con-list">
					<input placeholder="请填写车牌号" name="input" v-model="item.carNumber"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">车型</text>
				<picker @change="ModelChange" :value="ModelIndex" :range="ModelType" class="con-list">
					<view class="picker " v-model="item.carModel">
						{{ModelIndex>-1?ModelType[ModelIndex]:'请选择车型'}}
					</view>
				</picker>
				<!-- </view> -->
			</view>
			<view class="c-row b-b">
				<text class="tit">不含车头车长（米）</text>
				<picker @change="carLongChange" :value="carLongIndex" :range="carLongType" class="con-list">
					<view class="picker" v-model="item.carLength">
						{{carLongIndex>-1?carLongType[carLongIndex]:'请选择车长'}}
					</view>
				</picker>
			</view>
			<view class="c-row b-b">
				<text class="tit">载重（吨）</text>
				<view class="con-list">
					<input placeholder="请填写载重（吨）" name="input" v-model="item.carLoad"></input>
				</view>
			</view>
			<view class="c-row ">
				<text class="tit">出厂年份</text>
				<view class="con-list">
					<input placeholder="请填写出厂年份" name="input" v-model="item.yearManufacture"></input>
				</view>
			</view>
		</view>
		<button class="btn" v-if="opencarboolean == true" @click="carAdd">
				 <image src="../../static/img/jiaoyi/ic_fabu@3x.png" class="add" style="top: 8px;"></image> 
				 <texe>添加车辆</texe>
				 </button>
		<!-- 账户信息 -->
		<view class="information">
			<view class="c-row">
				<text class="tit">账户信息</text>
				<view class="con-list">
					<image v-bind:src="openuser" class="open" openuserboolean @click="openuserclick"></image>
				</view>
			</view>
		</view>

		<view class="informations" v-if="openuserboolean == true" v-for="(items , index) in driverPayeeInfoList"
			:Key="index">
			<!-- <view class="labels"> 账户 -？</view> -->
			<view class="c-row ">
				<text class="tit">账户 -{{index+1}}</text>
				<view class="con-list">
					<image src="../../static/img/jiaoyi/shanchu@2x.png" class="eliminate" @click="userDel(index)"></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">账户类型</text>
				<view class="con-list">
					<input placeholder="请填写账户类型" name="input" v-model="items.accountType"></input>
				</view>
			</view>
			<view class="c-row b-b"> 
				<text class="tit">银行卡照片（可选）</text>
				<view class="con-list">
					<!-- <input placeholder="请上传照片" name="input" v-model="items.payeeAddressUrl" @clisk="bankimg(items)"></input> -->
					<view  v-if="bankimg == ''"  @click="bankimgs(index)">请上传照片</view>
					<view  v-if="bankimg != ''" @click="bankimgs(index)">
						<image v-bind:src="bankimg" style="width: 40px; height: 40px;"></image>
					</view>
					
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">银行卡号</text>
				<view class="con-list">
					<input placeholder="请输入银行卡号" name="input" v-model="items.bankCard"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">开户行</text>
				
				<view class="con-list">
					<input placeholder="请输入开户行" name="input" v-model="items.bankDeposit"></input>
				</view>
			
			</view>
			<view class="c-row b-b">
				<text class="tit">开户支行</text>
				<picker @change="bankChange" :value="bankIndex" :range="bankType" class="con-list">
				<view class="con-list">
					{{bankIndex>-1?bankType[bankIndex]:'请选择开户支行'}}
				</view>
					</picker>
			</view>
			<view class="c-row b-b">
				<text class="tit">收款人姓名</text>
				<view class="con-list">
					<input placeholder="请输入收款人姓名" name="input" v-model="items.payeeName"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">收款人身份证号</text>
				<view class="con-list">
					<input placeholder="请输入收款人身份证号" name="input" v-model="items.payeeNumberCard"></input>
				</view>
			</view>
		</view>
		<button class="btn" v-if="openuserboolean == true" @click="userAdd()">
			 <image src="../../static/img/jiaoyi/ic_fabu@3x.png" class="add" style="top: 8px;"></image> 
			<text style="margin-top: -2px;">添加账户</text>
			</button>
		 <button class="btns btn"  @click="jumpUrl">下一步</button>
	</view>
	   
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				opencar: "../../static/img/authentication/down2@3x.png",
				openuser: "../../static/img/authentication/down2@3x.png",
				opencarboolean: false,
				openuserboolean: false,
				driverCarInfoList: [{
					carNumber: '',
					carModel: "高栏",
					carLength: "13",
					carLoad: "",
					yearManufacture: "",
				}],
				driverPayeeInfoList: [
					{
						accountType:"",
						cardAddressUrl:"",
						bankCard:"",
						bankDeposit:"",
						bankDepositBranch:"",
						payeeName:"",
						payeeNumberCard:"",
					}
				],
				ModelIndex: 0,
				Model: '',
				ModelType: ["高栏", "集装箱", "自卸车"],
				carLong: '',
				carLongIndex: 0,
				carLongType: ['13', '9.6', '8.2', '8.7', '11.7', '12.5', '13.7', '15', '16', '17.5'],
				DriverViewInfo:{},
				bankimg:"",
				bankImgs1:{},
				bankIndex:-1,
				bankType:[],
			}
		},
		onLoad(options){
			this.DriverViewInfo = JSON.parse(options.DriverViewInfo)
		},
		methods: {
			bankimgs(items){
				console.log(items)
				var that = this
				wx.chooseImage({
					success: function(res) {
						wx.uploadFile({
							url: 'https://www.zthymaoyi.com/upload/admin',
							filePath: res.tempFilePaths[0],
							name: 'file',
							success(res) {
								var data = res.data
								var strToObj = JSON.parse(data)
								// that.id[0] = strToObj.url
								that.bankimg = strToObj.url
								 that.bankImgs1.bankImg = strToObj.url
								that.$api.doRequest('get', '/driverViewInfo/bankShibie', that.bankImgs1).then(res => {
									console.log(res)
									that.$set(that.driverPayeeInfoList[items],'bankCard',res.data.data.bankNo)
									that.$set(that.driverPayeeInfoList[items],'bankDeposit',res.data.data.bankName)
		
									that.bankType = res.data.data.bankNameZhihang
									console.log(that.ban)
								}).catch(res => {
									uni.showToast({
										title: res.data.message,
										icon: 'none',
										duration: 2000
									})
								})
							}
						})
					}
				})	
			},
			jumpUrl(){
				for(var i = 0 ; i < this.driverCarInfoList.length ; i++){
					if (!this.driverCarInfoList[i].carNumber) {
						this.$api.msg('车牌号不能为空')
						return
					}
					if (!this.driverCarInfoList[i].carModel) {
						this.$api.msg('车型不能为空')
						return
					}
					if (!this.driverCarInfoList[i].carLength) {
						this.$api.msg('车长不能为空')
						return
					}
					if (!this.driverCarInfoList[i].carLoad) {
						this.$api.msg('载重不能为空')
						return
					}
					if (!this.driverCarInfoList[i].yearManufacture) {
						this.$api.msg('出厂年份不能为空')
						return
					}
				}
				for(var i = 0 ; i < this.driverPayeeInfoList.length ; i++){
					if (!this.driverPayeeInfoList[i].accountType) {
						this.$api.msg('账户类型不能为空')
						return
					}
					// if (!this.driverCarInfoList[i].cardAddressUrl) {
					// 	this.$api.msg('银行卡照片不能为空')
					
					// }
					if (!this.driverPayeeInfoList[i].bankCard) {
						this.$api.msg('银行卡号不能为空')
						return
					}
					if (!this.driverPayeeInfoList[i].bankDeposit) {
						this.$api.msg('开户行不能为空')
						return
					}
					if (!this.driverPayeeInfoList[i].bankDepositBranch) {
						this.$api.msg('开户支行不能为空')
						return
					}
					if (!this.driverPayeeInfoList[i].payeeName) {
						this.$api.msg('收款人姓名不能为空')
						return
					}
					if (!this.driverPayeeInfoList[i].payeeNumberCard) {
						this.$api.msg('收款人身份证号不能为空')
						return
					}
				}
					this.DriverViewInfo.driverCarInfoList = this.driverCarInfoList
					this.DriverViewInfo.driverPayeeInfoList = this.driverPayeeInfoList
					this.DriverViewInfo.driverPayeeInfoList.payeeAddressUrl = this.bankimg
					var model = JSON.stringify(this.DriverViewInfo);
					console.log(this.DriverViewInfo,"sjijsoi")
					return
				uni.navigateTo({
					url: `/pageD/identity/driverIdentityThree?DriverViewInfo=` + model
				})
			},
			carAdd() {
				this.driverCarInfoList.push({
					carNumber: '',
					carModel: "",
					carLength: "",
					carLoad: "",
					yearManufacture: "",
				})
			},
			userAdd() {
				this.driverPayeeInfoList.push({
					accountType:"",
					cardAddressUrl:"",
					bankCard:"",
					bankDeposit:"",
					bankDepositBranch:"",
					payeeName:"",
					payeeNumberCard:"",
				})
			},
			carDel(index) {
				if (this.driverCarInfoList.length > 1) {
					this.driverCarInfoList.splice(index, 1)
				}
			},
			userDel(index) {
				if (this.driverPayeeInfoList.length > 1) {
					this.driverPayeeInfoList.splice(index, 1)
				}
			},
			ModelChange(e) {
				this.ModelIndex = e.detail.value
				this.Model = this.ModelType[this.ModelIndex];
				
				this.driverCarInfoList[this.driverCarInfoList.length - 1].carModel = this.ModelType[this.ModelIndex];
			},
			bankChange(e) {
				this.bankIndex = e.detail.value
				this.Model = this.bankType[this.bankIndex];	
				this.driverPayeeInfoList[this.driverPayeeInfoList.length - 1].bankDepositBranch = this.bankType[this.bankIndex];
			},
			carLongChange(e) {
				this.carLongIndex = e.detail.value
				this.carLong = this.carLongType[this.carLongIndex];
				this.driverCarInfoList[this.driverCarInfoList.length - 1].carLength = this.carLongType[this.carLongIndex];
			},
			opencarclick() {
				if (this.opencarboolean == false) {
					this.opencarboolean = true;
					this.opencar = "../../static/img/authentication/up2%20(3).png"
				} else if (this.opencarboolean == true) {
					this.opencarboolean = false;
					this.opencar = "../../static/img/authentication/down2@3x.png"
				}
			},
			openuserclick() {
				if (this.openuserboolean == false) {
					this.openuserboolean = true;
					this.openuser = "../../static/img/authentication/up2%20(3).png"
				} else if (this.openuserboolean == true) {
					this.openuserboolean = false;
					this.openuser = "../../static/img/authentication/down2@3x.png"
				}
			}
		}
	}
</script>

<style scoped>
	.center {
		padding: 10px 20px;
		background-color: #F5F6FA;
	}

	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
		line-height: 36px;
	}

	.con-list {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		color: #AFB3BF;
		line-height: 40rpx;
		text-align: right;
		padding-right: 20rpx;
		font-size: 14px;
	}

	.open {
		width: 30px;
		height: 20px;
	}

	.information {
		margin-top: 10px;
		width: 100%;
		height: 56px;
		background-color: #FFFFFF;
		border-radius: 16px;
	}

	.informations {
		margin-top: 10px;
		background-color: #FFFFFF;
		border-radius: 20px;
	}

	.btn {
		margin-top: 10px;
		background-color: #FFFFFF;
		border-radius: 25px;
		border: none;
	}
	.btns{
		background-color: #22C572;
	}
	.add{
		width: 26px;
		height: 26px;

		/* background-image: url(../../static/img/jiaoyi/ic_fabu@3x.png); */
	}

	/* 清除 */
	.eliminate {
		width: 20px;
		height: 20px;
		float: right;
	}
	.bankImg{
		width: 20px;
		height: 20px;
	}

</style>
