From 8595b6aa074eafd86cdd99d1ab3a2623b842e961 Mon Sep 17 00:00:00 2001
From: WXL <1785969728@qq.com>
Date: 星期三, 20 三月 2024 18:13:26 +0800
Subject: [PATCH] 11

---
 src/views/project/unitCost/index.vue |   43 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/views/project/unitCost/index.vue b/src/views/project/unitCost/index.vue
index ed51192..229c77e 100644
--- a/src/views/project/unitCost/index.vue
+++ b/src/views/project/unitCost/index.vue
@@ -165,7 +165,7 @@
           <el-button
             size="mini"
             type="primary"
-            @click="download(scope.row)"
+            @click="download(scope.row.id)"
             icon="el-icon-download"
             circle
           ></el-button>
@@ -184,7 +184,7 @@
     <el-dialog
       :visible.sync="showSelectionDialog"
       :close-on-click-modal="false"
-      :title="'璇烽�夋嫨鎹愮尞妗堜緥'"
+      :title="'浠樻鍖荤枟鏈烘瀯閫夋嫨'"
       width="500px"
       style="text-align: center"
       v-loading="loading"
@@ -227,6 +227,7 @@
 import { listOrganization } from "@/api/project/organization";
 
 import OrgSelecter from "@/views/project/components/orgselect";
+import { getToken } from "@/utils/auth";
 
 export default {
   name: "Donorcharge",
@@ -290,6 +291,9 @@
         pageNum: 1,
         pageSize: 10,
         donorchargeid: null
+      },
+      headers: {
+        Authorization: "Bearer " + getToken()
       },
       // 琛ㄥ崟鍙傛暟
       form: {},
@@ -431,8 +435,39 @@
       });
     },
     // 鎵撳嵃
-    download(row) {
-      dyDonorpayment(row.id).then(res => {});
+    download(id) {
+      // const id =this.row.id
+      dyDonorpayment(id).then(res => {
+        var fileUrl = res;
+        //鑾峰彇褰撳墠缃戝潃
+        var urlBase = process.env.VUE_APP_BASE_API;
+        var curWWWPath = window.document.location.href;
+        var pos = curWWWPath.indexOf(window.document.location.pathname);
+        // 鍒涘缓a鏍囩
+        var aEle = document.createElement("a");
+        aEle.href =
+          curWWWPath.substring(0, pos) + urlBase + fileUrl["downloadUrl"];
+        console.log(aEle.href);
+        // 娣诲姞Authorization澶撮儴
+        fetch(aEle.href, {
+          headers: this.headers
+        })
+          .then(response => {
+            // 灏嗘枃浠朵笅杞介摼鎺ヤ綔涓篵lob瀵硅薄杩涜涓嬭浇
+            return response.blob();
+          })
+          .then(blob => {
+            const url = window.URL.createObjectURL(new Blob([blob]));
+            console.log(url);
+            const link = document.createElement("a");
+            link.href = url;
+            const name = fileUrl["downloadName"];
+            link.setAttribute("download", name); // 鏇挎崲file.pdf涓哄疄闄呯殑鏂囦欢鍚�
+            document.body.appendChild(link);
+            link.click();
+            link.parentNode.removeChild(link);
+          });
+      });
     },
 
     /** 鍒犻櫎鎸夐挳鎿嶄綔 */

--
Gitblit v1.9.3