<template>
	<view class="content">
		<view class="content-money">
			<view class="status_bar"><!-- 这里是状态栏 --></view>
			<view class="body-title">
				<view class="goback-box">
				</view>
				<view class="header">实名认证</view>
			</view>
			<view class="content-bg">
				<image src="../../users/static/sm.png" mode=""></image>
			</view>
		</view>
		<view class="yanzheng">
			<view class="top">
				<view class="tex">真实姓名</view>
				<input class="inp" type="text" placeholder="请输入真实姓名" v-model="name" required />
			</view>
			<view class="top">
				<view class="tex">身份证号</view>
				<input class="inp" type="text" placeholder="请输入身份证号" v-model="num" required />
			</view>
		</view>
		<view class="sc">
			<view class="poto">上传人脸正面照片</view>
			<image class="pto" @click="uploadpic" :src="image||`../../users/static/pto.png`" mode="widthFix"></image>
		</view>

		<view class="btn">
			<button class="bt" :class="{loding:uploding}" @click="uploding?'':setCheck()">立即认证</button>
		</view>
		<canvas canvas-id="canvas" v-if="canvasStatus"
			:style="{width: canvasWidth + 'px', height: canvasHeight + 'px',position: 'absolute',left:'-100000px',top:'-100000px'}"></canvas>
	</view>
</template>

<script>
	import {
		setCheck,
		getCheckMy
	} from "@/api/newapi";
	export default {
		data() {
			return {
				name: '',
				num: '',
				image: '',
				canvasWidth: "",
				canvasHeight: "",
				canvasStatus: false,
				uploding:false,//是否不允许提交
			};
		},
		onLoad() {
			getCheckMy().then(
			(res) => {
				console.log(res)
				if(res.data){
					if(res.data.info){
						if(res.data.info.status==0){
							this.uploding = true;
							
							uni.showModal({
								title: '提示',
								content: '正在审核中',
								showCancel: false,
							});
						}
						if(res.data.info.status==1){
							this.uploding = true;
							this.name = res.data.info.real_name;
							this.num = res.data.info.id_card;
							this.image =  res.data.info.image;
							uni.showModal({
								title: '提示',
								content: '审核已通过',
								showCancel: false,
							});
						}
						if(res.data.info.status==-1){
							this.uploding = true;
							uni.showModal({
								title: '提示',
								content: '审核未通过，原因：'+res.data.info.fail_msg,
								showCancel: false,
							});
						}
					}
				}
			}
			)
		},
		onShow() {

		},
		methods: {
			setCheck() {
				uni.showLoading({
					title: '提交中。。。',
					mask: true
				});

				setCheck({
					real_name: this.name,
					id_card: this.num,
					image: this.image
				}).then((res) => {
					uni.showToast({
						title:res.msg,
						duration:2000
					})
				}).catch((err) => {
					uni.showToast({
						title: err,
						icon: 'none'
					});
				})
			},
			/**
			 * 上传文件
			 * 
			 */
			uploadpic: function() {
				let that = this;
				this.canvasStatus = true
				that.$util.uploadImageChange('upload/image', function(res) {
					that.image = res.data.url;
				}, (res) => {
					this.canvasStatus = false
				}, (res) => {
					this.canvasWidth = res.w
					this.canvasHeight = res.h
				});
			},
		}
	};
</script>

<style lang="scss">
	page {
		background: #fff;
		height: 100%;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.content-money {
		height: 480rpx;

		.content-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 750rpx;
			height: 480rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.body-title {
			height: 80rpx;
			text-align: center;
			font-size: 35rpx;
			position: relative;

			.header {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #fff;
				height: 80rpx;
				font-size: 36rpx;
				font-weight: 700;
				z-index: 9;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.goback-box {
				position: absolute;
				left: 18rpx;
				top: 0;
				height: 80rpx;
				display: flex;
				align-items: center;
			}

			.goback {
				z-index: 100;
				width: 34rpx;
				height: 34rpx;
			}
		}
	}

	.yanzheng {
		width: 660rpx;
		height: 220rpx;
		background-color: #fff;
		margin-left: 45rpx;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;
		margin: -100rpx auto 0;
		position: relative;
		z-index: 2;

		.top {
			display: flex;
			justify-content: start;
			padding-top: 40rpx;

			.tex {
				size: 50rpx;
				padding-left: 25rpx;
				padding-top: 5rpx;
			}

			.inp {
				padding-left: 25rpx;
			}
		}
	}

	.sc {
		width: 660rpx;
		height: 400rpx;
		background-color: #fff;
		margin-top: 20rpx;
		margin-left: 45rpx;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;

		.poto {
			padding-top: 30rpx;
			margin-left: 25rpx;
			size: 50rpx;
		}

		.pto {
			width: 312rpx;
			min-height: 202rpx;
			margin-left: 175rpx;
			margin-top: 60rpx;
		}
	}

	.bt {
		width: 650rpx;
		background: linear-gradient(90deg, #ff8f3b, #ff3107);
		border-radius: 45rpx;
		margin-top: 90rpx;
		margin-left: 38rpx;
		color: #fff;
		height: 80rpx !important;
		line-height: 80rpx !important;
		&.loding{
			background: #e3e3e3;
		}
	}
</style>