<template>
    <view class="content">
        <image class="logo" src="/static/logo.png"></image>
        <view>
            <text class="title">{{title}}</text>
        </view>

        <button @click="navigateToIdentityAuth">开始认证</button>


        <!--<button @click="face">人脸认证</button>-->

        <!--<button @click="faceCheck">人脸认证结果查询</button>-->

        <button @click="navigateToIdentitySign">去签约</button>
        <!--<button @click="navigateToIdentityUserSign">用户签署</button>-->


        <button @click="navigateToIdentityReport">报告列表</button>


    </view>
</template>

<script>
import {authApi} from "@/api/auth";

export default {
    data() {
        return {
            title: 'Hello'
        }
    },
    onLoad() {

    },
    methods: {
        navigateToIdentityAuth() {
            uni.navigateTo({
                url: '/pages/auth/index', // 身份认证页面路径
            });
        },




        face(){
            let url = 'https://miniprogram-kyc.tencentcloudapi.com/api/web/login?webankAppId=IDAfndk9&version=1.0.0&nonce=WdOT9FJOZmsNoBAYrEaXM2deqeOMUUpy&orderNo=TC511322199205103651741865247778&h5faceId=tx00e36462c22d361bf7153f2e80d767&url=https%3A%2F%2Fprev.asign.cn%2Fauth%2Fface%2Fredirect%2F25330295799061848564984&resultType=1&userId=51132219920510365X&sign=F6DC906E9551C4EA9867DF47F3FFF6F32DFE9C80&from=browser';
            uni.navigateTo({
                url: `/pages/auth/face-auth?faceUrl=${encodeURIComponent(url)}`
            });

            // 监听认证结果
            uni.$on('FACE_AUTH_SUCCESS', this.handleAuthSuccess);
        },

        faceCheck(){
            let message = {code:100000,msg:'ok'}

            if (message.code === 100000) {
                message['bizId'] = '0p9Rb]TZ';
                message['serialNo'] = 'PA10320250314113651942815';


                let res = authApi.faceCheckApi(message)

                console.log('res',res)

            }





        },


        navigateToIdentitySign(){
            uni.navigateTo({
                url: '/pages/contract/index', // 身份认证页面路径
            });
        },

        navigateToIdentityReport(){
            uni.navigateTo({
                url: '/pages/contract/report', // 身份认证页面路径
            });
        },




        navigateToIdentityUserSign(){
            let url = 'https://h5.asign.cn/web/short/MrqQZb493218';
            let contractId = 1;
            uni.navigateTo({
                url: `/pages/contract/user-sign?contractId=${contractId}&userSignUrl=${encodeURIComponent(url)}`
            });

            //监听签署结果
            uni.$on('SIGN_SUCCESS', this.handleSignxSuccess);
        },

        handleSignxSuccess(data) {
            console.log('[test]监听签署结果 成功',data)
        },


        // 新增结果处理方法
        handleAuthSuccess(data) {
            console.log('我是测试的检测活体检测 ',data)

            uni.showToast({ title: '活体认证成功' });
            // 处理后续业务逻辑...
            // 例如更新认证状态、跳转回个人中心等
            setTimeout(() => {
                uni.navigateBack({ delta: 2 }); // 返回两级页面
            }, 1500);
        },
    }
}
</script>

<style>
.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;


}

button {
    margin-top: 20rpx;
}
.logo {
    height: 200rpx;
    width: 200rpx;
    margin: 200rpx auto 50rpx auto;
}

.text-area {
    display: flex;
    justify-content: center;
}

.title {
    font-size: 36rpx;
    color: #8f8f94;
}
</style>
