Jelajahi Sumber

feat: 发票下载支持 PDF/OFD/XML 三种格式下拉选择

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 2 hari lalu
induk
melakukan
e09e39913d
1 mengubah file dengan 20 tambahan dan 9 penghapusan
  1. 20 9
      admin-web/src/views/admin/invoice/index.vue

+ 20 - 9
admin-web/src/views/admin/invoice/index.vue

@@ -189,7 +189,16 @@
               <el-button v-if="row.status===0" v-auth="'invoice.modify'" size="small" plain type="warning" @click="handleInvice(row)">开票</el-button>
               <el-button v-if="row.status===0||row.status===3" v-auth="'invoice.modify'" size="small" plain type="danger" @click="handleCancelInvoice(row)">取消开票</el-button>
               <el-button v-if="row.status===0||row.status===3" v-auth="'invoice.modify'" size="small" plain type="primary" @click="handleConfirmManual(row)">已手动开票</el-button>
-              <el-button v-if="row.status===1" v-auth="'invoice.modify'" size="small" plain type="success" @click="previewInvoice(row)">下载</el-button>
+              <el-dropdown v-if="row.status===1" v-auth="'invoice.modify'" size="small" @command="(format: string) => downloadInvoice(row, format)">
+                <el-button size="small" plain type="success">下载</el-button>
+                <template #dropdown>
+                  <el-dropdown-menu>
+                    <el-dropdown-item command="invoiceUrl">PDF</el-dropdown-item>
+                    <el-dropdown-item command="ofdUrl">OFD</el-dropdown-item>
+                    <el-dropdown-item command="xmlUrl">XML</el-dropdown-item>
+                  </el-dropdown-menu>
+                </template>
+              </el-dropdown>
               <el-button   size="small" plain type="success" @click="handleInfo(row)">详情</el-button>
             </template>
             <template v-else>
@@ -366,20 +375,22 @@ const handleInfo = (row:any) => {
 }
 
 
-const previewInvoice =   (row: any) => {
+const downloadInvoice = (row: any, format: string) => {
   $get(`/finance/downloadInvoice/${row.id}`).then((res: any) => {
-    console.log(res)
-    let {downloadUrl} = res;
-    if (downloadUrl) {
-      window.open(downloadUrl, "_blank")
-
-      // doPriview(downloadUrl)
-
+    let url = res.data?.[format] || res[format];
+    if (url) {
+      window.open(url, "_blank");
+    } else {
+      Msg.error("下载地址不存在");
     }
   }).catch(e => {
     console.error(e)
   })
 }
+
+const previewInvoice = (row: any) => {
+  downloadInvoice(row, 'invoiceUrl');
+}
 /*
 const doPriview=async  (url:string) =>{
   const canvas = pdfViewer.value;