<template>
	<view class="main">
		<view class="h1">
			报名驾校前
		</view>
		<view class="tit">
			请按提示完成实名认证
		</view>
		<view class="iconImg">
			<image src="../../../static/images/icon/weishiming@2x.png" mode="widthFix"></image>
		</view>
		<view class="blueTxt">
			手持身份证准备拍摄，并保持光线充足和网络良好
		</view>
		<view class="btn" @click="start">
			点击开始实名认证
		</view>
	</view>
</template>

<script>
	import utilsApi from '@/api/utils.js'
	// #ifdef APP-PLUS
		const plug=uni.requireNativePlugin("Html5app-AliyunFaceVerify");
	// #endif
	export default {
		data() {
			return {
				checked: true,
				verifyToken: '',
				timer: null
			}
		},
		onLoad(options) {
			this.trainingApplyId = options.trainingApplyId
			
			// this.timer = setInterval(()=>{
			// 	this.getVerifyResultFn()
			// },3000)
		},
		
		onHide() {
			clearInterval(this.timer)
		},
		onUnload() {
			clearInterval(this.timer)
		},
		methods: {
			async getVerifyTokenFn(trainingApplyId) {
				let _this = this
				const [nulls, res] = await utilsApi.getVerifyToken({trainingApplyId: this.trainingApplyId})
				console.log('实名token')
				console.log(res.data)
				// #ifdef APP-PLUS
				console.log('****************')
				try{
					plug.RPManual({"verifyToken":res.data},ret=>{
						if(ret.code==1) {
							// 实名认证成功
							// getApp().globalData.realAuthsuccee = true
							uni.$emit('isRealAuthsucceeFn')
							_this.$store.commit('upDateRealAuthsuccee', true)
							clearInterval(_this.timer)
							uni.navigateBack()
						}
						console.log(ret)
					});
				}catch(e){
					console.log(e)
				}
				
				// #endif
				
			},
			// 检查实名认证结果
			async getVerifyResultFn() {
				const [nulls, res] = await utilsApi.getVerifyResult({trainingApplyId: this.trainingApplyId})
				if(res.data&&res.data.verifyStatus==1) {
					uni.showToast({
						title: '实名认证成功'
					})
					
					
					uni.navigateBack()
				}
				console.log(res)
			},
			start() {
				this.getVerifyTokenFn()
				
			},
		},
		
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		text-align: center;
		padding: 0 60rpx;
		background-color: #fff;
	  .h1 {
		font-size: 26rpx;
		line-height: 100rpx;
		color: #333;
		text-align: center;
	  }
	
	  .tit {
		font-size: 36rpx;
		font-weight: 700;
	  }
	
	  .iconImg {
		  width: 90%;
		  margin-top: 30rpx;
	    image {
			
	    }
	  }
	
	  .blueTxt {
		font-size: 28rpx;
		color: $themC;
		padding: 30rpx 0 60rpx 0;
	  }
	
	  .btn {
		width: 100%;
		text-align: center;
		line-height: 96rpx;
		background-color: $themC;
		color: #fff;
		height: 96rpx;
		border-radius: 8rpx;
	  }
	}
</style>