Ver código fonte

价格申报单导入失败下载文件

黄梓星 1 ano atrás
pai
commit
0635af09dd

+ 9 - 0
src/api/business/purchase/apply.js

@@ -48,3 +48,12 @@ export function mbDownload(data) {
     responseType: 'blob'
   })
 }
+// 导入失败文件下载
+export function failDownload(data) {
+  return request({
+    url: `/pu/priceApply/downloadFailData`,
+    method: 'post',
+    data: data,
+    responseType: 'blob'
+  })
+}

+ 22 - 2
src/views/purchase/apply/index.vue

@@ -1,7 +1,7 @@
 <script>
 import { dicts } from "./dicts";
 import useColumns from "./columns";
-import { LIST, mbDownload } from "@/api/business/purchase/apply";
+import { LIST, mbDownload, failDownload} from "@/api/business/purchase/apply";
 // 导入的token
 import { getToken } from "@/utils/auth";
 
@@ -127,7 +127,27 @@ export default {
       this.upload.open = false;
       this.upload.isUploading = false;
       this.$refs.upload.clearFiles();
-      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
+      this.$alert(response.data.msg, "导入结果", { dangerouslyUseHTMLString: true });
+      // 有失败的再次下载下来
+      if(response.data.flag) {
+        this.$modal.loading("正在下载导入失败数据,请稍后...");
+        failDownload({failDatas:response.data.datas}).then(res => {
+          this.$modal.closeLoading();
+          const blob = new Blob([res], {
+            type: "application/vnd.ms-excel;charset=UTF-8",
+          });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
+          const downloadElement = document.createElement("a"); //创建a标签
+          const href = window.URL.createObjectURL(blob); // 创建下载的链接
+          downloadElement.href = href;  //下载地址
+          downloadElement.download = '价格申报单导入失败数据' + this.parseTime(new Date().getTime()) + ".xlsx"; // 下载后文件名
+          document.body.appendChild(downloadElement);
+          downloadElement.click(); // 点击下载
+          document.body.removeChild(downloadElement); // 下载完成移除元素
+          window.URL.revokeObjectURL(href); // 释放blob对象
+        }).catch(err => {
+          this.$modal.closeLoading();
+        })
+      }
       this.useQuery(this.params, this.page);
     },
     errorFile(err) {