// pages/invoice/contract/contract.js const app = getApp(); const api = app.api; Page({ /** * 页面的初始数据 */ data: { invoiceId:"", invoiceOrderId:"", upFileInfo:null, formData:{ contractFileId:"", id:"", }, isSubmit:false, isShowFileChoose:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.invoiceOrderId){ this.setData({ invoiceId:options.invoiceId||'', invoiceOrderId:options.invoiceOrderId||'' },()=>{ this.getData(); }) } wx.hideShareMenu(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /**已提交获取数据**/ getData(){ const invoiceInfo=wx.getStorageSync('invoiceInfo'); if(invoiceInfo){ this.setData({ upFileInfo:invoiceInfo.contractFileInfo, formData:{ contractFileId:invoiceInfo.contractId, id:invoiceInfo.invoiceOrderId, } },()=>{ wx.removeStorageSync('invoiceInfo') }); } /*const {invoiceId,invoiceOrderId}=this.data; app.post(api.queryOrderInvoiceInfo,{ id:invoiceId, invoiceOrderId }).then(res=>{ const {data}=res; this.setData({ upFileInfo:data.contractFileInfo, formData:{ contractFileId:data.contractId, id:invoiceOrderId, } }) })*/ }, saveData(){ const{formData,invoiceId,isSubmit}=this.data; if(isSubmit){ return } if(!formData.contractFileId){ wx.showToast({ title: '请上传合同文件', icon: 'none', duration: 2000 }) return } this.setData({ isSubmit:true }); app.post(api.uploadArtistUserInvoice,formData).then(res=>{ console.log(res); const {invoiceOrderId}=res.data //记录id 回退记录 this.setData({ 'formData.id':invoiceOrderId, }) wx.navigateTo({ url:`/pages/invoice/editInvoice/editInvoice?id=${res.data.invoiceOrderId}&invoiceId=${invoiceId}` }) this.setData({ isSubmit:false, }); }).catch(()=>{ this.setData({ isSubmit:false }) }) }, chooseFileMsg(){ app.uploadFileMsg({ extension:['pdf'] }).then(res=>{ this.upFileFormatter(res) }).catch(error=>{ console.log(error) }); }, chooseFile(){ app.uploadFile({ extension:['pdf'] }).then(res=>{ this.upFileFormatter(res); }).catch(error=>{ console.log(error) }); }, upFileFormatter(res){ const data=JSON.parse(res.data); this.setData({ upFileInfo:data, isShowFileChoose:false, 'formData.contractFileId':data.id }) }, removeFile(){ this.setData({ upFileInfo:null, 'formData.contractFileId':'' }) }, /**预览pdf文件**/ prevFile() { const {upFileInfo}=this.data; if(upFileInfo.contentType.indexOf('image')!=-1){ app.previewImg([upFileInfo.url]); }else{ app.openDocument(upFileInfo.url) } }, /** 显示文件上传方式 **/ showFileChoose(){ this.setData({ isShowFileChoose:true }) }, /** 隐藏文件上传方式 **/ hideFileChoose(){ this.setData({ isShowFileChoose:false }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })