<template>
	<view class="index-content" :style="{'--status-bar-': statusBarHeight}">
		<view class="index-content-info">
			<!-- 头部主要内容 开始 -->
			<view class="index-content-header">
				<customNavbar :title="title" bgColor="rgba(0,0,0,0)" :is-left="true" :customNavbarInfo='{}'>
				</customNavbar>
			</view>
			<!-- 头部主要内容 结束 -->
			<view>
				<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
					<u-form-item label="真实姓名" prop="name" borderBottom ref="item1">
						<u--input v-model="form.name" border="none"></u--input>
					</u-form-item>
					<u-form-item label="开户行" prop="bankName" borderBottom ref="item1">
						<u--input v-model="form.bankName" border="none"></u--input>
					</u-form-item>
					<u-form-item label="银行卡号" prop="bankNo" borderBottom ref="item1">
						<u--input v-model="form.bankNo" border="none"></u--input>
					</u-form-item>
					<u-form-item label="开户行" prop="openBankName" borderBottom ref="item1">
						<u--input v-model="form.openBankName" border="none"></u--input>
					</u-form-item>
				</u--form>
			</view>
			<view>
				<u-button type="primary" @click="getRetailQrcode()" text="提交"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '我的银行卡',
				loading: false,
				statusBarHeight: 0, // 状态栏安全距离
				form: {
					"id": "",
					"name": "",
					"moblie": "",
					"bankName": "",
					"bankNo": "",
					"openBankName": ""
				},
				rules: {
					'name': {
						type: 'string',
						required: true,
						message: '请输入姓名',
						trigger: ['blur', 'change']
					},
					'moblie': {
						type: 'string',
						max: 1,
						required: true,
						message: '请输入手机号',
						trigger: ['blur', 'change']
					},
					'bankName': {
						type: 'string',
						max: 1,
						required: true,
						message: '请输入银行名称',
						trigger: ['blur', 'change']
					},
					'bankNo': {
						type: 'string',
						max: 1,
						required: true,
						message: '请输入银行卡号',
						trigger: ['blur', 'change']
					},
					'openBankName': {
						type: 'string',
						max: 1,
						required: true,
						message: '请输入开户行',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad() {

		},
		onShow() {
			this.statusBarHeight = getApp().globalData.statusBarHeight
			//this.load()
		},
		methods: {
			/**
			 * 获取 我的银行卡
			 */
			async getRetailQrcode() {
				try {
					uni.showLoading({
						title: "获取银行卡中..."
					})
					let res = await this.$u.api.getPersonsBankApi({
						userid: this.distribution_user_info.userId
					})	
					uni.hideLoading()
					if (res && res.code === 200) {
						this.form = {
							"id":  res.data.id,
							"name": res.data.name,
							"moblie": res.data.moblie,
							"bankName": res.data.bankName,
							"bankNo": res.data.bankNo,
							"openBankName": res.data.openBankName
						}
					}
				
				} catch (e) {
					//TODO handle the exception
					console.error("e===", e)
					uni.hideLoading()
				}
			},
			/**
			 * 提交 我的银行卡
			 */
			async getRetailQrcode() {
				this.$refs.uForm.validate().then(async res => {
					try {
						uni.showLoading({
							title: "提交数据中..."
						})
						let res = await this.$u.api.insertOrUpdateApi({...this.form})				
						if (res && res.code === 200) {
							uni.hideLoading()
							uni.showToast({
								title: "绑定成功!!!"
							})
							this.getRetailQrcode()
						}
						this.loading = false
					} catch (e) {
						//TODO handle the exception
						console.error("e===", e)
						this.loading = false
					}
				}).catch(errors => {
					
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.index-content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;

		--header-h: 170rpx;

		// background-color: 
		.index-content-info {
			width: 100%;
			box-sizing: border-box;
		}
	}

	/** 头部主要内容 开始 */
	.index-content-header {
		width: 100%;
		height: var(--header-h);
		box-sizing: border-box;
		background-color: var(--gd-bgm-color);

		::v-deep .u-search {
			padding: 0 30rpx !important;
		}

		::v-deep .u-search__action {
			color: #fff !important;
		}
	}

	/** 头部主要内容 结束  **/
</style>