// pages/ticketGet/ticketGet.js
const utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    invoiceType: ['增值税普通纸质发票', '增值税专用纸质发票'],
    invoiceTypeIndex: 0,
    invoiceStatus: '3',
    userInfo: '',
    company: '',
    invoiceCode: '',
    invoiceNumber: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUser()
  },

  //获取企业信息(当前登录用户的默认企业信息)
  getUser() {
    this.setData({
      userInfo: utils.getInfo(),
      company:utils.getCurrEntInfo()
    })
  },
  //空白发票作废
  invalidInvoice(type) {
    let params = {
      entTaxId: this.data.company.entTaxId,
      deviceType: this.data.company.defaultDeviceInfo.deviceType,
      taxDiscId: this.data.company.defaultDeviceInfo.taxDiscId,
      invoiceInvalidType: 2,
      invoiceCategory: this.data.invoiceStatus,
      invoiceCode: this.data.invoiceCode,
      invoiceNumber: this.data.invoiceNumber,
      invalidOper: this.data.userInfo.userName,
      mobile: this.data.userInfo.mobile,
      reqChannel: 5
    }
    utils.axios({
      method: 'post',
      url: '/sys/invoiceExt/invalid',
      data: params,
      sendBefore() {
        wx.showLoading({
          title: '加载中...'
        })
      },
      complete() {
        wx.hideLoading()
        wx.stopPullDownRefresh()
      },
      success: res => {
        if (res.code === 0) {
          utils.toast(res.data.msg)
        }
      }
    })
  },
  //取消
  toBack() {
    wx.navigateBack()
  },

  //发票类型
  setInvoiceType(e) {
    let value = Number(e.detail.value)
    let status = ''
    if (value === 0) {
      status = 3
    }
    if (value === 1) {
      status = 4
    }
    // if (value === 2) {
    //   status = 1
    // }
    // if (value === 3) {
    //   status = 2
    // }
    this.setData({
      invoiceTypeIndex: value,
      invoiceStatus: status
    })
  },
  // 获取发票代码
  setInvoiceCode(e) {
    this.setData({
      invoiceCode: e.detail.value
    })
  },
  // 获取发票号码
  setInvoiceNumber(e) {
    this.setData({
      invoiceNumber: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '诺信云',
      path: '/pages/index/index'
    }
  }
})