From 6eeb82e56306d645a290a0f5ba202efe3ef2385d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 27 十月 2026 17:49:09 +0800
Subject: [PATCH] feat(report): 新增PDF报告预览功能并重构报告下载流程

---
 src/views/business/materialOrderComponents/materialOrder/downFileDialog.vue |   99 ++++++++++++++++++-------------------------------
 1 files changed, 36 insertions(+), 63 deletions(-)

diff --git a/src/views/business/materialOrderComponents/materialOrder/downFileDialog.vue b/src/views/business/materialOrderComponents/materialOrder/downFileDialog.vue
index 37bc1d8..76f465c 100644
--- a/src/views/business/materialOrderComponents/materialOrder/downFileDialog.vue
+++ b/src/views/business/materialOrderComponents/materialOrder/downFileDialog.vue
@@ -1,85 +1,58 @@
 <template>
   <div>
-    <el-dialog title="鎶ュ憡鏌ョ湅涓嬭浇" v-model="isShow" width="500px" @closed="$emit('closeDownFileDialog')">
-      <div style="margin-bottom: 18px">
-        <span style="font-size: 16px;">杩涘巶妫�楠屾姤鍛婁笅杞�</span>
-        <lims-icon name="el-icon-paperclip" style="color:var(--el-color-primary);margin-left: 6px"></lims-icon>
-        <el-link :underline="false" style="vertical-align: bottom;font-size: 16px;"
-                 :disabled="!downLoadInfo.enterUrlS && !downLoadInfo.enterUrl"
-                 type="primary" @click="downLoad0">鏌ョ湅</el-link>
-      </div>
-      <div>
-        <span  style="font-size: 16px;">瀛e害妫�楠屾姤鍛婁笅杞�</span>
-        <lims-icon name="el-icon-paperclip" style="color:var(--el-color-primary);margin-left: 6px"></lims-icon>
-        <el-link :underline="false" style="vertical-align: bottom;font-size: 16px;"
-                 :disabled="!downLoadInfo.quarterUrlS && !downLoadInfo.quarterUrl"
-                 type="primary" @click="downLoad1">鏌ョ湅</el-link>
+    <el-dialog title="鎶ュ憡棰勮/涓嬭浇" v-model="isShow" width="520px" @closed="$emit('closeDownFileDialog')">
+      <div v-for="item in reports" :key="item.key" class="report-choice">
+        <span>{{ item.label }}</span>
+        <el-button link type="primary" :disabled="!canView(item)" @click="preview(item)">棰勮</el-button>
+        <el-button link type="primary" :disabled="!canView(item)" @click="download(item)">涓嬭浇</el-button>
+        <span v-if="!canView(item)" class="report-unavailable">鏈敓鎴愭垨灏氭湭鎵瑰噯</span>
       </div>
     </el-dialog>
+    <report-preview ref="reportPreview" />
   </div>
 </template>
 
 <script>
+import ReportPreview from '@/components/ReportPreview/index.vue'
+import { loadReportFile, reportFilename, reportPdfPath } from '@/utils/reportPreview'
+
 export default {
-  name: "downFileDialog",
-  // import 寮曞叆鐨勭粍浠堕渶瑕佹敞鍏ュ埌瀵硅薄涓墠鑳戒娇鐢�
-  components: {},
+  name: 'downFileDialog',
+  components: { ReportPreview },
   props: {
-    downFileDialogVisible: {
-      type: Boolean,
-      default: () => false
-    },
-    downLoadInfo: {
-      type: Object,
-      default: () => {}
-    },
+    downFileDialogVisible: { type: Boolean, default: false },
+    downLoadInfo: { type: Object, default: () => ({}) }
   },
   data() {
-    // 杩欓噷瀛樻斁鏁版嵁
-    return {
-      isShow: this.downFileDialogVisible,
+    return { isShow: this.downFileDialogVisible }
+  },
+  computed: {
+    reports() {
+      const info = this.downLoadInfo
+      return [
+        { key: 'enter', label: '杩涘巶妫�楠屾姤鍛�', url: info.enterUrlS || info.enterUrl, status: info.enterRatifyStatus },
+        { key: 'quarter', label: '瀛e害妫�楠屾姤鍛�', url: info.quarterUrlS || info.quarterUrl, status: info.quarterRatifyStatus }
+      ]
     }
   },
-  // 鏂规硶闆嗗悎
   methods: {
-    // 杩涘巶妫�楠屾姤鍛婁笅杞�
-    downLoad0 () {
-      if(this.downLoadInfo.enterRatifyStatus !== 1){
-        this.$message.error("鎶ュ憡鏈鎵规垨瀹℃壒鏈�氳繃锛屾棤娉曚笅杞�")
-        return
-      }
-      let url = this.downLoadInfo.enterUrlS ? this.downLoadInfo.enterUrlS : this.downLoadInfo.enterUrl
-      if(url){
-        url = url.split('.')[0]+'.pdf'
-        const link = document.createElement('a');
-        link.href = this.javaApi + url;
-        link.target = '_blank';
-        document.body.appendChild(link);
-        link.click();
-      }
+    canView(item) { return !!item.url && Number(item.status) === 1 },
+    preview(item) {
+      if (!this.canView(item)) return
+      this.$refs.reportPreview.open([{
+        key: item.key, label: item.label, format: 'pdf',
+        filename: reportFilename(item.label, 'pdf'),
+        load: signal => loadReportFile(reportPdfPath(item.url), signal)
+      }])
     },
-    // 瀛e害妫�楠屾姤鍛婁笅杞�
-    downLoad1 () {
-      if(this.downLoadInfo.quarterRatifyStatus !== 1){
-        this.$message.error("鎶ュ憡鏈鎵规垨瀹℃壒鏈�氳繃锛屾棤娉曚笅杞�")
-        return
-      }
-      let url = this.downLoadInfo.quarterUrlS ? this.downLoadInfo.quarterUrlS : this.downLoadInfo.quarterUrl
-      if(url){
-        url = url.split('.')[0]+'.pdf'
-        const link = document.createElement('a');
-        link.href = this.javaApi + url;
-        link.target = '_blank';
-        document.body.appendChild(link);
-        link.click();
-      }
+    download(item) {
+      if (this.canView(item)) this.$download.url(reportPdfPath(item.url), item.label + '.pdf')
     }
-  },
+  }
 }
 </script>
 
 <style scoped>
-:deep(.el-dialog) {
-  height: 160px;
-}
+.report-choice { display: flex; align-items: center; gap: 12px; padding: 12px 0; flex-wrap: wrap; }
+.report-unavailable { color: var(--el-text-color-secondary); font-size: 12px; }
 </style>

--
Gitblit v1.9.3