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

  /**
   * 页面的初始数据
   */
  data: {
    verify_dialog: getApp().globalData.OSSImgHeader + "verify_dialog.png",
    isshow: false,
    onresume: false,
    has_verify: true,
    guide_bg: getApp().globalData.OSSImgHeader+"guide_bg.png"
  },

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

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

  },

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

  //判断该雇员是否有姓名和身份证号
  checkUserInfo: function (skip_type) {
    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(skip_type);
      } else {
        that.setData({
          has_verify: false
        })
      }
    }
  },

  taxconfirm: function(skip_type) {
    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
          })
          if(skip_type=="1"){
            wx.navigateTo({
              url: '../taxperson/home',
            })
          } else if (skip_type == "2") {
            wx.navigateTo({
              url: '../addtionalreduce/home',
            })
          } else if (skip_type == "3") {
            wx.navigateTo({
              url: '../advancepayment/adPayHome',
            })
          } else if (skip_type == "4") {
            wx.navigateTo({
              //第一版本的跳转路径
              // url: '../finalpayment/home',
              url:'../finalpay/home',
            })
          } 
        }
      }
    })

  },

  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
          })
          wx.navigateTo({
            url: '../taxperson/home',
          })
        }
      }
    })
  },

  /**
   * 自然人信息采集
   */
  gotaxPerson: function() {
    this.checkUserInfo("1")
  },

  /**
   * 专项附加扣除
   */
  goAdditionalDiduction: function() {
    this.checkUserInfo("2")
  },

  /**
   * 预扣预缴
   */
  goAdvancePayment: function() {
    this.checkUserInfo("3")
  },

  /**
   * 汇算清缴
   */
  goFinalPayment: function() {
    this.checkUserInfo("4")
  },

  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
    })
  },

  close02:function(){
    this.setData({
      has_verify: true
    })
  },

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

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

  },

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

  },

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

  }
})