freeIncomeDetail.js 6.0 KB
var app = getApp();
var baseUrl = app.globalData.baseUrl;
Page({

  /**
   * Page initial data
   */
  data: {
    settlement_record_id: "",
    year: "2019",
    showAddView:false,
    infoList: [{}],
    total_account: 0,
    project: ["正常工资薪金", "劳务报酬", "稿酬", "特许经营权使用费"],
    deductcontent: ["高级专家延长离退休期间工薪免征个人所得税", "解除劳动合同当地工资3倍以内免税", "符合条件的津补贴免征个人所得税", "生育津贴和生育医疗费免税", "工伤保险免税", "符合条件的外交人员免征个人所得税", "外籍个人出差补贴免税", "外籍个人探亲费、语言训练费、子女教育费免税", "外籍个人生活费用免税", "符合条件的外籍来华专家工资薪金所得免征个人所得税", "薪金所得免征个人所得数", "横琴、香港、澳门居民免税", "平潭台湾居民免税", "安家费、退职费、退休工资、离休工资、离休生活补助费免税"],
    deductproperty: ["其他"],
    income_item: "",
    reduction_item: "",
    reduction_nature: "",
    exempt_income: "",
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function(options) {
    this.setData({
      settlement_record_id: options.id
    })
    this.getInfoList()
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function() {

  },

  getInfoList: function() {
    var that = this
    this.Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/exempt-income",
      header: {
        'Authorization': this.Authorization
      },
      data: {
        "years": that.data.year,
        "settlement_record_id": that.data.settlement_record_id
      },
      success: function(result) {
        console.log("infoList", result)
        if (result.statusCode == 200) {
          that.setData({
            total_account: result.data.total_account,
            infoList: result.data.items,
            income_item: "",
            reduction_item: "",
            reduction_nature: "",
            exempt_income: "",
          })
        }
      },
    })
  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function() {

  },

  // 所得项目
  bindProjectChange: function(e) {
    console.log('picker,携带值为', e.detail.value)
    this.setData({
      income_item: this.data.project[e.detail.value]
    })
  },

  // 减免事项名称
  bindDeductContent: function(e) {
    console.log('picker,携带值为', e.detail.value)
    this.setData({
      reduction_item: this.data.deductcontent[e.detail.value]
    })
  },

  // 减免性质名称
  bindDeductProperty: function(e) {
    console.log('picker,携带值为', e.detail.value)
    this.setData({
      reduction_nature: this.data.deductproperty[e.detail.value]
    })
  },

  // 免税收入金额
  bindIncome: function(e) {
    console.log('输入框', e.detail.value)
    this.setData({
      exempt_income: e.detail.value
    })
  },

  addItem: function() { //继续添加
    if (!this.data.showAddView){//是否新增了view
      this.setData({
        showAddView:true
      })
      return
    }
    if (!this.data.income_item || this.data.income_item.length < 1) {
      this.showToast("请选择所得项目")
      return
    }
    if (!this.data.reduction_item || this.data.reduction_item.length < 1) {
      this.showToast("请选择减免事项名称")
      return
    }
    if (!this.data.reduction_nature || this.data.reduction_nature.length < 1) {
      this.showToast("请选择减免性质名称")
      return
    }
    if (!this.data.exempt_income || this.data.exempt_income.length < 1) {
      this.showToast("请填写免税收入金额")
      return
    }
    this.goSubmit("1")
  },

  goSubmit: function(type) {//type=“1”,继续添加(当前页面),type=2保存,返回列表
    if (!this.data.income_item || this.data.income_item.length < 1) {
      this.showToast("请选择所得项目")
      return
    }
    if (!this.data.reduction_item || this.data.reduction_item.length < 1) {
      this.showToast("请选择减免事项名称")
      return
    }
    if (!this.data.reduction_nature || this.data.reduction_nature.length < 1) {
      this.showToast("请选择减免性质名称")
      return
    }
    if (!this.data.exempt_income || this.data.exempt_income.length < 1) {
      this.showToast("请填写免税收入金额")
      return
    }
    var that = this
    this.Authorization = app.globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/exempt-income",
      header: {
        'Authorization': this.Authorization
      },
      method: "POST",
      data: {
        "years": that.data.year,
        "settlement_record_id": that.data.settlement_record_id,
        "income_item": that.data.income_item,
        "reduction_item": that.data.reduction_item,
        "reduction_nature": that.data.reduction_nature,
        "exempt_income": parseFloat(that.data.exempt_income),
      },
      success: function(result) {
        console.log("infoList", result)
        if (result.statusCode == 200) {
          if(type=='1'){
            that.getInfoList()
            that.setData({
              showAddView:true
            })
          }else {
              wx.navigateBack({
                delat:1
              })
          }
        }
      },
    })
  },

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

  },

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

  },

  showToast: function (data) {
    if (data && data.length > 0) {
      wx.showToast({
        title: data,
        icon: "none",
        duration: 2000
      })
    }
  },

  /**
   * 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() {

  }
})