<template>
	<view class="content">
		<view class="content3 flex s-row">
			<view class="title">上传银行卡卡号页</view>
			<view @click="uploadImg" class="picture picture3" v-if="!dataDetails.payeeAddressUrl">
				<image class="xj-image" src="@/static/images/mine/ic_shanchuan@2x.png"></image>
				<view class="text">上传银行卡卡号页</view>
			</view>

			<view v-if="dataDetails.payeeAddressUrl" @click.stop="uploadImg" class="preview-card-img picture">
				<!-- <image class="card-img" :src="dataDetails.cardAddressUrl"></image> -->
				<view @click.stop="delCard">
					<image class='del-card' src="@/static/images/common/quxiao@2x.png">
					</image>
				</view>
				<image class="" :src="dataDetails.payeeAddressUrl" mode="aspectFit"></image>
			</view>

			<view class="flex row">
				<view class="left-text">银行卡卡号</view>
				<view class="flex">
					<u--input placeholder="输入银行卡号码" inputAlign='left' border="none" v-model="dataDetails.bankCard">
					</u--input>
				</view>
			</view>
			<view class="flex row">
				<view class="left-text">开户行</view>
				<u--input placeholder="输入开户行" inputAlign='left' border="none" v-model="dataDetails.bankDeposit">
				</u--input>
			</view>
			<view class="flex row">
				<view class="left-text khzh-styel">开户支行</view>
				<view class="flex align-center" v-if="isShowManualInput">
					<u--input class="select-bankzh point" placeholder="输入开户支行" inputAlign='left' border="none"
						v-model="dataDetails.bankDepositBranch">
					</u--input>
					<view @click="manualInput" class="type">选择支行</view>
				</view>
				<view class="flex align-center" v-if="!isShowManualInput">
					<!-- 	<u--input  @click="selectZhbank" placeholder="选择开户支行" inputAlign='left' border="none" disabled>
					</u--input> -->
					<view class="select-bankzh" @click="selectZhbank">
						{{dataDetails.bankDepositBranch?dataDetails.bankDepositBranch:'选择开户支行'}}
					</view>
					<view @click="manualInput" class="type">手动输入</view>
				</view>

			</view>
			<view class="flex row noborder">
				<view class="left-text">收款人</view>
				<view class="flex">
					<u--input placeholder="输入收款人姓名" inputAlign='left' border="none" v-model="dataDetails.payeeName">
					</u--input>
				</view>
			</view>
			<u-picker :show="isShowBank" :columns="columns" :closeOnClickOverlay='true' @close='zhBankClose'
				@cancel='zhBankClose' @confirm='confirmBank'></u-picker>
			</u-picker>
			<view class="" style="color: red;font-size: 26rpx;margin-top: 20rpx;">*收款人须为司机本人</view>
		</view>

		<u-toast ref="uToast"></u-toast>
		<view class="submit-btn" @click="submit">提交</view>
		<u-action-sheet :actions="$helper.imgTypeList" :title="$helper.imgType" :show="isShowimgType"
			@select="imgTypeSelect" :closeOnClickOverlay="true" :closeOnClickAction="true" @close="isShowimgType=false">
		</u-action-sheet>
	</view>
</template>

<script>
	import upload from '@/components/upload.vue';
	import uploadImage from '@/components/ossutil/uploadFile.js';
	var _this;
	import {
		mapState
	} from 'vuex';
	export default {
		components: {},
		data() {
			return {

				isShowimgType: false,
				dataDetails: {
					driverId: '',
					payeeAddressUrl: '',
					bankCard: '',
					bankDeposit: '',
					bankDepositBranch: '',
					payeeName: '',
				},
				imagesrc: '',
				columns: [

				],
				isShowBank: false,
				isShowManualInput: false,
				index: ''
			};
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onLoad() {
			_this = this;
			this.dataDetails.driverId = this.userInfo.driverId
		},
		methods: {
			delCard() {
				_this.dataDetails.payeeAddressUrl = ''
				_this.$forceUpdate()
			},
			uploadImg(type, ) {
				this.uploadType = type
				this.isShowimgType = true

			},
			zhBankClose() {
				this.isShowBank = false
			},
			// 选择支行
			selectZhbank() {
				if (uni.$u.test.isEmpty(this.columns)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "请先上传银行卡！",
					})
					return true
				}

				this.isShowBank = true
			},
			confirmBank(e) {
				console.log(e)
				this.dataDetails.bankDepositBranch = e.value[0]
				this.isShowBank = false
			},
			manualInput() {
				if (this.isShowManualInput) {
					if (uni.$u.test.isEmpty(this.dataDetails.payeeAddressUrl)) {
						this.$refs.uToast.show({
							type: 'error',
							message: "请先上传银行卡！",
						})
						return true
					}
					this.isShowBank = true

				} else {
					this.isShowBank = false
				}
				this.isShowManualInput = !this.isShowManualInput
			},
			//设置图片
			setImage(e) {
				console.log(e);
				//显示在页面
				//this.imagesrc = e.path;
				if (e.dotype == 'idphoto') {
					_this.zjzClipper(e.path);
				} else if (e.dotype == 'watermark') {
					_this.watermark(e.path);
				} else {
					_this.savePhoto(e.path);
				}
			},
			//保存图片到相册，方便核查
			savePhoto(path) {
				this.imagesrc = path;
				uploadImage(path, 'appData/',
					result => {
						// 上传成功
						console.log('图片地址', result)
					}
				)
				//保存到相册
				// uni.saveImageToPhotosAlbum({
				// 	filePath: path,
				// 	success: () => {
				// 		uni.showToast({
				// 			title: '已保存至相册',
				// 			duration: 2000
				// 		});
				// 	}
				// });
			},
			uploadImg() {

				this.isShowimgType = true
			},

			imgTypeSelect(val) {
				console.log(val)
				if (val.name == '相册') {
					uni.chooseImage({
						count: 1,
						sourceType: this.$helper.chooseImage.sourceType,
						success: function(res) {
							console.log(JSON.stringify(res.tempFilePaths));
							uploadImage('image', res.tempFilePaths[0], 'appData/',
								result => {
									// 上传成功
									console.log('图片地址', result)
									_this.$request.baseRequest('get',
											'/driverInfo/bankShibie', {
												bankImg: result,
											}).then(res => {
											_this.dataDetails.payeeAddressUrl = result
											if (res.data.bankNo) {
												_this.dataDetails.bankCard = res.data.bankNo
											}
											if (res.data.bankName) {
												_this.dataDetails.bankDeposit = res.data.bankName
											}
											// 开户支行LIst
											if (res.data.bankNameZhihang) {
												_this.columns.push(res.data
													.bankNameZhihang)
											}
											_this.$forceUpdate()
										})
										.catch(res => {
											uni.$u.toast(res.message);
										});
								}
							)
						}
					});
				} else {
					uni.$u.route('/pages/mine/camera/idcard/idcard?dotype=bank');
				}
			},
			//身份证正面
			getImgUrl1(src) {
				// console.log(src)
				// console.log('------------res-----------')
				// let that = this;
				// that.id[0] = src
				// that.id1 = src
				// that.certificates = false
				// that.personImgs.personImg = that.id[0]
				// that.$api.doRequest('get', '/driverViewInfo/personShibie', that
				// 	.personImgs).then(res => {
				// 	if (res.data.data.recPerson != null) {
				// 		if (res.data.data.recPerson != "") {
				// 			that.$set(that.DriverViewInfo, 'driverName', res
				// 				.data.data.recPerson)
				// 		}
				// 	}
				// 	if (res.data.data.recPersonNo != null) {
				// 		if (res.data.data.recPersonNo != "") {
				// 			that.$set(that.DriverViewInfo, 'numberCard', res
				// 				.data.data.recPersonNo)
				// 		}
				// 	}
				// }).catch(res => {
				// 	uni.showToast({
				// 		title: res.data.message,
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// })
			},
			submit() {
				// // 获取银行卡颜色
				// let _obj = {
				// 	"input":this.dataDetails.payeeAddressUrl
				// }
				// this.$request.baseRequest('post', '/ClothingColorController/recognition', _obj)
				// 	.then(res => {
				// 		if (res.code == '200') {
				// 			this.dataDetails.cardColor = res.data

				// 		} else {
				// 			uni.$u.toast(res.message);
				// 		}

				// 	})
				// 	.catch(res => {
				// 		uni.$u.toast(res.message);
				// 	});
				
				
				if(this.dataDetails.payeeName != uni.getStorageSync("firstAuthentication").numberCard){
					this.$refs.uToast.show({
						type: 'error',
						message: "收款人须为司机本人！",
					})
					return
				}else{
					this.$request.baseRequest('get', '/driverPayeeInfo/bankCradShibie', {
						name: this.dataDetails.payeeName,
						idCard: uni.getStorageSync("firstAuthentication").numberCard,
						accountNo: this.dataDetails.bankCard
					}).then(
						res => {
							if(res.data.distinguishNum == "01"){
								this.dataDetails.commonId = this.userInfo.id
								this.$request.baseRequest('post', '/driverPayeeInfo/api/addInfo', this.dataDetails).then(
										res => {
											if (res.code == '200') {
												let params = {
													type: 'success',
													message: "提交成功",
												}
												this.$refs.uToast.show({
													...params
												})
												uni.$u.route('/pages/mine/manageBankCards/index');
								
											} else {
												uni.$u.toast(res.message);
											}
								
										})
									.catch(res => {
										uni.$u.toast(res.message);
									});
							}else{
								uni.$u.toast(res.data.distinguish);
							}
						})
				}
			},
		},
	};
</script>

<style scoped lang="scss">
	.row4-img {
		width: 32rpx;
		height: 32rpx;
	}

	.content {
		padding: 20rpx;
		padding-bottom: 50rpx;
	}

	.content3 {
		background: white;
		padding: 20rpx;
		box-sizing: border-box;

		.left-text {
			// background: red;
			width: 290rpx;
			color: #333333;
			display: flex;
			align-items: center;
		}

		.row {
			border-bottom: 1px solid #EEEEEE;
			padding-bottom: 28rpx;
			margin-top: 26rpx;

			.ch-style {}
		}

		.row-ch {
			padding-right: 180rpx;
			box-sizing: border-box;
		}
	}

	.title {
		color: #999999;
		margin: 20rpx 0;
	}

	.picture {
		margin-top: 20rpx;
		background: #F5F6FA;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #6A7282;
		width: 100%;
		height: 440rpx;
		position: relative;

		.text {
			margin-top: 20rpx;
		}
	}

	.xj-image {
		width: 100rpx;
		height: 100rpx;
	}

	.picture3 {
		background: url(../../../static/images/mine/yhkzm.png);
		background-size: 100% 100%;
	}

	.select-bankzh {
		width: 230rpx;
		// height: 48rpx;
	}

	.type {
		background: #2772FB;
		border-radius: 10rpx;
		color: white;
		box-sizing: border-box;
		padding: 4rpx 10rpx;
		font-size: 26rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 68rpx;
	}

	.submit-btn {
		position: fixed;
		bottom: 40rpx;
		width: 90%;
		background: #2772FB;
		color: white;
		text-align: center;
		margin-left: 5%;
		padding: 30rpx 0;
		border-radius: 50rpx;
	}

	.del-card {
		position: absolute;
		top: -10rpx;
		right: -6rpx;
		width: 80rpx;
		height: 80rpx;
		z-index: 9;
	}

	.preview-card-img {
		// /deep/uni-image>div, uni-image>img {
		//     transform: scale(1.5) rotate(-90deg);
		// }
	}
</style>
