lookandupdate.js 10.2 KB
// pages/main/addtionalreduce/childreneducate/childreneducate.js
var app = getApp();
var baseUrl = app.globalData.baseUrl;

Page({

  /**
   * Page initial data
   */
  data: {
    cur_status: "",
    legal_entity_id: "",
    declareStatus: {
      "to_declare ": "待申报",
      "declaring": "申报中",
      "success": "审核成功",
      "failed": "审核失败"
    },
    additiontitle: {
      "children_education": "子女教育",
      "continuing_education": "继续教育",
      "support_duty": "赡养老人",
      "medical_fund": "大病医疗",
      "house_fund": "住房"
    },
    title: '',
    imgpath: '',
    new_data: null,
    modal_images: {
      "children_education": "/images/childedu_declare.png",
      "continuing_education": "/images/continueedu_declare.png",
      "support_duty": "/images/support_older_declare.png",
      "medical_fund": "/images/health_declare.png",
      "house_fund": "/images/house_declare.png"
    },
    showModal_img: false,
    showModal_reducetype: false,
    showModal_addtype: false,
    url_arr: {
      "children_education": "persontax/v1/children-educations/",
      "continuing_education": "persontax/v1/continuing-educations/",
      "support_duty": "support-duties/",
      "medical_fund": "persontax/v1/medical_founds/",
      "house_fund": "persontax/v1/house_founds/"
    },
    reducetype: {
      "month": "月度扣除",
      "year": "年度扣除"
    },
    additionInfo: [],
    reducetypeData: ["月度", "年度"],
    modalData: {},
    children_modalData: {
      title: "请选择子女进行申报",
      datas: [],
      canceltext: "添加新子女并申报",
      confirmtext: "确定为该子女申报",
    },
    support_older_modalData: {
      title: "请选择父母或祖父母进行申报",
      datas: [],
      canceltext: "添加被赡养人并申报",
      confirmtext: "确定为该被赡养人申报",
    },
    medical_modalData: {
      title: "请选择本人、配偶或子女进行大病支出申报",
      datas: [],
      canceltext: "添加家庭成员并申报",
      confirmtext: "确定为该选择的人申报",
    },
    selected_reduceindex: 0,
    selected_addindex: 0
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function(options) {
    var that = this
    console.log("options", options);
    this.setData({
      cur_status: options.status,
      legal_entity_id: options.legal_entity_id
    })
    wx.setNavigationBarTitle({
      "title": that.data.additiontitle[options.status],
    })
  },

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

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function() {
    var that = this
    this.getAdditionInfo()
    this.getTaxList()
  },

  getAdditionInfo() {
    var that = this;
    var Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + that.data.url_arr[that.data.cur_status] + that.data.legal_entity_id,
      header: {
        'content-type': 'application/json',
        "Authorization": Authorization
      },
      success: function(res) {
        if (res && res.data) {
          console.log("res", res)

          that.setData({
            additionInfo: res.data.items
          })
        }
      }
    })
  },

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

  // lookimg: function() { //查看材料

  //   if (this.data.imgpath && this.data.imgpath.length > 0) {
  //     wx.previewImage({
  //       urls: [this.data.imgpath],
  //     })
  //   } else {
  //     wx.showToast({
  //       title: '暂无可查看资料',
  //     })
  //   }

  // },

  showdetail: function(e) {
    console.log("showdetail", JSON.stringify(this.data.additionInfo[e.currentTarget.id]))
    if (this.data.additionInfo && this.data.additionInfo.length > 0) {
      wx.navigateTo({
        url: '../additiondetail/additiondetail?datas=' +
          JSON.stringify(this.data.additionInfo[e.currentTarget.id]) + "&status=" + this.data.cur_status,
      })
    }
  },

  godelete: function(e) { //删除
    var that = this;
    var Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + 'persontax/v1/op/delete',
      data: {
        item_type: that.data.cur_status,
        id: that.data.legal_entity_id
      },
      header: {
        'content-type': 'application/json',
        "Authorization": Authorization
      },
      success: function(res) {
        if (res && res.data) {
          console.log("res", res)

        }
      }
    })
  },

  goedit: function(e) { //编辑
    console.log("goedit", e)
    if (this.data.additionInfo && this.data.additionInfo.length > 0) {
      wx.navigateTo({
        url: '../additiondetail/additiondetail?datas=' + JSON.stringify(this.data.additionInfo[e.currentTarget.id]) + "&status=" + this.data.cur_status,
      })
    }
  },

  goadd: function(e) { //添加
    console.log("goadd", e)
    var that = this
    var modalinfo, senddata
    if (this.data.cur_status == 'continuing_education' || this.data.cur_status == 'house_fund') {
      wx.navigateTo({
        url: '../addextrainfo/addextrainfo?datas=' + '' + '&status=' + this.data.cur_status + '&reducetype=' + this.data.reducetypeData[this.data.selected_reduceindex],
      })
    } else {
      if (this.data.cur_status == 'children_education') { //modalData
        modalinfo = this.data.children_modalData
      } else if (this.data.cur_status == 'support_duty') {
        modalinfo = this.data.support_older_modalData
      } else if (this.data.cur_status == 'medical_fund') {
        modalinfo = this.data.medical_modalData
      }
      senddata = JSON.stringify(modalinfo.datas[e.currentTarget.id])
      console.log("modalinfo", modalinfo)
      if (modalinfo.datas.length < 2) {
        wx.navigateTo({
          url: '../addextrainfo/addextrainfo?status=' + this.data.cur_status + '&datas=' + senddata + '&reducetype=' + this.data.reducetypeData[this.data.selected_reduceindex],
        })
      } else {
        this.showAddtionmodal(modalinfo)
      }
    }
  },

  getTaxList: function() {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var Authorization = app.globalData.Authorization;
    console.log('Authorization', Authorization)
    if (!Authorization || Authorization.length < 10) {
      return
    }
    wx.request({
      url: baseUrl + 'persontax/v1/personal-taxes',
      method: "GET",
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": Authorization
      },
      data: {
        'all': true
      },
      success: function(res) {
        console.log('succ', res)
        if (res.statusCode < 300) {
          that.handleData(res.data);
        }
      },
      fail(res) {
        console.log(res.data)
      },
      complete() {
        wx.hideLoading()
        that.setData({
          load_finish: true
        })
      }
    })
  },

  handleData: function(data) {

    if (data.items && data.items.length > 0) {
      var childRelativelist = []
      var medicalRelativelist = []
      var olderRelativelist = []
      var childmodal = this.data.children_modalData
      var oldermodal = this.data.support_older_modalData
      var medicalmodal = this.data.medical_modalData
      for (var i = 0; i < data.items.length; i++) {
        if (data.items[i].family_ties == '子' || data.items[i].family_ties == '女') {
          childRelativelist.push(data.items[i])
        } else if (data.items[i].family_ties != '祖父母' && data.items[i].family_ties != '外祖父母') {
          medicalRelativelist.push(data.items[i])
        } else if (data.items[i].family_ties == '祖父母' || data.items[i].family_ties == '外祖父母') {
          olderRelativelist.push(data.items[i])
        }
      }
      childmodal.datas = childRelativelist
      oldermodal.datas = olderRelativelist
      medicalmodal.datas = medicalRelativelist
      this.setData({
        children_modalData: childmodal,
        support_older_modalData: oldermodal,
        medical_modalData: medicalmodal
      })
    }
  },

  showModalImg: function(e) {
    console.log("showModalImg", e)
    this.setData({
      showModal_img: true,
    })
  },

  closeModalImg: function(e) {
    console.log("closeModalImg", e)
    this.setData({
      showModal_img: false
    })
  },

  // 扣除类型
  showModalReducetype: function(e) {
    console.log("reducetype", e)
    this.setData({
      showModal_reducetype: true,
    })
  },

  showAddtionmodal: function(modalinfo) {
    this.setData({
      modalData: modalinfo,
      showModal_addtype: true,
    })
  },

  reduce_modalCancel: function() { //modal取消(扣除类型)
    this.setData({
      showModal_reducetype: false
    })
  },

  reduce_modalConfirm: function() { //modal确认(扣除类型)
    this.setData({
      showModal_reducetype: false
    })
  },

  modalCancel: function() { //modal取消(添加)
    this.setData({
      showModal_addtype: false
    })
  },

  modalConfirm: function(e) { //modal确认(添加)
    console.log("modalConfirm", e)
    this.setData({
      showModal_addtype: false
    })
    var senddata = JSON.stringify(this.data.modalData.datas[this.data.selected_addindex])
    console.log("senddata", senddata)
    wx.navigateTo({
      url: '../addextrainfo/addextrainfo?status=' + this.data.cur_status + '&datas=' + senddata  + '&reducetype=' + this.data.reducetypeData[this.data.selected_reduceindex],
    })
  
  },

  goselect: function(e) {
    console.log("goselect", e)
    if (this.data.showModal_reducetype) {
      this.setData({
        selected_reduceindex: e.currentTarget.id
      })
    }
    if (this.data.showModal_addtype) {
      this.setData({
        selected_addindex: e.currentTarget.id
      })
    }
  },

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

  }
})