donationDetail.js 6.5 KB
// pages/main/finalpay/donationDetail/donationDetail.js
var app = getApp();
var baseUrl = app.globalData.baseUrl;
Page({

  /**
   * Page initial data
   */
  data: {
    settlement_record_id:"",
    year: "2019",
    showAddView: false,
    infoList: [{}],
    total_account: 0,
    deductPick: ["30%", "100%"],
    "donated_unit_code": "",
    "donated_unit_name": "",
    "donation_code": "",
    "donation_year": "",
    "donation_account": "",
    "deduction_ratio": "", //扣除比例 
    "comment": "",
  },

  /**
   * 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/donation-deduction",
      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,
            "donated_unit_code": "",
            "donated_unit_name": "",
            "donation_code": "",
            "donation_year": "",
            "donation_account": "",
            "deduction_ratio": "", //扣除比例 
            "comment": "",
          })
        }
      },
    })
  },


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

  },

  getInputInfo:function(e){//
    console.log("输入框", e.currentTarget.id,e.detail.value)
    var key = e.currentTarget.id+""
    if ("donated_unit_code"==key){
      this.setData({"donated_unit_code": e.detail.value,})
    }
    if ("donated_unit_name" == key) {
      this.setData({ "donated_unit_name": e.detail.value, })
    }
    if ("donation_code" == key) {
      this.setData({ "donation_code": e.detail.value, })
    }
    if ("donation_year" == key) {
      this.setData({ "donation_year": e.detail.value, })
    }
    if ("donation_account" == key) {
      this.setData({ "donation_account": e.detail.value, })
    }
    if ("comment" == key) {
      this.setData({ "comment": e.detail.value, })
    }
  },

  deductRatioPicker:function(e){//捐赠比例
    console.log('picker,携带值为', e.detail.value)
    var new_data = this.data.deductPick[e.detail.value]
    this.setData({
      deduction_ratio: new_data ? new_data.replace("%",""):""
    })
  },

  addItem: function() { //继续添加
    if (!this.data.showAddView) {//是否新增了view
      this.setData({
        showAddView: true
      })
      return
    }
    if (!this.data.donated_unit_code || this.data.donated_unit_code.length < 1) {
      this.showToast("请填写受赠单位纳税人识别号")
      return
    }
    if (!this.data.donated_unit_name || this.data.donated_unit_name.length < 1) {
      this.showToast("请填写受赠单位名称")
      return
    }
    if (!this.data.donation_code || this.data.donation_code.length < 1) {
      this.showToast("请填写捐赠凭证码")
      return
    }
    if (!this.data.donation_year || this.data.donation_year.length < 1) {
      this.showToast("请填写捐赠年度")
      return
    }
    if (!this.data.donation_account || this.data.donation_account.length < 1) {
      this.showToast("请填写扣除金额")
      return
    }
    if (!this.data.deduction_ratio || this.data.deduction_ratio.length < 1) {
      this.showToast("请选择扣除比例")
      return
    }
    this.goSubmit("1")
  },

  goSubmit: function(type) {//type=“1”,继续添加(当前页面),type=2保存,返回列表
    if (!this.data.donated_unit_code || this.data.donated_unit_code.length < 1) {
      this.showToast("请填写受赠单位纳税人识别号")
      return
    }
    if (!this.data.donated_unit_name || this.data.donated_unit_name.length < 1) {
      this.showToast("请填写受赠单位名称")
      return
    }
    if (!this.data.donation_code || this.data.donation_code.length < 1) {
      this.showToast("请填写捐赠凭证码")
      return
    }
    if (!this.data.donation_year || this.data.donation_year.length < 1) {
      this.showToast("请填写捐赠年度")
      return
    }
    if (!this.data.donation_account || this.data.donation_account.length < 1) {
      this.showToast("请填写扣除金额")
      return
    }
    if (!this.data.deduction_ratio || this.data.deduction_ratio.length < 1) {
      this.showToast("请选择扣除比例")
      return
    }
    var that = this
    this.Authorization = app.globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/donation-deduction",
      header: {
        'Authorization': this.Authorization
      },
      method: "POST",
      data: {
        "years": that.data.year,
        "settlement_record_id": that.data.settlement_record_id,
        "donated_unit_code": that.data.donated_unit_code,
        "donated_unit_name": that.data.donated_unit_name,
        "donation_code": that.data.donation_code,
        "donation_year": that.data.donation_year,
        "donation_account": parseFloat(that.data.donation_account),
        "deduction_ratio": parseFloat(that.data.deduction_ratio),
        "comment":that.data.comment
      },
      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() {

  }
})