const app = require('../../utils/util.js');
const tools = require('../../utils/tools.js');
Page({
  data: {
    info: {}
  },
  wanshan() {
    wx.navigateTo({
      url: '/pages/finishInfo/finishInfo',
    })
  },
  shenfen() {
    wx.navigateTo({
      url: '/pages/idCardDetail/idCardDetail',
    })
    // if (this.data.info.headPicPath) {
    //   wx.navigateTo({
    //     url: '/pages/idCardDetail/idCardDetail',
    //   })
    // } else {
    //   wx.navigateTo({
    //     url: '/pages/idCard/idCard',
    //   })
    // }
  },
  xiugai() {
    wx.navigateTo({
      url: '/pages/updatepassword/updatepassword',
    })
  },
  aboutUs() {
    wx.navigateTo({
      url: '/pages/aboutUs/aboutUs',
    })
  },
  adviceSubmit() {
    wx.navigateTo({
      url: '/pages/adviceSubmit/adviceSubmit',
    })
  },
  tuichu() {
    wx.showModal({
      showCancel: true,
      title: '是否退出？',
      content: "退出后将会解绑当前微信号,无法使用当前微信号自动登陆",
      success: (res) => {
        if (res.confirm) {
          wx.showLoading({
            mask: true,
            title: '退出中',
          })
          wx.request({
            url: app.globalData.publicUrl + '/applet/unbind',
            method: "GET",
            data: {
              appletsId: wx.getStorageSync('openId')
            },
            success: (res) => {
              console.log(res)
              wx.hideLoading()
              if (res.data.code == 0) {
                wx.clearStorageSync();
                wx.switchTab({
                  url: '/pages/index/index',
                })
              } else {
                wx.showModal({
                  showCancel: false,
                  content: '退出失败请联系管理员'
                })
              }
            },
            fail: () => {
              wx.hideLoading()
            }
          })
        }
      }
    })

  },
  oftenAnswer() {
    wx.navigateTo({
      url: '/pages/question/question',
    })
  },
  onShow() {
    tools.rzStatus().then((res) => {
      if (res.data.code == 0) {
        if (res.data.data) {
          wx.request({
            url: app.globalData.publicUrl + '/applet/findUserInfo',
            method: "GET",
            header: {
              appletsId: wx.getStorageSync('openId')
            },
            success: (res) => {
              this.setData({
                info: res.data.data
              })
            }
          })
          tools.finishInfo().then((res) => {
            console.log(res.data.data.perfect, '我完善信息了吗 1代表完后 0代表未完成')
            console.log(res.data.data.comparison, '我人脸识别过了吗 1代表完后 0代表未完成')
            this.setData({
              perfect: res.data.data.perfect,
              comparison: res.data.data.comparison
            })
          })
        }
      } else {
        wx.clearStorageSync();
        wx.showModal({
          showCancel: false,
          content: '当前您未登录,请登录',
          success(res) {
            if (res.confirm) {
              wx.redirectTo({
                url: '/pages/login/login',
              })
            }
          }
        })
      }
    })
  },
  onHide() {
    this.setData({
      info: ''
    })
  }
})