// pages/home/home.js
var app = getApp();
var baseUrl = app.globalData.baseUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    load_finish:false,
    text_tip: "去完善",
    taxlist: ['']
  },

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

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
    console.log('onShow')
    this.getTaxList()
  },

  getTaxList: function() {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var Authorization = app.globalData.Authorization;
    console.log('Authorization', Authorization)
    if (!Authorization || Authorization.length < 10) {
      return
    }
    wx.request({
      url: baseUrl + 'persontax/v1/personal-taxes',
      method: "GET",
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": Authorization
      },
      data: {
        'all': true
      },
      success: function(res) {
        console.log(res.data)
        that.setData({
          taxlist: res.data.items
        })
        if (res.data.items && res.data.items.length > 0) {
          that.getStatus(res.data.items)
        }
      },
      fail(res) {
        console.log(res.data)
      },
      complete(){
        wx.hideLoading()
        that.setData({
          load_finish:true
        })
      }
    })
  },

  getStatus: function(data) {
    console.log('data', data )
    if (data[0].family_ties.length < 1 && data[0].name.length > 0 && data[0].taxpayer_status.length > 0 && data[0].id_card_type.length > 0 && data[0].id_card_no.length > 0 && data[0].mobile.length > 0 && data[0].is_investor.length > 0 && data[0].is_specific_profession.length > 0) {
      this.setData({
        text_tip: '去查看'
      })
    } else {
      this.setData({
        text_tip: '去完善'
      })
    }
  },

  goadd: function(e) {
    console.log(e)
    wx.navigateTo({
      url: '../addinfo/addinfo',
    })
  },

  goedit: function(e) {
    console.log(e)
    wx.navigateTo({
      url: '../editinfo/editinfo?id=' + e.currentTarget.id,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

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

  },

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

  },

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

  },

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

  }
})