const app = getApp();
// 初始化慧眼实名核身组件
const verify = require('../../../verify_mpsdk/main');
verify.init();
Page({

 
  data: {
    optioninfo:'',
    token:'',
    wxauthentication: [],     //我的微信
  },


  onLoad: function (options) {

        var that = this;
    
    // getApp().showLoading();   //提示加载中
        //  认证信息
    let optioninfo_url = 'my/authentication/adopticonone';
        let optioninfo_data = {
          // uid: options.uid,
        };
        app.postRequest(optioninfo_url, optioninfo_data, function (res) {
          console.log(res.data);
          if (res.code == 201) {

            that.setData({
              optioninfo: res.data,

            })
          }
        })

        //  我的微信
        let wxauthentication_url = 'my/wxqrcode/wxauthentication';
        let wxauthentication_data = {
        };
        app.postRequest(wxauthentication_url, wxauthentication_data, function (res) {
          // console.log(res.data);
          that.setData({
            wxauthentication: res.data
          })

        })


  },
  faceid:function(e){
    let that = this;
    let optioninfo_url = 'my/faceid/getbiztoken';
    let optioninfo_data = {};
    app.postRequest(optioninfo_url, optioninfo_data, function (res) {
      console.log(res.data);
      if (res.code == 201) {

        switch (res.data.is_ocr){
          case 1:
            wx.navigateTo({
              url: '../Realname/Realname'
            });
              //跳转到显示页面
            break;  
          case 2:
            that.setData({
              token: res.data.biztoken
            })
            that.gotoVerify();
            break;  
        }
     
       
      }else{
        wx.showModal({
          content: '实名认证失败，请稍后再试',
          showCancel: false
        })
      }

    })
    // 
   

  
    return false;
    
  },
  gotoVerify: function () {
    let self = this;

    // 调用实名核身功能
    wx.startVerify({
      // 传入的数据
      data: {
        token: this.data.token,
        // endPath:"/pages/verify/verify"
      },
      // 验证成功后触发
      success: function (data) {
        // console.log('收到验证成功的回调')
        // console.log(data);
        let optioninfo_url = 'my/faceid/biztokenresult';
        let optioninfo_data = {biz_token:data.BizToken};
        app.postRequest(optioninfo_url, optioninfo_data, function (res) {
       
              if (res.code == 201) {
                wx.showModal({
                  content: res.msg,
                  showCancel: false
                })
              } else {
                wx.showModal({
                  content: res.msg,
                  showCancel: false
                })
              }

        })
        //这里是受到认证完成的回调结果
        // setTimeout(()=> {
        //   wx.showModal({
        //     title: '收到验证成功的回调',
        //     content: `${data.BizToken}`,
        //     showCancel: false
        //   })
        // },500)
      },
      // 验证失败时触发
      fail: function (err) {
        console.log('收到验证失败的回调')
        console.log(err);
        setTimeout(() => {
          wx.showModal({
            title: '收到验证失败的回调',
            content: `${err.ErrorMsg}`,
            showCancel: false
          })
        }, 500)
      }
    });
  }

})