83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
|
|
|
|||
|
|
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()
|
|||
|
|
}
|