<template>
	<view class="containerView">
		<list-cell title="姓名" type="text" placeholder="请输入姓名" v-model="certName"></list-cell>

		
		<list-cell title="身份证号码" type="text" placeholder="请输入身份证号码" v-model="certNum"></list-cell>
		
		<list-cell title="银行卡号码" type="text" placeholder="请输入银行卡号码" v-model="accountNo"></list-cell>
		
		<list-cell title="手机号" type="text" placeholder="请输入银行预留号码" v-model="mobile"></list-cell>

		<button v-if="!user.accountNo" class="confirm-btn" @click="toLogin"
			:disabled="logining">认证</button>
		<view style="font-size: 24upx;color: #999999;padding: 0 64rpx;margin-top: 32rpx;margin-bottom: 10rpx;">请正确填写收款人的银行卡号和真实的收款人姓名</view>
		<view style="font-size: 24upx;color: #999999;padding: 0 64rpx;;margin-bottom: 10rpx;">手机号需是银行卡预留手机号</view>
		<view style="font-size: 24upx;color: #999999;padding: 0 64rpx;;margin-bottom: 10rpx;">银行卡号需与收款人姓名一致</view>
		<view style="font-size: 24upx;color: #999999;padding: 0 64rpx;;margin-bottom: 10rpx;">身份证信息仅可使用一次</view>
		<view style="font-size: 24upx;color: #999999;padding: 0 64rpx">否则将无法正常收款，请须知</view>

	</view>
</template>

<script>
	import listCell from '@/me/components/com-input';
	export default {
		components: {
			listCell
		},
		data() {
			return {
				certName: '',
				mobile: '',
				certNum: '',
				accountNo: '',
				user: {},
				logining: false
			}
		},
		onLoad() {
			let userId = uni.getStorageSync('userId');

			if (userId) {
				this.$u.api.userinfo().then(res => {
					if (res.code === 0) {
						this.user = res.data
						if (res.data.certName) {
							this.certName = res.data.certName;
						}
						if (res.data.mobile) {
							this.mobile = res.data.mobile;
						}
						if (res.data.accountNo) {
							this.certNum = res.data.certNo;
							this.accountNo = res.data.accountNo;
						}
						
					}
				})
			}

		},
		methods: {
			inputChange(e) {
				const key = e.currentTarget.dataset.key;
				this[key] = e.detail.value;
			},
			navBack() {
				uni.navigateBack();
			},

			toLogin() {
			    
				if (!this.certName) {
					uni.showToast({
						title: '请输入姓名',
						icon: 'none'
					})
				} else if (!this.mobile) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
				} else if (!this.certNum) {
					uni.showToast({
						title: '请输入身份证账号',
						icon: 'none'
					})
				} else if (!this.accountNo) {
					uni.showToast({
						title: '请请输入银行卡号',
						icon: 'none'
					})
				} else {
					this.logining = true
					this.$u.post('app/user/realNameAuth?certName=' + this.certName + '&mobile=' + this.mobile + '&certNum=' + this.certNum + '&accountNo=' + this.accountNo.replace(/\s+/g, '')).then(
						res => {
							this.logining = false
							console.log(res);
							if(res.code===0){
								uni.setStorageSync('certName', this.certName)
								uni.setStorageSync('mobile', this.mobile)
								uni.setStorageSync('certNum', this.certNum)
								uni.setStorageSync('accountNo', this.accountNo)
								uni.showToast({
									title: '修改成功',
									icon: 'none',
									complete() {
										setTimeout(function() {
											uni.navigateBack();
										}, 1000)
									}
								})
							}else{
								uni.showToast({
									title:res.msg||'修改失败',
									icon:'none'
								})
							}
							

						});

				}
				
			},
		},

	}
</script>

<style lang='scss'>
	page {
		background: #FFFFFF;
	}

	.containerView {
		padding-top: 32upx;
		position: relative;
		width: 100%;
		height: 100%;
		overflow: hidden;
		background: #ffffff;
	}

	.confirm-btn1 {
		width: 300px;
		height: 42px;
		line-height: 42px;
		border-radius: 30px;
		margin-top: 70upx;
		/* background: whitesmoke; */
		background: #ff7581;
		color: #FFFFFF;
		font-size: 32rpx;

		&:after {
			border-radius: 60px;
		}
	}



	.confirm-btn {
		width: 300px;
		height: 42px;
		line-height: 42px;
		border-radius: 30px;
		margin-top: 70upx;
		background: #ff7581;
		color: #ffffff;
		font-size: 32rpx;

		&:after {
			border-radius: 60px;
		}
	}
</style>