<template>
	<view class="containerView">
		<list-cell title="收款人姓名" type="text" placeholder="请输入支付宝收款人姓名" v-model="zhiFuBaoName"></list-cell>

		<list-cell title="支付宝账号" type="text" placeholder="请输入要绑定的支付宝手机号" v-model="zhiFuBao"></list-cell>
		
		<list-cell title="身份证号码" type="text" placeholder="请输入要绑定身份证号码" v-model="certNum"></list-cell>


		<button :class="zhiFuBao&&zhiFuBaoName?'confirm-btn':'confirm-btn1'" @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">否则将无法正常收款，请须知</view>

	</view>
</template>

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

			if (userId) {
				this.$u.api.userinfo().then(res => {
					if (res.code === 0) {
						if (res.data.zhiFuBao) {
							this.zhiFuBao = res.data.zhiFuBao;
						}
						if (res.data.zhiFuBaoName) {
							this.zhiFuBaoName = res.data.zhiFuBaoName;
						}
						if (res.data.certNo) {
							this.certNum = res.data.certNo;
						}
					}
				})
			}

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

			toLogin() {
				let zhiFuBao = this.zhiFuBao
				let zhiFuBaoName = this.zhiFuBaoName
				let certNum = this.certNum
			    
				if (!zhiFuBao) {
					uni.showToast({
						title: '请设置收款人姓名',
						icon: 'none'
					})
				} else if (!zhiFuBaoName) {
					uni.showToast({
						title: '请设置收款人支付宝账号',
						icon: 'none'
					})
				} else if (!certNum) {
					uni.showToast({
						title: '请设置收款人身份证账号',
						icon: 'none'
					})
				} else {
					this.logining = true
					this.$u.post('app/user/updateUser?zhiFuBao=' + zhiFuBao + '&certName=' + zhiFuBaoName + '&certNum=' + certNum).then(
						res => {
							this.logining = false
							console.log(res);
							if(res.code===0){
								uni.setStorageSync('zhiFuBao', zhiFuBao)
								uni.setStorageSync('zhiFuBaoName', zhiFuBaoName)
								uni.setStorageSync('certNum', certNum)
								uni.showToast({
									title: '修改成功',
									icon: 'none',
									complete() {
										setTimeout(function() {
											uni.navigateBack();
										}, 1000)
									}
								})
							}else{
								uni.showToast({
									title:res.msg||'修改失败',
									icon:'none'
								})
							}
							

						});

				}
				// if (!zhifubao) {
				// 	this.$queue.showToast("请设置收款人支付宝账号");
				// } else if (!zhifubaoName) {
				// 	this.$queue.showToast("请设置收款人姓名");
				// } else {
				// this.$queue.showLoading("修改中...");
				// this.$Request.postT("/cash/userinfo?userId=" + userId + "&zhifubao=" + zhifubao + "&zhifubaoName=" + zhifubaoName).then(
				// 	res => {
				// 		if (res.status === 0) {
				// 			if (res.data.zhifubao) {
				// 				this.zhifubao = res.data.zhifubao;
				// 			}
				// 			if (res.data.zhifubaoName) {
				// 				this.zhifubaoName = res.data.zhifubaoName;
				// 			}
				// 			this.navBack();
				// 		} else {
				// 			// this.$queue.showToast(res.msg)
				// 		}
				// 		uni.hideLoading();
				// 	});
				// }
			},
		},

	}
</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>