endowmentInsurDetail.js 7.8 KB
// pages/main/finalpay/otherDeductDetail/endowmentInsurDetail.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",
    infoList: [{}],
    total_account:0,
    showAddView: false,
    option_start_date: "",
    option_end_date: "",

    "tax_extension_account": "",
    "option_start_time": "", //申报扣除月份起,
    "option_end_time": "", //申报扣除月份止,
    "tax_check_code": "",
    "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/tax-extension",
      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),

            option_start_date: "",
            option_end_date: "",
            "tax_extension_account": "",
            "option_start_time": "", //申报扣除月份起,
            "option_end_time": "", //申报扣除月份止,
            "tax_check_code": "",
            "year_premium": "", //年度保费,
            "month_premium": "", //月度保费 
            "year_deduction": "", //本年扣除金额
          })
        }
      },
    })
  },

  handleData: function(items) { //解析列表数据时间戳
    for (var i = 0; i < items.length; i++) {
      if (items[i].option_start_time && items[i].option_start_time > 1000) {
        items[i].option_start_time = format.formatTime_date(items[i].option_start_time)
      } else {
        items[i].option_start_time = ""
      }
      if (items[i].option_end_time && items[i].option_end_time > 1000) {
        items[i].option_end_time = format.formatTime_date(items[i].option_end_time)
      } else {
        items[i].option_end_time = ""
      }
    }
    return items
  },

  bindDatePicker: function(e) { //时间选择
    var datelong = Date.parse(new Date(e.detail.value)) / 1000
    console.log("picker", e)
    if ("option_start_time" == e.currentTarget.id) {
      this.setData({
        option_start_date: e.detail.value,
        option_start_time: datelong
      })
    } else if ("option_end_time" == e.currentTarget.id) {
      this.setData({
        option_end_date: e.detail.value,
        option_end_time: datelong
      })
    }

  },

  getInputInfo: function(e) { //
    console.log("输入框", e.currentTarget.id, e.detail.value)
    var key = e.currentTarget.id + ""
    if ("tax_extension_account" == key) {
      this.setData({
        "tax_extension_account": e.detail.value,
      })
    }
    if ("tax_check_code" == key) {
      this.setData({
        "tax_check_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,
      })
    }
  },

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

  },

  addItem: function() { //继续添加
    if (!this.data.showAddView) { //是否新增了view
      this.setData({
        showAddView: true
      })
      return
    }
    if (!this.data.tax_extension_account || this.data.tax_extension_account.length < 1) {
      this.showToast("请填写税延养老账号编号")
      return
    }
    if (!regex.test(this.data.tax_extension_account)) {
      this.showToast("税延养老账户编号格式有误")
      return
    }
    if (!this.data.option_start_time || this.data.option_start_time.length < 1000 || !this.data.option_end_time || this.data.option_end_time.length < 1000) {
      this.showToast("请选择申报扣除起止月")
      return
    }
    if (!this.data.tax_check_code || this.data.tax_check_code.length < 1) {
      this.showToast("请填写报税校验码")
      return
    }
    if (!regex.test(this.data.tax_check_code)) {
      this.showToast("报税校验码格式有误")
      return
    }
    if (!this.data.year_deduction || this.data.year_deduction.length < 1) {
      this.showToast("请填写本年扣除金额")
      return
    }
    this.goSubmit("1")
  },

  goSubmit: function(type) {
    if (!this.data.tax_extension_account || this.data.tax_extension_account.length < 1) {
      this.showToast("请填写税延养老账户编号")
      return
    }
    if (!regex.test(this.data.tax_extension_account)) {
      this.showToast("税延养老账号编号格式有误")
      return
    }
    if (!this.data.option_start_time || this.data.option_start_time.length < 1000 || !this.data.option_end_time || this.data.option_end_time.length < 1000) {
      this.showToast("请选择申报扣除起止月")
      return
    }
    if (!this.data.tax_check_code || this.data.tax_check_code.length < 1) {
      this.showToast("请填写报税校验码")
      return
    }
    if (!regex.test(this.data.tax_check_code)) {
      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/tax-extension",
      header: {
        'Authorization': this.Authorization
      },
      method: "POST",
      data: {
        "years": that.data.year,
        "settlement_record_id": that.data.settlement_record_id,
        "tax_extension_account": that.data.tax_extension_account,
        "option_start_time": that.data.option_start_time, //申报扣除月份起,
        "option_end_time": that.data.option_end_time, //申报扣除月份止,
        "tax_check_code": that.data.tax_check_code,
        "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() {

  }
})