<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="name"
						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="idcard"
						ref="idcard" />
				</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="phone"
						ref="idcard" />
				</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="code"
						ref="idcard" />
				</view>
				<view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
			</view>
			<view class="tit tit1">
				身份证照片(正反两面）
			</view>
			<view class="" @click="imgsub('sfzz')">
				<image :src="sfzz" mode="" class="sfz" v-if="sfzz"></image>
				<image src="../../static/user/sfzz.png" mode="" class="sfz" v-else></image>
			</view>
			<view class="tip">
				身份证头像面
			</view>
			<view class="" @click="imgsub('sfzf')">
				<image :src="sfzf" mode="" class="sfz" v-if="sfzf"></image>
				<image src="../../static/user/sfzf.png" mode="" class="sfz" v-else></image>
			</view>

			<view class="tip">
				身份证国徽面
			</view>
		</view>
		<view class="btm-btn" @click="bank">
			确认
		</view>
		<codeImage @openCode='getCode' loginType="register" @close='showAlert=false' :phone="phone" ref="alertImage"
			:show='showAlert'></codeImage>
	</view>
</template>
<script>
	import codeImage from '@/components/codeImage.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		upload
	} from '@/api/order.js';
	import {
		enroll
	} from '@/api/index.js'
	import {
		getLevelList,
		bank,
		bankInfo,
		realName
	} from '@/api/user.js'


	export default {
		components: {
			codeImage
		},
		data() {
			return {
				countDown: 0,
				name: '',
				idcard: '',
				sfzz: '',
				sfzf: '',
				code: '',
				phone: '',
				loading: false,
				showAlert: false
			};
		},
		onLoad(opt) {},
		onShow() {

		},
		onReachBottom() {

		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {
			// 发送验证码
			getCode() {
				const obj = this;
				obj.countDown = 60;
				obj.time = setInterval(() => {
					obj.countDown--;
				}, 1000);
				//调用验证码接口
			},
			imgsub(name) {
				console.log('上传头像')
				upload({
					filename: ''
				}).then(data => {
					console.log("data", data);
					this.bankInfo[name] = data[0].url;
				})
			},
			//发送验证码
			verification() {
				let obj = this;
				if (this.phone == '') {
					this.$api.msg('请输入电话号码');
					return;
				}
				if (this.phone.length < 11) {
					this.$api.msg('请输入正确的手机号');
					return;
				}
				// 判断是否在倒计时
				if (obj.countDown > 0) {
					return false;
				} else {
					obj.showAlert = true;
					obj.$refs.alertImage.getImage()
				}
			},
			bank() {
				let that = this
				if (that.loading) {
					return
				}
				if (that.name == '') {
					return that.$api.msg('请输入您的姓名')
				}
				if (that.idcard == '') {
					return that.$api.msg('请输入身份证号')
				}
				if (that.sfzz == '') {
					return that.$api.msg('请上传身份证照片')
				}
				if (that.sfzf == '') {
					return that.$api.msg('请上传身份证照片')
				}
				let data = {
					real_name: that.name,
					id_card: that.idcard,
					id_card_front_image: that.sfzz,
					id_card_back_image: that.sfzf
				}
				that.loading = true
				realName(data).then(res => {
					console.log(res);
					uni.showToast({
						title: '提交成功',
						duration: 2000
					});
					setTimeout(() => {
						uni.navigateBack()
						that.loading = false
					}, 1500)

				}).catch(err => {
					console.log('err');
					that.loading = false
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	page {
		height: auto;
		min-height: 100%;
		background-color: #fff;
	}

	.tab {
		width: 690rpx;
		margin: auto;
		// height: 606rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 30rpx 0 99rpx;

		.tit {
			font-weight: 500;
			font-size: 32rpx;
			color: #222222;
		}

		.tit1 {
			padding-top: 45rpx;
		}
	}

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

		.code {
			color: $base-color;
			font-size: 23rpx;
			border-left: 1px solid #eeeeee;
			width: 150rpx;
			flex-shrink: 0;
			text-align: center;
		}

		.bg-name {
			width: 182rpx;
			height: 100%;
			flex-shrink: 0;
			// padding-left: 20rpx;
		}

		.bg-val {
			// width: 430rpx;
			flex-grow: 1;
			height: 100%;

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

	.btm-btn {
		width: 690rpx;
		line-height: 80rpx;
		background: #333333;
		border-radius: 10rpx;
		margin: auto;
		font-size: 30rpx;
		color: #FFFFFF;
		text-align: center;
	}

	.sfz {
		width: 300rpx;
		height: 210rpx;
		display: block;
		margin: 35rpx auto;
		border-radius: 35rpx;
		border: #ececec 1px solid;
	}

	.tip {
		text-align: center;
		font-size: 26rpx;
		font-weight: 500;
		color: #333333;
	}
</style>