//index.js
//获取应用实例
const app = getApp()
var counter = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    src: "../../assets/imgs/takephoto.jpg",
    takephoto_txt: "点击图标开始认证识别",
    dongtaishuju: 0,
    phone_model: '',
    benchmarkLevel: 0,
    content: "1.识别时请将整个结构三维码放到识别框中，保持画面清晰稳定直到显示认证结果\r\n2.确保标签与背景保持在同一平面内，便于手机相机聚焦\r\n3.AI验证的标签需要与扫描进入主页的这枚标签一致（否则会提示码不同）",
    showCover: true,
    status_zhi: '',
    extraData: '',
    all_info: '',
    cpid: '',
    showmodel:true,
    zhongfen:false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options.cpid', options.cpid)
    // 使用正则表达式来匹配数字和字母
    var reg = /^[0-9a-zA-Z]+$/;
    // const labelcode = extraData.cpid
    if (options.cpid && options.cpid.length > 14 && reg.test(options.cpid)) {
      console.log('中汾页面');
      this.setData({
        zhongfen:true,
        showmodel:false
      })
     console.log('this.data.zhongfen',this.data.zhongfen)
      // this.setData({
      //   webviewUrl: `https://tjfnew.china315net.com/dist/zhongfen/route.ashx?cpid=${options.cpid}`,
      // });
      wx.navigateTo({
        url:`/pages/anti/anti?cpid=${options.cpid}`
      })
    }
    // wx.clearStorageSync(); // 清空本地缓存数据
    wx.getSystemInfo({
      success: (res) => {
        console.log('获取用户信息res', res)
        let all_info = res
        // console.log('all_info',all_info)
        wx.setStorage({
          key: 'all_info',
          data: all_info
        });
        let phone_model = res.model;
        let benchmarkLevel = res.benchmarkLevel;
        // console.log('benchmarkLevel',benchmarkLevel)
        // console.log('phone_model',phone_model)
        wx.setStorage({
          key: 'phone_model',
          data: phone_model
        });
        wx.setStorage({
          key: 'benchmarkLevel',
          data: benchmarkLevel
        })
      },
    })
  },
  webviewError: function (e) {
    console.log('webview 加载错误', e);
  },
  webviewMessage: function (e) {
    console.log('webview 收到消息', e);
  },
  /**
   * 生命周期函数--监听被展示时调用
   */
  onShow: function (options) {
    const extraData = wx.getStorageSync('extraData')
    // this.setData('extraData',extraData)
    // console.log('extraData', extraData)
    // console.log('extraData.success', extraData.success)
    if (typeof extraData.success !== 'undefined') {
      console.log('盛意标签');
      var status_zhi = ''
      wx.setStorage({
        'key': 'status_zhi',
        data: status_zhi
      })
      // console.log('status_zhi',status_zhi)
    } else {
      console.log('不是盛意标签')
      var status_zhi = true
      wx.setStorage({
        'key': 'status_zhi',
        data: status_zhi
      })
      // console.log('status_zhi',status_zhi)
    }
    if(this.data.showmodel === true){
      wx.showModal({
        title: '注意事项：',
        content: this.data.content,
        showCancel: false, // 是否显示取消按钮，默认值 true
        // cancelText: '非常自信', // 取消按钮的文字，默认值 '取消'
        confirmText: '我已知晓', // 确定按钮的文字，默认值 '确定'
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          }
        },
        fail: function (res) {
          console.log(res)
        }
      })
    }
  },
  /**ss
   * 跳转到拍照界面
   */
  takePhoto: function (e) {
    wx.navigateTo({
      // url: '../takePhoto/takePhoto'
      url: '../cameraTakePhoto/cameraTakePhoto',
    })
    counter++;
    this.setData({
      dongtaishuju: counter
    });
    if (this.data.dongtaishuju > 3) {
      this.setData({
        dongtaishuju: 0
      })
    }
    wx.setStorage({
      'key': 'dongtaishuju',
      'data': this.data.dongtaishuju
    })
    // console.log('this.data.dongtaishuju',this.data.dongtaishuju)
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},

  attention() {
    wx.reLaunch({
      url: '../attention/attention',
    })
  },
})