首页新增跳转用电查询

This commit is contained in:
2024-05-07 08:45:49 +08:00
parent 63cb2f8250
commit 9fddb955ce
4 changed files with 51 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import { getInvoiceInfoDetail, downloadInvoice } from "../../service/invoice";
import { alertInfo } from "../../utils";
import request from '../../utils/request'
const { OK } = request;
// pages/invoiceInfo/index.js
@@ -40,8 +41,30 @@ Page({
console.log('res', res.tapIndex)
const { code, message, data } = await downloadInvoice(that.data.id, res.tapIndex);
if (code !== OK) {
alertInfo(message)
return;
}
const filePath = `${wx.env.USER_DATA_PATH}/发票/${that.data.id}.${res.tapIndex === 0 ? 'xml' : "pdf"}`;
FileSystemManager.writeFile({
filePath: filePath,
data: res.data,
encoding: 'base64', // 2. base64解密写入, 后台返回的byte[]数组是经过base64编码的其他方式写入文件打开格式不对
success: function(res) {
wx.openDocument({
filePath: filePath,
fileType: [res.tapIndex === 0 ? 'xml' : "pdf"], // 3. 这个必须写合法类型,不然下载不了
success: function (res) {
console.log('打开文档成功')
},
fail: function (e) {
console.log(e.errMsg);
}
})
},
fail: function (e) {
console.log(e.errMsg);
}
});
}
})
},