healthInsurDetail.js 5.9 KB
// pages/main/finalpay/otherDeductDetail/healthInsurDetail.js
var app = getApp();
var baseUrl = app.globalData.baseUrl;
var format = require('../../../../utils/util.js');
const regex = /^[0-9a-zA-Z]{1,}$/
Page({

  /**
   * Page initial data
   */
  data: {
    settlement_record_id:"",
    year: "2019",
    showAddView: false,
    infoList: [{}],
    total_account:0,
    effect_date:"",

    "tax_code": "",
    "date_policy": "", //保单生效日期,
    "year_premium": "", //年度保费
    "month_premium": "", //月度保费 
    "year_deduction": "", //本年扣除金额
  },

  /**
   * 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/commercial-insurance-tax",
      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: that.handleData(result.data.items) ,
            "tax_code": "",
            "date_policy": "",
            "year_premium": "",
            "month_premium": "",
            "year_deduction": "",
          })
        }
      },
    })
  },

  handleData: function (items){
    for (var i = 0; i < items.length; i++) {
      if (items[i].date_policy && items[i].date_policy>1000){
        items[i].date_policy = format.formatTime_date(items[i].date_policy)
      }else{
        items[i].date_policy = ""
      }
    }
    return items
  },

  /**
   * 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 ("tax_code" == key) {
      this.setData({
        "tax_code": e.detail.value,
      })
    }
    if ("year_premium" == key) {
      this.setData({
        "year_premium": e.detail.value,
      })
    }
    if ("month_premium" == key) {
      this.setData({
        "month_premium": e.detail.value,
      })
    }
    if ("year_deduction" == key) {
      this.setData({
        "year_deduction": e.detail.value,
      })
    }
  },

  datePolicyPicker: function(e) {
    var datelong = Date.parse(new Date(e.detail.value)) / 1000
    console.log("日期", e.detail.value, datelong)
    this.setData({
      effect_date: e.detail.value,
      date_policy: datelong
    })
  },

  addItem: function() { //继续添加
    if (!this.data.showAddView) {//是否新增了view
      this.setData({
        showAddView: true
      })
      return
    }
    if (!this.data.tax_code || this.data.tax_code.length < 1) {
      this.showToast("请填写税优识别码")
      return
    }
    if (!regex.test(this.data.tax_code)) {
      this.showToast("税优识别码格式有误")
      return
    }
    if (!this.data.date_policy || this.data.date_policy.length < 1000) {
      this.showToast("请选择保单生效日期")
      return
    }
    if (!this.data.year_deduction || this.data.year_deduction.length < 1) {
      this.showToast("请填写本年扣除金额")
      return
    }
    this.goSubmit("1")
  },

  goSubmit: function (type) {//type=“1”,继续添加(当前页面),type=2保存,返回列表
    if (!this.data.tax_code || this.data.tax_code.length < 1) {
      this.showToast("请填写税优识别码")
      return
    }
    if (!regex.test(this.data.tax_code)) {
      this.showToast("税优识别码格式有误")
      return
    }
    if (!this.data.date_policy || this.data.date_policy.length < 1000) {
      this.showToast("请选择保单生效日期")
      return
    }
    if (!this.data.year_deduction || this.data.year_deduction.length < 1) {
      this.showToast("请填写本年扣除金额")
      return
    }
    var that = this
    this.Authorization = app.globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/commercial-insurance-tax",
      header: {
        'Authorization': this.Authorization
      },
      method: "POST",
      data: {
        "years": that.data.year,
        "settlement_record_id": that.data.settlement_record_id,
        "tax_code": that.data.tax_code,
        "date_policy": that.data.date_policy , //保单生效日期,
        "year_premium": parseFloat(that.data.year_premium)  ,//年度保费,
        "month_premium": parseFloat(that.data.month_premium), //月度保费 
        "year_deduction": parseFloat(that.data.year_deduction), //本年扣除金额
      },
      success: function (result) {
        console.log("infoList", result)
        if (result.statusCode == 200) {
          if (type == '1') {
            that.getInfoList()
            that.setData({
              showAddView: true
            })
          } else {
            wx.navigateBack({
              delta: 2
            })
          }
        }
      },
    })
  },

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

  }
})