From d9c209aecf592804ba2d119a65eddc1f73bd913c Mon Sep 17 00:00:00 2001 From: WXL <1785969728@qq.com> Date: 星期三, 28 二月 2024 15:09:03 +0800 Subject: [PATCH] 11 --- src/views/project/travelexpenseapply/travelexpensedetail/index.vue | 89 +++++++++++++++++++++++++------------------- 1 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/views/project/travelexpenseapply/travelexpensedetail/index.vue b/src/views/project/travelexpenseapply/travelexpensedetail/index.vue index ead57ef..f1e7bbd 100644 --- a/src/views/project/travelexpenseapply/travelexpensedetail/index.vue +++ b/src/views/project/travelexpenseapply/travelexpensedetail/index.vue @@ -1636,7 +1636,7 @@ this.tableDatatop = []; this.fileListto = []; this.invoicefileListto = []; - this.pdfimg = []; + this.pdfimg = ""; this.invoicepdfimg = []; this.pdfimgsrcList = []; this.invoicepdfimgsrcList = []; @@ -1645,26 +1645,32 @@ this.pdfVisible = true; if (this.rbDetails[index].annexfilesList) { - this.rbDetails[index].annexfilesList.forEach((value, indexson) => { - const pdfimg = this.Networkheader + "/prod-api" + value.url; - fetch(pdfimg, config) - .then(response => response.blob()) - .then(blob => { - // 灏嗚幏鍙栫殑鏁版嵁娴佽浆鎹负URL - this.fileListto.push({ - name: value.name, - url: URL.createObjectURL(blob) + + const fetchPromises = this.rbDetails[index].annexfilesList.map( + (value, indexson) => { + const pdfimg = this.Networkheader + "/prod-api" + value.url; + return fetch(pdfimg, config) + .then(response => response.blob()) + .then(blob => { + return { + name: value.name, + url: URL.createObjectURL(blob) + }; + }) + .catch(error => { + console.error("Error loading image", error); + return null; }); - if (this.fileListto.length == 1) { - this.pdfimg = URL.createObjectURL(blob); - } - this.pdfimgsrcList.push(URL.createObjectURL(blob)); - }) - .catch(error => { - console.error("Error loading image", error); - return; - }); + } + ); + + Promise.all(fetchPromises).then(fileListto => { + this.fileListto = fileListto.filter(item => item !== null); + this.pdfimg = this.fileListto[0].url; + console.log(this.pdfimg, "pdfimg"); + this.pdfimgsrcList = this.fileListto.map(item => item.url); }); + this.previewpdf = true; } else { this.fileListto = []; @@ -1673,26 +1679,31 @@ } //鍙戠エ if (this.rbDetails[index].invoicefilesList) { - this.rbDetails[index].invoicefilesList.forEach((value, indexson) => { - const pdfimg = this.Networkheader + "/prod-api" + value.url; - fetch(pdfimg, config) - .then(response => response.blob()) - .then(blob => { - // 灏嗚幏鍙栫殑鏁版嵁娴佽浆鎹负URL - this.invoicefileListto.push({ - name: value.name, - url: URL.createObjectURL(blob) + const fetchPromises = this.rbDetails[index].invoicefilesList.map( + (value, indexson) => { + const pdfimg = this.Networkheader + "/prod-api" + value.url; + return fetch(pdfimg, config) + .then(response => response.blob()) + .then(blob => { + return { + name: value.name, + url: URL.createObjectURL(blob) + }; + }) + .catch(error => { + console.error("Error loading image", error); + return null; }); - if (this.invoicefileListto.length == 1) { - this.invoicepdfimg = URL.createObjectURL(blob); - } - this.invoicepdfimgsrcList.push(URL.createObjectURL(blob)); - }) - .catch(error => { - console.error("Error loading image", error); - return; - }); + } + ); + + Promise.all(fetchPromises).then(invoicefileListto => { + this.invoicefileListto = invoicefileListto.filter(item => item !== null); + this.invoicepdfimg = this.invoicefileListto[0].url; + console.log(this.invoicepdfimg, "invoicepdfimg"); + this.invoicepdfimgsrcList = this.invoicefileListto.map(item => item.url); }); + this.previewpdf = true; } else { this.invoicefileListto = []; @@ -1700,11 +1711,13 @@ this.pdftitle = ""; } - if (this.activeName == 1) { + if (this.activeName == "common") { this.pdftitle = "鍏�" + this.pdfimgsrcList.length + "椤�"; } else { this.pdftitle = "鍏�" + this.invoicepdfimgsrcList.length + "椤�"; } + console.log(this.fileListto, "this.fileListto"); + console.log(this.rbDetails[index].annexfilesList, "annexfilesList"); }, // 鐐瑰嚮宸蹭笂浼犳枃浠� -- Gitblit v1.9.3