<template>
	<view class="content">
		<view class="" style="height: 20rpx;">

		</view>
		<view class="tab">
			<view class="bd-wrap flex">
				<view class="bg-name">
					真实姓名：
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入真实姓名" class="val-ipt" v-model="bankInfo.fullname" ref="name" />
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					手机号：
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入手机号" class="val-ipt" v-model="bankInfo.phone" ref="phone" />
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					银行卡号：
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入银行卡号" class="val-ipt" v-model="bankInfo.bankno"
						ref="address" />
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					开户行：
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入开户行" class="val-ipt" v-model="bankInfo.bank"
						ref="storenamae" />
				</view>
			</view>
			<view class="bd-wrap flex" >
				<view class="bg-name">
					所属支行：
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入所属支行" class="val-ipt" v-model="bankInfo.subbranch"
						ref="storenamae" />
				</view>
			</view>

		</view>
		<view class="btm-btn" @click="bank">
			确认
		</view>
	</view>
</template>
<script>
	import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
	import {
		enroll
	} from '@/api/index.js'
	import {
		getLevelList,
		bank,
		bankInfo
	} from '@/api/user.js'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			pickerAddress
		},
		data() {
			return {
				bankInfo: {
					fullname: '',
					phone: '',
					bankno: '',
					bank: '',
					subbranch: '',
				},
				loading: false,
			};
		},
		onLoad(opt) {
		},
		onShow() {
			this.getbankInfo()
		},
		onReachBottom() {

		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {
			getbankInfo() {
				bankInfo().then(res => {
					console.log(res);
					if(res.data && res.data.id) {
						this.bankInfo = res.data
						uni.setNavigationBarTitle({
							title:'修改银行卡信息'
						})
					}
				})
			},
			// 选中城市切换
			onCityClick({
				data
			}) {
				// let address = this.addressData.address;
				// address.province = data[0];
				// address.city = data[1];
				// address.district = data[2];
				this.address = data.join('-');
			},
			bank() {
				let that = this
				if (that.loading) {
					return
				}
				if (that.bankInfo.fullname == '') {
					return that.$api.msg('请输入您的姓名')
				}
				if (that.bankInfo.phone == '') {
					return that.$api.msg('请输入手机号')
				}
				if (that.bankInfo.bankno == '') {
					return that.$api.msg('请输入银行卡号')
				}
				if (that.bankInfo.bank == '') {
					return that.$api.msg('请输入银行')
				}
				if (that.bankInfo.subbranch == '') {
					return that.$api.msg('请输入所属支行')
				}
				that.loading = true
				bank(that.bankInfo).then(res => {
					console.log(res);
					uni.showToast({
						title: '提交成功',
						duration: 2000
					});
					setTimeout(() => {
						// uni.switchTab({
						// 	url: '/pages/user/user'
						// })
						uni.navigateBack()
						that.loading = false
					}, 1500)

				}).catch(err => {
					console.log('err');
					that.loading = false
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.tab {
		width: 690rpx;
		margin: auto;
		// height: 606rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
	}

	.bd-wrap {
		width: 690rpx;
		// height: 100rpx;
		padding: 20rpx 0;
		background-color: #fff;
		border-bottom: 1px solid #f2f2f2;
		// line-height: 100rpx;
		font-size: 32rpx;
		position: relative;

		.code {
			position: absolute;
			width: 100rpx;
			height: 100rpx;
			right: 10rpx;
			color: #f64342;
			font-size: 23rpx;
		}

		.bg-name {
			width: 280rpx;
			height: 100%;
			padding-left: 20rpx;
		}

		.bg-val {
			width: 430rpx;
			height: 100%;

			.val-ipt {
				padding-top: 10rpx;
				display: inline-block;
				width: 100%;
				height: 100%;
				// background-color: #009100;
				padding-left: 10rpx;

			}
		}
	}

	.btm-btn {
		margin: 60rpx auto 0;
		font-size: 34rpx;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		line-height: 82rpx;
		
		width: 560rpx;
		height: 80rpx;
		background: #FA2740;
		border-radius: 40rpx;
	}
</style>