// pages/main/guide/guide.js
var baseUrl = getApp().globalData.baseUrl;
let Authorization = '';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow: false,
    mobile:"",
    onresume: false,
    has_verify: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    console.log("onshow")
    this.setData({
      onresume:true
    })
    this.checkUserInfo()

  },

  //判断该雇员是否有姓名和身份证号
  checkUserInfo: function() {
    var that = this;
    Authorization = getApp().globalData.Authorization;
    var real_auth_status = getApp().globalData.real_auth_status
    console.log("real_auth_status", real_auth_status)
    console.log("Authorization", Authorization)
    if (Authorization && Authorization.length > 10) {
      // that.setData({
      //   has_verify: false
      // })
      if (real_auth_status == 'active') { //不需要再实名认证
        that.setData({
          has_verify: true,
          onresume: false,
        })
        that.taxconfirm();
      } else {
        that.setData({
          has_verify: false
        })
      }
      // wx.request({
      //   url: baseUrl + 'socialwork/v1/employees/verify',
      //   data: {},
      //   header: {
      //     'content-type': 'application/json',
      //     "Authorization": Authorization
      //   },
      //   success: function(res) {
      //     if (res.statusCode && res.statusCode >= 300) {
      //       wx.showToast({
      //         title: res.data.message,
      //         icon: 'none',
      //         duration: 1000
      //       })
      //     } else {
      //       // that.setData({
      //       //   has_verify: false
      //       // })
      //       if (!res.data.need_verify) { //不需要再实名认证
      //         that.setData({
      //           has_verify: true
      //         })
      //         that.taxconfirm();
      //       } else {
      //         that.setData({
      //           has_verify: false
      //         })
      //       }
      //     }
      //   }
      // })
    }
  },

  taxconfirm: function() {
    var that = this;
    Authorization = getApp().globalData.Authorization;

    wx.request({
      url: baseUrl + 'persontax/v1/personal-taxes-confirm',
      header: {
        'content-type': 'application/json',
        "Authorization": Authorization
      },
      success: function(res) {
        console.log("taxconfirm", res)
        if (res.statusCode == 200 && !that.data.isshow && res.data.status != '0') { //未完善
          that.showModal(res.data)
        } else {
          that.setData({
            isshow: false
          })
        }
      }
    })

  },

  showModal: function(data) {
    var that = this
    that.setData({
      isshow: true
    })
    wx.showModal({
      title: '温馨提示',
      content: '您的自然人基础信息尚未完善,请先完善基础信息',
      confirmText: '立即完善',
      showCancel: false,
      confirmColor: '#357aeb',
      success(res) {
        if (res.confirm) {
          that.setData({
            isshow: false
          })
          that.gotaxPerson()
        }
      }
    })
  },

  /**
   * 自然人信息采集
   */
  gotaxPerson: function() {
    wx.navigateTo({
      url: '../taxperson/home',
    })
  },

  /**
   * 专项附加扣除
   */
  goAdditionalDiduction: function() {
    wx.navigateTo({
      url: '../addtionalreduce/home',
    })
  },

  /**
   * 预扣预缴
   */
  goAdvancePayment: function() {
    wx.navigateTo({
      url: '../advancepayment/adPayHome',
    })
  },

  /**
   * 汇算清缴
   */
  goFinalPayment: function() {
    wx.navigateTo({
      url: '../finalpayment/home',
    })
  },

  gochat: function() {
    wx.navigateTo({
      url: '../smartchat/chat',
    })
  },

  loginout: function() {
    wx.showModal({
      title: '退出登录',
      content: '确认要退出登录吗?',
      confirmText: '确定',
      showCancel: true,
      cancelText: "取消",
      confirmColor: '#357aeb',
      success(res) {
        console.log("loginout", res)
        if (res.confirm) {
          wx.reLaunch({
            url: '../../login/login'
            // url: '../../getPhone/getPhone'
          })
        }
      }
    })
  },


  go_verify_idcard: function() { //身份证认证
    wx.navigateTo({
      url: '../verify/verify_info?foreigner=false',
    })
  },

  go_verify: function() { //外籍人员信息认证
    wx.navigateTo({
      url: '../verify/verify_info?foreigner=true',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    console.log("onhide")
    this.setData({
      onresume: false
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
     
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})