invoiceCode.js 3.92 KB
// tabWorkOrder/pages/invoiceCode/invoiceCode.js
import commonApi from '~/api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isloading: false,
    codeInfo: {},
    isShadeShow: false,
    shadeObj: {
      type: 'success',
      title: '申请成功',
      tipTxt: '已经开票成功,无法申请重开,有问题建议线下联系总部'
    },
    editFormData: [{
      label: '销售方名称',
      name: 'enterpriseName'
    }, {
      label: '开票金额',
      name: 'invoiceAmount',
      prefix: '¥'
    }, {
      label: '票通订单号',
      name: 'tradeNo'
    }, {
      label: '生成时间',
      name: 'tradeTime'
    }, {
      label: '二维码有效期',
      name: 'expireTime'
    }]
  },
  handleConfirm() {
    let { codeInfo, isloading } = this.data
    if (isloading) {
      return true
    }
    const params = {
      orderCode: codeInfo.bizOrderCode
    }
    wx.$util.showLoading()
    this.setData({
      isloading: true
    })
    commonApi.getOrderCode(params).then(res => {
      console.log(res, 'res---')
      let { invoiceInfo, invoiceIssueQrcode } = res.data
      if (invoiceInfo) {
        // 开票成功、开票失败
        wx.$router.redirectTo("tabWorkOrder.invoiceResult", {
          obj: {
            // code - 0000:成功;其他:失败
            code: invoiceInfo.code,
            bizOrderCode: invoiceIssueQrcode.bizOrderCode,
            invoiceAmount: invoiceIssueQrcode.invoiceAmount,
            createdDate: invoiceIssueQrcode.createdDate,
            imgUrl: invoiceInfo.imgUrl,
            msg: invoiceInfo.msg
          }
        })
      }
    }).finally(() => {
      wx.$util.hideLoading()
      this.setData({
        isloading: false
      })
    })
  },
  handleCancelInvoice() {
    let { codeInfo, isloading } = this.data
    console.log(codeInfo, '---')
    if (isloading) {
      return true
    }
    const params = {
      qrcodeNo: codeInfo.qrcodeNo
    }
    this.setData({
      isloading: true
    })
    commonApi.cancelInvoiceQrcode(params).then(res => {
      console.log(res, 'res---')
      let { code, data } = res
      if(code == 0) {
        this.setData({
          isShadeShow: true,
          'shadeObj.type': data.code == 0 ? 'success' : 'error',
          'shadeObj.title': data.code == 0 ? '申请成功' : '申请失败',
          'shadeObj.tipTxt': data.code == 0 ? '原开票二维码已经作废,请选择发票类型重新开票' : data.message,
        })
        }
    }).finally(() => {
      this.setData({
        isloading: false
      })
    })
  },
  handleShadeConfirm() {
    let { shadeObj } = this.data
    this.setData({
      isShadeShow: false
    })
    shadeObj.type == 'success' ? this.handleNewInvoce() : this.handleConfirm()
  },
  handleNewInvoce() {
    let { codeInfo } = this.data
    codeInfo.orderCode = codeInfo?.bizOrderCode || ''
    getApp().globalData.selectInvoiceObj = { isOpen: true, codeInfo: JSON.parse(JSON.stringify(codeInfo)) };
    wx.$router.back()
  },
  handleBack() {
    let { isloading } = this.data
    if (isloading) {
      return true
    }
    getApp().globalData.selectInvoiceObj = { isOpen: false };
    wx.$router.back()
  },
  onRoute(res) {
    console.log(res)
    this.setData({
      codeInfo: JSON.parse(JSON.stringify(res.obj))
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})