<script setup>
	// 添加银行卡
	import {
		ref,
		reactive,
		computed,
	} from 'vue'
	import {
		useStore
	} from 'vuex'
	import {
		onLoad,
	} from '@dcloudio/uni-app'
	// 工具库
	import util from '@/common/js/util.js'
	// api
	import api from '@/api/index.js'
	// 获取验证码
	import getCode from '@/components/getCode/getCode'

	// 银行卡列表
	const bankList = reactive([])
	// 表单对象
	const form = reactive({
		cardNumber: '',
		phoneNumber: '',
		userIdCard: '',
		userRealName: '',
	})

	// 绑定
	function handleSubmit() {
		const data = {
			...form
		}

		// 
		if (!data.phoneNumber) {
			util.alert('手机号不能为空')
			return
		}
		if (!data.userIdCard) {
			util.alert('身份证号不能为空')
			return
		}
		if (!data.cardNumber) {
			util.alert('用户手机号不能为空')
			return
		}
		if (!data.userRealName) {
			util.alert('真实姓名不能为空')
			return
		}

		// 
		api.mine.addBankCard({
			data,
		}).then(rs => {
			if (rs.code == 200) {
				uni.$emit('updateBindingBank')
				util.alert('添加成功')

				setTimeout(() => {
					uni.navigateBack()
				}, 500)
				return
			}
			util.alert({
				content: rs.msg,
				showCancel: false,
			})
		})
	}
</script>

<template>
	<view class="appbw">
		<!-- 表单 -->
		<view class="form mtb30 mlr40">
			<!-- <view class="line">
				<view class="title">银行卡类型</view>
				<view class="inputBox">
					<picker :range="bankList" range-key="name">
						<view class="rows">
							<input class="input" disabled type="text" placeholder="请选择银行卡类型" />
							<uni-icons type="bottom" />
						</view>
					</picker>
				</view>
			</view> -->

			<view class="line">
				<view class="title">银行卡卡号</view>
				<view class="inputBox">
					<input class="input" v-model="form.cardNumber" type="text" placeholder="请输入银行卡卡号" />
				</view>
			</view>

			<view class="line">
				<view class="title">姓名</view>
				<view class="inputBox">
					<input class="input" v-model="form.userRealName" type="text" placeholder="请输入姓名" />
				</view>
			</view>

			<view class="line">
				<view class="title">身份证号</view>
				<view class="inputBox">
					<input class="input" v-model="form.userIdCard" type="text" placeholder="请输入身份证号" />
				</view>
			</view>

			<view class="line">
				<view class="title">手机号（银行绑定的手机号）</view>
				<view class="inputBox">
					<input class="input" v-model="form.phoneNumber" type="text" placeholder="请输入手机号" />
				</view>
			</view>

			<!-- <view class="line">
				<view class="title">验证码</view>
				<view class="inputBox rows">
					<input class="input" type="text" placeholder="请输入验证码" />
					<view class="getCode btn black plr30">
						<getCode />
					</view>
				</view>
			</view> -->

			<view class="btn lg black mt50" @click="handleSubmit">绑定</view>
		</view>

		<view class="fill"></view>
	</view>
</template>

<style lang="scss" scoped>
	// 图表
	.form {

		// 
		.line {
			margin: 30rpx 0;

			// 
			.title {
				color: #111;
				font-size: 32rpx;
			}

			// 
			.inputBox {
				margin-top: 15rpx;
				padding: 10rpx 30rpx;
			}
		}
	}
</style>