<template>
	<view class="content">
		<view class="theform">
			<u--form labelPosition="left" :model="dataForm" :rules="rules" ref="uForm">
				<u-form-item required label-width="180rpx" :label="$t('MY_WAL_33')" prop="accountName" ref="item1">
					<u--input :placeholder="$t('S_C_70')" v-model="dataForm.accountName" disabledColor="#F5F5F5;"></u--input>
				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('MY_WAL_34')" prop="sex" ref="item1">
					<u-radio-group v-model="sexRadio" @change="radioGroupChange">
						<u-radio :customStyle="{marginRight: '16rpx'}" v-for="(item, index) in sexList" :key="index"
							:name="item.value">{{ item.label }}</u-radio>
					</u-radio-group>
				</u-form-item>
				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('MY_WAL_35')" prop="idName" @click="showCtype = true; " ref="item1">
					<u--input suffixIcon="arrow-right" readonly v-model="dataForm.idName" disabledColor="#ffffff"
						:placeholder="$t('CK_KS_38')">
					</u--input>
				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('MY_WAL_36')" prop="idCard" ref="item1">
					<u--input :placeholder="$t('S_C_70')" v-model="dataForm.idCard" disabledColor="#F5F5F5;"></u--input>
				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('CK_KS_41')" @click="showAmount = true; " prop="bankName" ref="item1">
					<u--input suffixIcon="arrow-right" readonly v-model="dataForm.bankName" disabledColor="#ffffff"
						:placeholder="$t('CK_KS_38')">
					</u--input>


				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('MY_WAL_24')" prop="cardNumber" ref="item1">
					<u--input :placeholder="$t('S_C_70')" v-model="dataForm.cardNumber" disabledColor="#F5F5F5;"></u--input>
				</u-form-item>

				<u-form-item required label-width="180rpx" :label="$t('CK_KS_43')" prop="subBankName" ref="item1">
					<u--input :placeholder="$t('S_C_70')" v-model="dataForm.subBankName" disabledColor="#F5F5F5;"></u--input>
				</u-form-item>
				<u-form-item required @click="getDiqu" :label="$t('w_0068')" label-width="180rpx" prop="theaddress">
					<u--input v-model="dataForm.theaddress" readonly suffixIcon="arrow-right" disabledColor="#ffffff"
						:placeholder="$t('CK_KS_38')">
					</u--input>
				</u-form-item>

				<view class="view-class">
					<u-form-item required :label="$t('S_C_27')" class="label-style" label-width="180rpx" prop="address">
						<u-textarea v-model="dataForm.address" placeholder-class="place-class" class="border-color"
            maxlength="200"
							:placeholder="$t('S_C_70')" />

					</u-form-item>
				</view>
				<u-form-item required label-width="180rpx" :label="$t('w_0052')" prop="phone" ref="item1">
					<u--input v-model="dataForm.phone" :placeholder="$t('S_C_70')"></u--input>
				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('w_0043')" prop="verificationCode" ref="item1">
					<u--input v-model="dataForm.verificationCode" :placeholder="$t('S_C_70')">
						<template slot="suffix">
							<text style="color: #18ACFF;" @tap='getCode'>{{tips}}</text>
						</template>
					</u--input>

				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('MY_ORD_60')" >
					<uploadImg :ifsfz='true' @imageUploaded='imageUploaded1' prop="idFront" style="margin-right: 30rpx;" :bgimg="`../../../static/images/idCard1.png`"
						v-model="dataForm.idFront"></uploadImg>

				</u-form-item>
				<u-form-item required label-width="180rpx" :label="$t('MY_ORD_61')">
					<uploadImg :ifsfz='true' @imageUploaded='imageUploaded2' prop="idBack" style="margin-right: 30rpx;" :bgimg="`../../../static/images/idCard2.png`"
						v-model="dataForm.idBack"></uploadImg>

				</u-form-item>
				<u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
				<u-picker @cancel='showAmount=false' :show="showAmount" ref="uPicker" :columns="bankCardChioceList"
					@confirm="confirm" keyName='bankName'></u-picker>
				<u-picker @cancel='showCtype=false' :show="showCtype" ref="uPicker2" :columns="cardTypeList"
					@confirm="confirm2" keyName='label'></u-picker>
			</u--form>

		</view>
		<view class="btnbox">
			<u-button class="subbtn" @click="submit">{{$t('w_0035')}}</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
		<v-address ref="address" @getAddressData="AddressData" :defaultCode="defaultCode"
			@addressData="addressData"></v-address>
	</view>
</template>

<script>
	import * as ban from "@/config/balance.js"
	import address from '@/components/address.vue'
	import uploadImg from '@/components/uploadImg.vue'
	export default {
		components: {
			'v-address': address,
			uploadImg
		},
		data() {
			return {
				showAmount: false,
				showCtype: false,
				dataForm: {
					bankName: "",
					cardNumber: "",
					pkBank: "",
					subBankName: "",
					accountName: "",
					idCard: "",
					pkProvince: "",
					pkCity: "",
					pkCounty: "",
					theaddress: "",
					idFront:"",
					idBack:""
				},
				sexRadio: 1,
				address: "",
				defaultCode: [],
				bankCardChioceList: [], //银行选择
				cardTypeList: [], //证件类型
				sexList: [{
						label: this.$t('MY_WAL_44'),
						value: 1
					},
					{
						label: this.$t('MY_WAL_45'),
						value: 2
					},
				],
				rules: {
					accountName: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger: ['blur', 'change']
					}],
					sexRadio: [{

						required: true,
						message: this.$t('CK_KS_38'),
						trigger: 'change',
					}],
					idName: [{
						type: 'string',
						required: true,
						message: this.$t('CK_KS_38'),
						trigger: ['change']
					}],
					idCard: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger: ['blur', 'change']
					}],
					pkBank: [{
						type: 'string',
						required: true,
						message: this.$t('CK_KS_38'),
						trigger: ['change']
					}],
					address: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger:['blur', 'change']
					}],
					cardNumber: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger: ['blur', 'change']
					}],
					subBankName: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger: ['blur', 'change']
					}],
					theaddress: [{
						type: 'string',
						required: true,
						message: this.$t('CK_KS_38'),
						trigger: ['change']
					}],
					idFront: [{

						required: true,
						message: this.$t('MY_CK_16'),

					}],
					idBack: [{

						required: true,
						message: this.$t('MY_CK_16'),

					}],
					phone: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger: ['blur', 'change']
					}],
					verificationCode: [{
						type: 'string',
						required: true,
						message: this.$t('S_C_70'),
						trigger: ['blur', 'change']
					}],

				},
				tips: '',
				// refCode: null,
				seconds: 60,

			}
		},
		onLoad() {
			this.getList()

		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},

		methods: {
			imageUploaded1(url){
				this.dataForm.idFront= url
			},
			imageUploaded2(url){
				this.dataForm.idBack= url
			},
			// radio选择发生变化
			radioGroupChange(e) {
				this.dataForm.sex = e
				// console.log('🌈eeee',e)
			},
			AddressData(name) {
				this.dataForm.theaddress = name
			},
			getDiqu() {
				this.$refs.address.setShow()
			},
			addressData(diqu, obj) {
				this.dataForm.theaddress = diqu
				this.dataForm.pkProvince = obj.province
				this.dataForm.pkCity = obj.city
				this.dataForm.pkCounty = obj.county
				this.$forceUpdate()
			},

			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.dataForm.phone) {
					if (this.$refs.uCode.canGetCode) {
						// 模拟向后端请求验证码
						uni.showLoading({
							title: this.$t('MY_ORD_62')
						})
						ban.getVerification({
							phone: this.dataForm.phone
						}).then((res) => {
							uni.hideLoading();
							// 这里此提示会被this.start()方法中的提示覆盖
							uni.$u.toast(this.$t('MY_WAL_49'));
							// 通知验证码组件内部开始倒计时
							this.$refs.uCode.start();
						})
					} else {
						uni.$u.toast(this.$t('MY_ORD_63'));
					}
				} else {
					uni.$u.toast(this.$t('MY_WAL_47'))
					return
				}
			},
			end() {},
			start() {},
			getList() {
				ban.getBankCardChoiceList().then(res => {
					this.bankCardChioceList = [res.data]
				})
				//证件类型
				ban.getCardType().then((res) => {
					this.cardTypeList = [res.data];
				});
			},


			submit() {
				this.$refs.uForm.validate().then(res => {
					ban.addAuthentication(this.dataForm).then(res => {
						if (res.code == 200) {
							uni.$u.toast(res.msg)
							setTimeout(() => {
								uni.navigateBack()
							}, 1500);

						} else {

							uni.$u.toast(res.msg)
						}
					}).catch(err => {

					})
				}).catch(errors => {
					uni.$u.toast(this.$t('MY_ORD_64'))
					return false
				})
			},
			confirm2(e) {
				this.dataForm.idName = e.value[0].label
				this.dataForm.idType = e.value[0].value
				this.showCtype = false
			},
			confirm(e) {
				this.dataForm.bankName = e.value[0].bankName
				this.dataForm.pkBank = e.value[0].pkId
				this.showAmount = false
			},

		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-input--radius,
	.u-input--square {
		border-radius: 12rpx;
		// border:2rpx solid #cccccc;
	}

	.content {
		background: #F2F2F2;

		.uni-textarea {
			height: 100rpx;
		}

		.theform {
			margin-top: 6rpx;
			background: #FFFFFF;
			padding: 20rpx 23rpx 48rpx 23rpx;

			.contentye {
				font-size: 28rpx;
				margin-left: 200rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
			}

		}

		.btnbox {
			margin-top: 38rpx;
			padding: 0 20rpx;

			.subbtn {
				background: #FB3024;
				border-radius: 46rpx;
				font-size: 30rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #FFFFFF;
			}
		}

		.getcodes {

			background: #2FBC42;
			border-radius: 38rpx;
			color: #fff;
		}


	}
</style>