|
@@ -135,6 +135,7 @@
|
|
|
<el-table-column label="操作" width="150" align="center" fixed="right">
|
|
<el-table-column label="操作" width="150" align="center" fixed="right">
|
|
|
<template #default="{ row }">
|
|
<template #default="{ row }">
|
|
|
<el-button type="primary" link @click="handlePreviewInvoice(row)" v-if="row.invoiceAnnex">预览</el-button>
|
|
<el-button type="primary" link @click="handlePreviewInvoice(row)" v-if="row.invoiceAnnex">预览</el-button>
|
|
|
|
|
+ <el-button type="primary" link @click="handleDownloadInvoice(row)" v-if="row.invoiceAnnex">下载</el-button>
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
</el-table>
|
|
</el-table>
|
|
@@ -229,6 +230,42 @@ const handlePreviewInvoice = (row: any) => {
|
|
|
window.open(row.invoiceAnnex, '_blank');
|
|
window.open(row.invoiceAnnex, '_blank');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// 下载发票附件
|
|
|
|
|
+const handleDownloadInvoice = async (row: any) => {
|
|
|
|
|
+ if (!row.invoiceAnnex) {
|
|
|
|
|
+ ElMessage.warning('发票附件不存在');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const url = row.invoiceAnnex;
|
|
|
|
|
+ const fileName = url.split('/').pop() || '发票附件';
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 使用 fetch 获取文件内容
|
|
|
|
|
+ const response = await fetch(url);
|
|
|
|
|
+ if (!response.ok) {
|
|
|
|
|
+ throw new Error('下载失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ const blob = await response.blob();
|
|
|
|
|
+ const blobUrl = window.URL.createObjectURL(blob);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建下载链接
|
|
|
|
|
+ const link = document.createElement('a');
|
|
|
|
|
+ link.href = blobUrl;
|
|
|
|
|
+ link.download = decodeURIComponent(fileName);
|
|
|
|
|
+ document.body.appendChild(link);
|
|
|
|
|
+ link.click();
|
|
|
|
|
+ document.body.removeChild(link);
|
|
|
|
|
+
|
|
|
|
|
+ // 释放 blob URL
|
|
|
|
|
+ window.URL.revokeObjectURL(blobUrl);
|
|
|
|
|
+ ElMessage.success('下载成功');
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('下载失败:', error);
|
|
|
|
|
+ // 降级方案:直接打开链接让用户手动保存
|
|
|
|
|
+ window.open(url, '_blank');
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const handleBack = () => {
|
|
const handleBack = () => {
|
|
|
router.back();
|
|
router.back();
|
|
|
};
|
|
};
|