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


  data: {
    declare_status: "",//申报状态"0" //待申报  "1" //申报成功
    refund_status: "",//退税状态
    pay_status: "",//补税状态
    declaring_unit_status: "4",//1:本单位申报,2:本单位其他申报,3:其他单位申报,4:待确认申报
    payinfo:{},
    unitInfo: [],
    showUnit:false,
    declaring_unit_id:"",
    showModal_selfDeclare:false,
    declare_status_arr:["待申报","申报成功"],
    refund_status_arr: ["待退税", "退税中", "退税成功", "退税失败","放弃退税"],
    pay_status_arr: ["无需补税", "待补税","补税成功"],
  },


  onLoad: function(options) {
    this.getPayInfo();
  },


  onReady: function() {

  },


  onShow: function() {

  },

  yearPick: function() {

  },

  getPayInfo:function(){
    var that = this
    this.Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/declare-detail",
      header: {
        'Authorization': this.Authorization
      },
      data: { 'years': '2019' },
      success: function (result) {
        console.log("payinfo",result)
        if (result.statusCode==200) {
          that.setData({
            payinfo: result.data
          })
        }
      },
    })
  },

  getUnitInfo:function(){//获取申报单位
    var that = this
    this.Authorization = getApp().globalData.Authorization;
    that.setData({
      showUnit: true
    })
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/declare-unit",
      header: {
        'Authorization': this.Authorization
      },
      data: { },
      success: function (result) {
        console.log("unitInfo", result.data)
        if (result.statusCode == 200) {
          that.setData({
            unitInfo: result.data.items
          })
        }
      },
      complete:function(e){
        that.setData({
          showUnit:true
        })
      }
    })
  },

  updateDeclareState: function (id) {//是否在本单位申报
    var that = this
    this.Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/record",
      header: {
        'Authorization': this.Authorization
      },
      data: { 'declaring_unit_id': id },
      success: function (result) {
        console.log("declareinfo", result)
        if (result.statusCode == 200) {
          that.setData({
            
          })
        }
      },
    })
  },

  // 是否放弃退税,(是:"5",否:"")
  forgiveRefund: function () {
    var that = this
    this.Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/record",
      header: {
        'Authorization': this.Authorization
      },
      data: { 'refund_status': '' },
      success: function (result) {
        console.log("refund", result)
        if (result.statusCode == 200) {
          that.setData({

          })
        }
      },
    })
  },

  // 确认提交申请退税
  forgiveRefund: function () {
    var that = this
    this.Authorization = getApp().globalData.Authorization;
    wx.request({
      url: baseUrl + "payroll/v1/settlement-tax/record",
      header: {
        'Authorization': this.Authorization
      },
      data: {
        "name": "xxxx",  //姓名,
        "bank": "xxxx",  //开户行,
        "bank_card_no": "xxxx",  //银行卡号,
        "bank_province": "xxxx",  //银行省份,
      },
      success: function (result) {
        console.log("refund", result)
        if (result.statusCode == 200) {
          that.setData({

          })
        }
      },
    })
  },


  // 跳转到H5页面测试
  skipH5_01: function() {
    wx.navigateTo({
      url: '../../common/webview?type=1',
    })
  },

  skipH5_02: function() {
    wx.navigateTo({
      url: '../../common/webview?type=2',
    })
  },

  finalpay_detail: function() {
    wx.navigateTo({
      url: 'incomeDetail/incomeDetail',
    })
  },

  declareHere: function() {
    this.getUnitInfo()
  },

  declareNotHere: function() {
    var that = this
    wx.showModal({
      title: '',
      content: '确认不在本单位进行汇算清缴申报吗?',
      confirmColor: '#357aeb',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          that.updateDeclareState("")
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  unitPick:function(e){//选择申报单位
    console.log("unitPick",e)
    this.setData({
      declaring_unit_id: e.currentTarget.id,
      showUnit: false
    })
    this.updateDeclareState(e.currentTarget.id)
  },

  selfdeclare_close(){//关闭自行申报弹窗
    this.setData({
      showModal_selfDeclare: false
    })
  },

  declareBySelf:function(){//查看自行申报方式
    this.setData({
      showModal_selfDeclare: true
    })
  },

  godeclareHistory:function(){
    wx.redirectTo({
      url: '../advancepayment/adPayHome',
    })
  },

  noOtherUnitInfo:function(){//没有其他单位个税申报

  },

  otherUnitInfo: function () {//有其他单位个税申报
    wx.navigateTo({
      url: 'addUnitInfo/addUnitInfo',
    })
  },

  onHide: function() {

  },


  onUnload: function() {

  },


  onPullDownRefresh: function() {

  },


  onReachBottom: function() {

  },


  onShareAppMessage: function() {

  }
})