gjy 3 år sedan
förälder
incheckning
edc3901ebc
1 ändrade filer med 69 tillägg och 5 borttagningar
  1. 69 5
      src/views/houseSelfCollect/paymentManagement.vue

+ 69 - 5
src/views/houseSelfCollect/paymentManagement.vue

@@ -251,6 +251,8 @@ import {
   import {
     downloadFile
   } from '@/utils/batchDown'
+  import JSZip from 'jszip'
+  import FileSaver from 'file-saver'
   import {
     getpayment,
     selectWarehouseSelf,
@@ -270,6 +272,7 @@ import {
   import {
     getHp
   } from '@/utils/getHasPermission'
+import download from '../../components/WsDownload/download'
   export default {
     components: {
       paymentPrint
@@ -373,6 +376,53 @@ import {
           })
 
       },
+        /**文件打包
+  * arrImages:文件list:[{fileUrl:文件url,renameFileName:文件名}]
+  * filename 压缩包名
+  * */
+  filesToRar(arrImages, filename) {
+  let _this = this;
+  let zip = new JSZip();
+  let cache = {};
+  let promises = [];
+  _this.title = '正在加载压缩文件';
+  for (let item of arrImages) {
+   const promise= _this.getImgArrayBuffer(item.fileUrl).then(data => {
+   // 下载文件, 并存成ArrayBuffer对象(blob)
+   zip.file(item.renameFileName, data, { binary: true }); // 逐个添加文件
+   cache[item.renameFileName] = data;
+   });
+   promises.push(promise);
+  }
+  Promise.all(promises).then(() => {
+   zip.generateAsync({ type: "blob" }).then(content => {
+   _this.title = '正在压缩';
+   // 生成二进制流
+   FileSaver.saveAs(content, filename); // 利用file-saver保存文件 自定义文件名
+   _this.title = '压缩完成';
+   });
+  }).catch(res=>{
+   _this.$message.error('文件压缩失败');
+  });
+  },
+ //获取文件blob
+  getImgArrayBuffer(url){
+  let _this=this;
+  return new Promise((resolve, reject) => {
+   //通过请求获取文件blob格式
+   let xmlhttp = new XMLHttpRequest();
+   xmlhttp.open("GET", url, true);
+   xmlhttp.responseType = "blob";
+   xmlhttp.onload = function () {
+   if (this.status == 200) {
+    resolve(this.response);
+   }else{
+    reject(this.status);
+   }
+   }
+   xmlhttp.send();
+  });
+  },
       invoicingClick() {
         // let data = JSON.stringify({
         //   paymentManagementList : this.modification
@@ -394,14 +444,28 @@ import {
             debugger
             console.log(response)
             if (response.length > 0) {
+              
+              var arr=[]
               for (let i = 0; i < response.length; i++) {
+                arr.push({fileUrl:response[i],renameFileName:'发票'+i})
                 //创建标签下载文件
-                let a = document.createElement('a');
-                a.href = response[i];
-                a.setAttribute('download', response[i]);
-                a.click();
-                a.remove();
+                // window.open(response[i],)
+                // let a = document.createElement('a');
+                // // a.href = response[i];
+                // a.setAttribute('target', 'blank');
+                // a.setAttribute('download', response[i]);
+                // a.setAttribute('href', response[i]);
+                // a.click();
+                // a.remove();
+                // let b = document.createElement('a');
+                // // b.href = response[i];
+                // b.setAttribute('target', 'blank');
+                // b.setAttribute('download', response[i]);
+                // b.setAttribute('href', response[i]);
+                // b.click();
+                // b.remove();
               }
+              this.filesToRar(arr, 'download')
             }
             //未完成,接口调通后替换假数据
             // response = {