<template>
	<view class="page-body">
		<view class="action-btn">
		  <button @click="handleRegister()" class="register-btn cu-btn block bg-blue lg round">点击身份证实名认证</button>
		</view>
		<view class="action-btn">
		  <button @click="handlePassport()" class="register-btn cu-btn block bg-blue lg round">点击护照实名注册</button>
		</view>
	</view>
</template>

<script>
	import {
		startEid
	} from '@/mp_ecard_sdk/main.js'
	import {
		getEidtoken,
		sendEidtoken
	} from "@/api/login.js"
	export default{
		data(){
			return{
				eidToken: "",
				vals:1
			}
		},
		methods:{
			// 获取eidtoken
			getEidtokenFn() {
				getEidtoken({}).then(res => {
					this.eidToken = res.data.EidToken
				})
			},
			// 点击实名认证
			handleRegister() {
				let that = this
				startEid({
					data: {
						token: this.eidToken,
					},
					verifyDoneCallback(res) {
						const {
							token,
							verifyDone
						} = res;
						console.log('收到核身完成的res:', res);
						console.log('核身的token是:', token);
						console.log('是否完成核身:', verifyDone);
						sendEidtoken({
							"eidToken": token
						}).then(res => {
							// that.certificationStatus = '1
							let params = {}
							params.nickName = res.data.name;
							params.idCard = res.data.identityNo;
							params.id = res.data.id;
							console.log(params,"PPPPPPPPPPPPP");
							uni.navigateTo({
								url: '/pages/register?params=' + JSON.stringify(
									params)
							});
						})
					},
				});
			},
			// 点击护照注册
			handlePassport(){
				uni.navigateTo({
					url: `/pages/register?valus=${this.vals}`
				});
			}
		},
		onLoad() {
			this.getEidtokenFn()
		},
	}
</script>

<style lang="scss">
	.page-body{
		background-color: #ffffff;
		.register-btn{
			margin-top: 30rpx;
		}
	}
</style>