Ver código fonte

销售发票附件下载

hurx 9 horas atrás
pai
commit
b7abfc11fc
1 arquivos alterados com 37 adições e 0 exclusões
  1. 37 0
      src/views/reconciliation/invoiceManage/detail.vue

+ 37 - 0
src/views/reconciliation/invoiceManage/detail.vue

@@ -135,6 +135,7 @@
             <el-table-column label="操作" width="150" align="center" fixed="right">
               <template #default="{ row }">
                 <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>
             </el-table-column>
           </el-table>
@@ -229,6 +230,42 @@ const handlePreviewInvoice = (row: any) => {
   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 = () => {
   router.back();
 };