// pages/invoice/preview/preview.js const app = getApp(); const api = app.api; import WxValidate from '../../../utils/WxValidate' Page({ /** * 页面的初始数据 */ data: { invoiceId:16, invoiceOrderId:20, invoiceInfo:null, isShowInvoiceDetail:false, isShowInvoiceSure:false, isSubmit:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ invoiceId:options.invoiceId, invoiceOrderId:options.invoiceOrderId }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getData() }, showInvoiceDetail(){ this.setData({ isShowInvoiceDetail:true }) }, hideInvoiceDetail(){ this.setData({ isShowInvoiceDetail:false }) }, hideInvoiceSure(){ this.setData({ isShowInvoiceSure:false }) }, sureInvoice(){ /*'EuqOzIPHw16p-4A4x2rFf-t0khWIiv_rP_lAi-Zjvrk',*/ wx.requestSubscribeMessage({ tmplIds: [ 'MiZ76kP6vQ7akw04b1bWOrZMrXqMw8hrdCEHZNHPK-A', 'TL7rAlbCWIWtr7A0lW-v5qR2MDH4UQk0YkkxOZuq-Bc', 'bXJEBQtWtoF3VhSg4t-JtU2kdECo9uSFEllHDUDoKak' ], success: (res)=> { this.setData({ isShowInvoiceSure:true }) } }) }, /** * get data * **/ getData(){ const {invoiceId,invoiceOrderId}=this.data; app.post(api.queryOrderInvoiceInfo,{ id:invoiceId, invoiceOrderId }).then(res=>{ this.setData({ invoiceInfo:res.data }) }) }, /** * 提交发票 * **/ saveData(){ const {invoiceOrderId,isSubmit}=this.data; if(isSubmit){ return } this.setData({ isSubmit:true }) app.post(api.updateInvoiceOrder,{ invoiceOrderId:invoiceOrderId, orderStatus:2, // 2已提交 3已支付 }).then(res=>{ console.log(res); this.setData({ isSubmit:false, }); wx.reLaunch({ url:"/pages/invoice/myInvoice/myInvoice" }) }).catch(()=>{ this.setData({ isSubmit:false }) }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, viewInvoice: function(){ app.base64src(this.data.invoiceInfo.invoiceFileBase64, res => { console.log(res) // 返回图片地址,直接赋值到image标签即可 wx.previewImage({ current: res, urls: [res] }) }); } })