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

  /**
   * Page initial data
   */
  data: {
    datas: ["", ""],
    is_declared: false,
    additionlist: [],
    declareStatus: {
      "to_declare ": "待申报",
      "declaring": "申报中",
      "success": "审核成功",
      "failed": "审核失败"
    },
    additiontitle: {
      "children_education": "子女教育",
      "continuing_education": "继续教育",
      "support_duty": "赡养老人",
      "medical_fund": "大病医疗",
      "house_fund_rent": "住房",
      "house_fund_loan": "住房",
      "house_fund": "住房"
    },
    reducetype:{
      "":"月",
      "month":"月",
      "year":"年"
    },
    datas02: ["子女教育", "继续教育", "赡养老人", "大病医疗", "住房贷款利息"]
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    console.log("onLoad");
  },

  godeclare: function (e) {
    console.log("godeclare", e);
    var newdata = this.data.additionlist[e.currentTarget.id]
    wx.navigateTo({
      url: 'godeclare/godeclare?legal_entity_id=' + newdata.legal_entity_id + "&legal_entity=" + newdata.legal_entity,
    })
  },

  godetail: function () {
    wx.navigateTo({
      url: 'godetail/godetail',
    })
  },

  lookandadd: function (e) {
    var str = e.currentTarget.id.split('-')
    var data = this.data.additionlist;
    console.log("lookandadd", str);

    wx.navigateTo({
      url: 'lookandupdate/lookandupdate?status=' + data[str[0]].addition_items[str[1]].addition_category + "&legal_entity_id=" + data[str[0]].legal_entity_id + "&legal_entity=" + data[str[0]].legal_entity,
    })
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {
    console.log("onReady");
  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {
    console.log("onShow");
    var that = this
    this.getAdditionList()
  },

  getAdditionList: function () {
    var that = this;
    var Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + 'persontax/v1/person-additions',
      data: {
        limit: 10,
        offset: 0
      },
      header: {
        'content-type': 'application/json',
        "Authorization": Authorization
      },
      success: function (res) {
        if (res && res.data) {
          console.log("res", res)
          that.setData({
            additionlist: res.data.items
          })
        }
      }
    })
  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  }
})