2026-07-27 11:26:39 +08:00

83 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import dayjs from 'dayjs';
import { getHisInvoice } from '@/utils/api';
import { loading as showLoading, hideLoading, toast, confirm } from '@/utils/widget';
function previewWithBase64(data, url) {
const fs = my.getFileSystemManager();
const time = dayjs().format('YYYY-MM-DD HH-mm-ss');
const filePath = `${my.env.USER_DATA_PATH}/${time}.pdf`;
fs.writeFile({
filePath,
data,
encoding: 'base64',
success(res) {
console.log(JSON.stringify(res))
//第二步预览PDF文件
my.openDocument({
filePath,
fileType: 'pdf',
success(res) {
console.log('open document success')
},
fail(err) {
if (url) {
previewWithUrl(url)
} else {
toast(`预览发票失败:${err.errMsg || ''}`)
}
console.log('openDocument fail:' + JSON.stringify(err))
},
})
},
fail(err) {
if (url) {
previewWithUrl(url)
} else {
toast(`预览发票失败:${err.errMsg || ''}`)
}
},
});
}
function previewWithUrl(url) {
uni.setClipboardData({
data: url,
success: () => {
confirm('已复制发票地址,请在浏览器中打开', { showCancel: false, confirmText: '知道了' })
}
})
}
export function viewShippingInfo(id) {
uni.navigateTo({
url: `/pages/consult/drug-purchase-list/shipping-info?id=${id}`
})
}
export async function viewInvoice(patientId, orderNo) {
showLoading()
const res = await getHisInvoice({
patientId,
orderNo
});
if (res && res.success) {
const url = typeof res.data === 'string' ? res.data : ''
if (url) {
previewWithUrl(url)
}
// const pdfbase64 = res.data && res.data.dzfp && res.data.dzfp[0] && res.data.dzfp[0].pdfbase64;
// if (pdfbase64) {
// previewWithBase64(pdfbase64, url)
// } else if (url) {
// previewWithUrl(url)
// }
else {
confirm('发票正在开具中,请稍后再试!', { showCancel: false, confirmText: '知道了' })
}
} else {
confirm('发票正在开具中,请稍后再试!', { showCancel: false, confirmText: '知道了' })
}
hideLoading()
}