import { getInvoiceInfo, makeInvoice } from "../../service/invoice" import { alertInfo, alertSuccess, loadingFunc } from "../../utils/index"; import request from '../../utils/request' const { OK } = request // pages/invoicing/index.js Page({ /** * 页面的初始数据 */ data: { money: 0, tenement: "", tenementName: "", ids: [], count: 0, show: false, remark: "" }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const { money = 0, tenement, ids = '', count = 0, tenementName } = options; this.setData({ money, tenement, ids: ids.split(","), count, tenementName }) this.getDetail(); }, async getDetail() { const { code, message, data } = await getInvoiceInfo() if (code !== OK) { alertInfo(message) return; } if (!data?.tenement?.id || !data?.name) { const user = wx.getStorageSync('user') if (user.isAdmin) { wx.showModal({ title: '提示', content: '当前公司没有开票信息,请先前往开票信息页面编辑开票信息', confirmText: '前往编辑', cancelText: '取消', complete: (res) => { if (res.cancel) { wx.navigateBack() } if (res.confirm) { wx.redirectTo({ url: '/pages/invoiceList/index?tab=2', }) } } }) return } else { wx.showModal({ title: '提示', content: '当前公司没有开票信息,请联系管理员编辑完开票信息之后再开票', showCancel: false, confirmText: '返回', complete: (res) => { if (res.cancel) { wx.navigateBack() } if (res.confirm) { wx.navigateBack() } } }) return } } this.setData({ detail: {...data, }, remark: data.remark }) }, changeRemark(e) { this.setData({ remark: e.detail }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, async onSubmit() { loadingFunc(async() => { const {ids = [], remark } = this.data; const tenement = wx.getStorageSync('tenement') const { code, message, data } = await makeInvoice({ ids, tenement: tenement.id, remark }) if (code !== OK) { alertInfo(message) return; } alertSuccess("操作成功") setTimeout(() => { wx.redirectTo({ url: '/pages/invoiceList/index?tab=1', }) }, 500) }) }, changeShow() { this.setData({ show: true }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })