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

		</view>
		<view class="tab">
			<view class="tit">
				填写个人信息
			</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.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="bankInfo.idcard" ref="idcard" />
				</view>
			</view>
			<view class="tit tit1">
				上传证件
			</view>
			<view class="" @click="imgsub('sfzz')">
				<image :src="bankInfo.sfzz" mode="" class="sfz" v-if="bankInfo.sfzz" ></image>
				<image src="../../static/img/sfzz.png" mode="" class="sfz" v-else></image>
			</view>
			<view class="tip">
				身份证头像面
			</view>
			<view class="" @click="imgsub('sfzf')">
				<image :src="bankInfo.sfzf" mode="" class="sfz" v-if="bankInfo.sfzf"></image>
				<image src="../../static/img/sfzf.png" mode="" class="sfz" v-else></image>
			</view>
			
			<view class="tip">
				身份证国徽面
			</view>
		</view>
		<view class="btm-btn" @click="bank">
			确认
		</view>
	</view>
</template>
<script>
	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 {
		data() {
			return {
				bankInfo: {
					name: '',
					idcard: '',
					sfzz: '',
					sfzf: ''
				},
				loading: false,
			};
		},
		onLoad(opt) {
		},
		onShow() {
			
		},
		onReachBottom() {

		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {
			imgsub(name) {
				console.log('上传头像')
				upload({
					filename: ''
				}).then(data => {
					console.log("data", data);
					this.bankInfo[name] = data[0].url;
				})
			},
			bank() {
				let that = this
				if (that.loading) {
					return
				}
				if (that.bankInfo.name == '') {
					return that.$api.msg('请输入您的姓名')
				}
				if (that.bankInfo.idcard == '') {
					return that.$api.msg('请输入身份证号')
				}
				if (that.bankInfo.sfzz == '') {
					return that.$api.msg('请上传身份证照片')
				}
				if (that.bankInfo.sfzf == '') {
					return that.$api.msg('请上传身份证照片')
				}
				let data = {
					real_name: that.bankInfo.name,
					id_card: that.bankInfo.idcard,
					id_card_front_image:that.bankInfo.sfzz,
					id_card_back_image: that.bankInfo.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>
	.tab {
		width: 690rpx;
		margin: auto;
		// height: 606rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 30rpx 30rpx 99rpx;
		.tit {
			font-weight: bold;
			padding:25rpx 0;
			font-size: 38rpx;
			font-weight: 500;
			color: #333333;
		}
		.tit1 {
			padding-top: 45rpx;
		}
	}

	.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 {
				width: 100%;
				height: 100%;
				// background-color: #009100;
				padding-left: 10rpx;
				padding-top: 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: $base-color;
		border-radius: 40rpx;
	}
	.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>