const _my = require("../../../__antmove/api/index.js")(my);
const wx = _my;
// pages/temporary_prove/index.js
// index.js
var verify = require("../../../utils/util/util");
const face = require("../../../utils/faceCheck/faceCheck");
const {
  pro_baseUrl_wxrlxf
} = require("../../../utils/func/request");
const getPhone = require("../../../utils/getPhone/wx_getPhone");
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 胶囊位置信息
    statusBarHeight: 0,
    titleBarHeight: 0,
    // 基础路径
    baseUrl: pro_baseUrl_wxrlxf,
    inputName: "",
    inputIdcard: "",
    phone: "",
    workPlace: "",
    carNumber: "",
    warnName: 1,
    //姓名校验信息
    warnIdcard: 1,
    //身份证校验信息
    disableSubmit: true,
    iscarNumber: false //车牌键盘弹起
  },

  //获得姓名
  getInputName(e) {
    this.setData({
      warnName: 1,
      inputName: e.detail.value
    });
    if (!e.detail.value) {
      this.setData({
        warnName: "您输入的姓名不可以为空!"
      });
    } else {
      this.setData({
        warnName: 2
      });
    }
  },
  //获得身份证号
  getInputIdcard(e) {
    var result = verify.isCardID(e.detail.value);
    if (!result.state) {
      this.setData({
        warnIdcard: result.data
      });
    } else {
      this.setData({
        warnIdcard: 2,
        inputIdcard: e.detail.value
      });
    }
  },
  //获取手机号
  async getPhoneNumber(e) {
    wx.showLoading({
      title: "获取中...",
      mask: true
    });
    var result = await getPhone(e);
    wx.hideLoading();
    this.setData({
      phone: result
    });
  },
  // 单位
  getValue(e) {
    let type = e.currentTarget.dataset.type;
    this.setData({
      [type]: type === "workPlace" ? e.detail.value : e.detail
    });
  },
  // 车牌键盘弹起
  getCarNumber() {
    this.setData({
      iscarNumber: true
    });
  },
  //实名认证
  submit() {
    let {
      inputName,
      inputIdcard,
      phone,
      workPlace,
      carNumber
    } = this.data;
    app.data.workPlace = workPlace;
    app.data.carNumber = carNumber;
    face.intoFace_wxrlxf_FKJ(inputName, inputIdcard, phone).then(suc => {
      this.data.flag = 1;
    }, err => {
      console.log(err);
    });
  },
  //验证人脸
  async doFaceCheck() {
    let taskId = wx.getStorageSync("wx_dateCode_FKJ");
    // taskId = '355411594437459968'
    if (!taskId) return;
    var res = await face.getFace_wxrlxf("/api/next/getVisitorUserInfo", "get", {
      taskId
    });
    //todo--人脸结果
    if (res.code === 200) {
      wx.setStorageSync("machineInfo_FKJ", res.data);
      wx.redirectTo({
        url: "/pages/temporary_prove_FKJ/rlxf_pass/rlxf_pass"
      });
    } else {
      my.alert({
        title: "提示",
        content: "认证失败请重新认证!"
      });
    }
  },
  //查看照片
  watch() {
    wx.previewImage({
      urls: [this.data.baseUrl + "/file/img/instruction.png"]
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.setData({
      statusBarHeight: app.globalData.statusBarHeight,
      titleBarHeight: app.globalData.titleBarHeight
    })
    var url = decodeURIComponent(options.q);
    var json = verify.GetQueryJson(url);
    // json = {
    //     type: 2,
    // }
    if (json && json.type == 2) {
      // 判断缓存
      var machineInfo_FKJ = wx.getStorageSync("machineInfo_FKJ");
      if (machineInfo_FKJ) {
        wx.redirectTo({
          url: "/pages/temporary_prove_FKJ/rlxf_pass/rlxf_pass"
        });
      }
    } else {
      my.alert({
        title: "提示",
        content: "未检测到设备码,请扫正确的二维码进入小程序哦~"
      });
      this.setData({
        disableSubmit: false
      });
      return;
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.flag === 1) {
      this.doFaceCheck();
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  antmoveAction: function () {
    //执行时动态赋值，请勿删除
  }
});