ソースを参照

1、pdf合并下载

huangmp 2 年 前
コミット
8fbe74ce97

+ 2 - 0
package.json

@@ -18,8 +18,10 @@
     "element-ui": "2.15.7",
     "file-saver": "^2.0.5",
     "js-base64": "^3.6.1",
+    "jszip": "^3.10.1",
     "lodash": "4.17.5",
     "moment": "^2.29.1",
+    "pdf-lib": "^1.17.1",
     "qrcode": "^1.4.4",
     "video.js": "^7.8.4",
     "videojs-contrib-hls": "^5.15.0",

+ 9 - 9
src/views/modules/afterSales/thirdAfterSales.vue

@@ -4,11 +4,11 @@
     <div class="search-bar">
       <el-form :inline="true" class="search-form" ref="searchForm" :model="searchForm" label-width="auto" size="small">
         <div class="input-row">
-          <el-form-item label="售后渠道" class="search-form-item">
+          <el-form-item label="售后渠道" class="search-form-item" v-if="shopId === 1">
             <el-select v-model="searchForm.printChannel" clearable>
               <el-option label="广森" value="GSART"></el-option>
-              <el-option label="快印" value="KuaiYin"></el-option>
-              <el-option label="蜗牛" value="WoNiu"></el-option>
+              <el-option label="快印" value="KuaiYin" v-if="shopId === 1"></el-option>
+              <el-option label="蜗牛" value="WoNiu" v-if="shopId === 1"></el-option>
             </el-select>
           </el-form-item>
           <el-form-item label="订单编号" class="search-form-item">
@@ -76,8 +76,8 @@
     <!-- 列表相关区域 -->
     <div class="main-container">
       <div class="operation-bar">
-        <div class="default-btn primary-btn" @click="addOrUpdateHandle()">新增售后</div>
-        <div class="default-btn primary-btn" @click.stop="getUpload()">导入售后数据</div>
+        <div class="default-btn primary-btn" v-if="shopId === 1" @click="addOrUpdateHandle()">新增售后</div>
+        <div class="default-btn primary-btn" v-if="shopId === 1" @click.stop="getUpload()">导入售后数据</div>
       </div>
       <div class="table-con spec-table">
         <el-table
@@ -133,13 +133,13 @@
               <span>{{ scope.row.costAmount}}</span>
             </template>
           </el-table-column>
-          <el-table-column label="退款金额" prop="refundAmount" align="center" v-if="shopId === 1">
+          <el-table-column label="退款金额" v-if="shopId === 1" prop="refundAmount" align="center">
             <template slot-scope="scope">
               <span>{{ scope.row.refundAmount}}</span>
             </template>
           </el-table-column>
           <!-- 退款方式 -->
-          <el-table-column label="退款方式" prop="refundType" align="center">
+          <el-table-column label="退款方式" v-if="shopId == 1" prop="refundType" align="center">
             <template slot-scope="scope">
               <span v-if="scope.row.refundType === 0">余额</span>
               <span v-if="scope.row.refundType === 1">微信</span>
@@ -156,8 +156,8 @@
             <template slot-scope="scope">
               <div class="text-btn-con">
                 <div class="default-btn text-btn" @click="addOrUpdateHandle(scope.row.id, true)">详情</div>
-                <div class="default-btn text-btn" @click="addOrUpdateHandle(scope.row.id, false)">{{$t("crud.updateBtn")}}</div>
-                <div class="default-btn text-btn" @click.stop="deleteHandle(scope.row.id)">{{$t("text.delBtn")}}</div>
+                <div class="default-btn text-btn" v-if="shopId == 1" @click="addOrUpdateHandle(scope.row.id, false)">{{$t("crud.updateBtn")}}</div>
+                <div class="default-btn text-btn" v-if="shopId == 1" @click.stop="deleteHandle(scope.row.id)">{{$t("text.delBtn")}}</div>
                 </div>
             </template>
           </el-table-column>

+ 1 - 0
src/views/modules/print/print-order-info.vue

@@ -11,6 +11,7 @@
       width="80%"
       @close="closeDialog"
       v-if="visible"
+      top="1vh"
    >
     <div class="new-page-title">
       <div class="line" />

+ 34 - 8
src/views/modules/print/print-order.vue

@@ -99,6 +99,17 @@
               </el-select>
             </template>
           </el-form-item>
+          <el-form-item label="是否合单"  :label-width=" lang === 'en' ? '145px' : '85px'">
+            <template>
+              <el-select
+                v-model="dataForm.isMerge"
+                clearable
+                size="small">
+                <el-option key="1" label="否" value="1"></el-option>
+                <el-option key="2" label="是" value="2"></el-option>
+              </el-select>
+            </template>
+          </el-form-item>
           <el-form-item label="张数:" :label-width=" lang === 'en' ? '145px' : '85px'">
             <InputNumberRange v-model="productNumsRange"></InputNumberRange>
           </el-form-item>
@@ -140,11 +151,12 @@
     <div class="main">
       <div class="content">
         <div style="margin-bottom: 20px">
-          <el-checkbox @change="checked=>handleSelectAll(checked)" class="all-check-btn" >全选 </el-checkbox>
+          <el-checkbox @change="checked=>handleSelectAll(checked)" class="all-check-btn" v-model="selectAll">全选 </el-checkbox>
           <span v-if="dataListSelections.size" class="had-selected">已选 {{dataListSelections.size}}</span>
+          <span v-if="dataListSelections.size" class="had-selected" style="font-weight: bold;color: red;font-size: 20px"> {{selectSheets}}张</span>
           <el-button size="small" type="primary" icon="el-icon-plus" @click="openGenerateWaveDialog">生成波次</el-button>
           <el-button size="small" icon="el-icon-upload2" @click="openAddToWaveDialog">添加已有波次</el-button>
-          <el-button size="small" type="success" @click="checkAndAutoCreateWave">自动生成波次</el-button>
+<!--          <el-button size="small" type="success" @click="checkAndAutoCreateWave">自动生成波次</el-button>-->
         </div>
         <!-- 列标题 -->
         <div :class="['tit', showHeadScroll ? 'fixed-top' : '']">
@@ -180,7 +192,7 @@
           v-for="(order, index) in dataList"
           :key="order.printOrderId">
           <div class="prod-tit">
-            <el-checkbox v-model="order.checkStatus" :ref="'checkbox' + index" @change="checked=>handleSelectionChange(checked, order.orderNumber)"></el-checkbox>
+            <el-checkbox v-model="order.checkStatus" :ref="'checkbox' + index" @change="checked=>handleSelectionChange(checked, order)"></el-checkbox>
             <span class="order-number">{{ $t("order.number") }}:{{ order.orderNumber }}</span>
             <span class="order-time">用户下单时间:{{ order.orderTime }}</span>
             <span class="order-time">推送时间:{{ order.createTime }}</span>
@@ -486,6 +498,7 @@
         numList: [10, 20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,'更多'],
         dataListLoading: false,
         dataListSelections: new Set(),
+        selectSheets: 0,
         generateWaveDialogVisible: false,
         timeActive: null,
         numActive: null,
@@ -731,25 +744,38 @@
        */
       handleSelectAll (checked) {
         let it = this;
+        it.selectSheets = 0;
         if(checked){
+          it.selectAll = true;
           this.dataList.forEach((item, index) => {
             it.$set(item,'checkStatus',true)
             it.dataListSelections.add(item.orderNumber);
-            it.selectAll = true
+            it.selectSheets = it.selectSheets + item.prodNums;
           })
         }else{
           this.dataList.forEach((item, index) => {
             it.$set(item,'checkStatus',false)
             it.dataListSelections.delete(item.orderNumber);
-            it.selectAll = false;
           })
+          it.selectAll = false;
+          this.selectSheets = 0;
         }
+
       },
-      handleSelectionChange(checked, orderNumber){
+      handleSelectionChange(checked, order){
         if(checked){
-          this.dataListSelections.add(orderNumber);
+          this.dataListSelections.add(order.orderNumber);
+          this.selectSheets = this.selectSheets + order.prodNums;
+          if(this.dataListSelections.size === this.dataList.length){
+            this.selectAll = true;
+          }
         }else{
-          this.dataListSelections.delete(orderNumber)
+          this.dataListSelections.delete(order.orderNumber);
+          this.selectSheets = this.selectSheets - order.prodNums;
+          if(this.dataListSelections.size == 0){
+            this.selectAll = false;
+            this.selectSheets = 0;
+          }
         }
       },
       /**

+ 137 - 12
src/views/modules/print/wave-print-order.vue

@@ -40,7 +40,8 @@
               <span style="margin-left: 30px" v-if="wave.updateTime">{{wave.updateTime}}</span>
             </div>
             <el-button size="small" @click="generatePdfCombinationBatch" :disabled="wave.productionStatus == 0" :loading="wavePrintOrderPdfDownloadLoading">批量生成PDF</el-button>
-            <el-button size="small" @click="downloadPdfBatch" :disabled="wave.productionStatus == 0" :loading="wavePrintOrderPdfDownloadLoading">批量下载ZIP</el-button>
+<!--            <el-button size="small" @click="downloadPdfBatch" :disabled="wave.productionStatus == 0" :loading="wavePrintOrderPdfDownloadLoading">批量下载ZIP</el-button>-->
+            <el-button size="small" @click="mergeAndDownloadPDF" :disabled="wave.productionStatus == 0" :loading="wavePrintOrderPdfDownloadLoading">合并PDF并下载</el-button>
 <!--            <el-button size="small" @click="downloadPrintOrderPdfZip" :disabled="wave.productionStatus == 0" :loading="wavePrintOrderPdfDownloadLoading">批量下载PDF</el-button>-->
             <el-button size="small" :loading="wavePrintOrderInfoDownloadLoading" @click="downloadWavePrintOrderInfo" :disabled="wave.productionStatus == 0">下载订单信息</el-button>
             <el-button size="small" @click="openScanDialog" :disabled="wave.productionStatus == 0">扫描发货</el-button>
@@ -77,9 +78,9 @@
                   </el-form>
                 </template>
               </el-table-column>-->
-              <el-table-column
-                type="selection">
-              </el-table-column>
+<!--              <el-table-column-->
+<!--                type="selection">-->
+<!--              </el-table-column>-->
               <el-table-column
                 align="center"
                 prop="serialNo"
@@ -251,7 +252,7 @@
             @size-change="handleSizeChange"
             @current-change="handleCurrentChange"
             :current-page="page.currentPage"
-            :page-sizes="[61, 122]"
+            :page-sizes="[61, 200, 400, 600]"
             :page-size="page.pageSize"
             layout="total, sizes, prev, pager, next, jumper"
             :total="page.total">
@@ -298,6 +299,7 @@
 </template>
 
 <script>
+  import {PDFDocument}  from 'pdf-lib';
   import ProdPic from '@/components/prod-pic';
   import InputNumberRange from '@/components/input-number-range';
   import ExpressBillUpload from './express-bill-upload';
@@ -633,17 +635,18 @@
         })
       },
       generatePdfCombinationBatch(){
-        if(this.dataListSelections.size == 0){
-          this.$message.error("请至少选择一个订单");
-          return ;
-        }
+        // if(this.dataListSelections.size == 0){
+        //   this.$message.error("请至少选择一个订单");
+        //   return ;
+        // }
         this.$confirm('确定要批量生成PDF吗?', '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
         }).then(() => {
-          let orderNumberList = this.dataListSelections.map(item=>item['orderNumber'])
-          let dataBody = {"printChannel": this.printChannel, "waveId": this.wave.waveId, orderNumberList: orderNumberList};
+          // let orderNumberList = this.dataListSelections.map(item=>item['orderNumber'])
+          // let dataBody = {"printChannel": this.printChannel, "waveId": this.wave.waveId, orderNumberList: orderNumberList};
+          let dataBody = {"printChannel": this.printChannel, "waveId": this.wave.waveId};
           this.$http({
             url: this.$http.adornUrl('/printOrder/printOrder/generatePdfCombinationBatch'),
             method: 'post',
@@ -677,7 +680,6 @@
             type: 'application/zip'
           })
           saveAs(blob, fileName)
-          // downloadZip(data, fileName + ".zip");
         }).catch((error) => {
           this.wavePrintOrderPdfDownloadLoading = false;
         })
@@ -712,6 +714,23 @@
           xmlhttp.send();
         });
       },
+      getPdfFile2 (url) {
+        return new Promise((resolve, reject) => {
+          try {
+            let xmlhttp = new XMLHttpRequest();
+            xmlhttp.open("GET", url, true);
+            xmlhttp.responseType = "arraybuffer";
+            xmlhttp.onload = function () {
+              if (this.status == 200) {
+                resolve(this.response);
+              }else{
+                reject(this.status);
+              }
+            }
+            xmlhttp.send();
+          } catch (ignored) {}
+        });
+      },
       downloadPdfBatch () {
         if(this.dataListSelections.size == 0){
           this.$message.error("请至少选择一个订单");
@@ -752,6 +771,112 @@
         });
       },
 
+      /*//合并并下载PDF
+      async mergeAndDownloadPDF(){ // urlList 单个PDF文件的URL
+        try{
+          this.wavePrintOrderPdfDownloadLoading = true;
+          // 获取pdf链接集合
+          this.getPrintPdfBatch().then(async (list)=>{
+            let pdfUrlList = [];
+            for(let i=0 ; i <list.length; i++){
+              let pdfList = list[i].pdfList;
+              for(let j=0 ; j <pdfList.length; j++){
+                pdfUrlList.push(this.resourcesUrl + pdfList[j].pdfUrl);
+              }
+            }
+            let promises = [];
+            pdfUrlList.forEach(url =>{
+              let promise = this.getPdfFile2(url);
+              promises.push(promise);
+            })
+            let pdfBuffers = await Promise.all(promises);
+            let newPdf = await PDFDocument.create();
+            for (let k=0 ; k<pdfBuffers.length; k++) {
+              let pdfDocument = await PDFDocument.load(pdfBuffers[k]);
+              let contentPages = await newPdf.copyPages(pdfDocument, pdfDocument.getPageIndices());
+              for (let l=0; l<contentPages.length; l++) {
+                newPdf.addPage(contentPages[l]);
+              }
+            }
+            let uint8Array = await newPdf.save();
+            let mergeBuffer = Buffer.from(uint8Array);
+            downloadPdf(mergeBuffer, this.wave.waveNo + "_" + this.wave.waveName + ".pdf");
+            this.wavePrintOrderPdfDownloadLoading = false;
+          });
+        }catch (error) {
+          this.wavePrintOrderPdfDownloadLoading = false;
+        }
+
+      },*/
+
+      //合并并下载PDF
+      async mergeAndDownloadPDF(){ // urlList 单个PDF文件的URL
+        try{
+          this.wavePrintOrderPdfDownloadLoading = true;
+          // 获取pdf链接集合
+          this.getPrintPdfBatch().then(async (list)=>{
+            // let pdfUrlList = [];
+            let newPdf = await PDFDocument.create();
+            for(let i=0 ; i <list.length; i++){
+              let pdfList = list[i].pdfList;
+              for(let j=0 ; j <pdfList.length; j++){
+                // pdfUrlList.push(this.resourcesUrl + pdfList[j].pdfUrl);
+                let pdfBuffer = await this.getPdfFile2(this.resourcesUrl + pdfList[j].pdfUrl);
+                let pdfDocument = await PDFDocument.load(pdfBuffer);
+                let contentPages = await newPdf.copyPages(pdfDocument, pdfDocument.getPageIndices());
+                for (let l=0; l<contentPages.length; l++) {
+                  newPdf.addPage(contentPages[l]);
+                }
+              }
+            }
+            // let promises = [];
+            // pdfUrlList.forEach(url =>{
+            //   let promise = this.getPdfFile2(url);
+            //   promises.push(promise);
+            // })
+            // let pdfBuffers = await Promise.all(promises);
+            //
+            // for (let k=0 ; k<pdfBuffers.length; k++) {
+            //   let pdfDocument = await PDFDocument.load(pdfBuffers[k]);
+            //   let contentPages = await newPdf.copyPages(pdfDocument, pdfDocument.getPageIndices());
+            //   for (let l=0; l<contentPages.length; l++) {
+            //     newPdf.addPage(contentPages[l]);
+            //   }
+            // }
+            let uint8Array = await newPdf.save();
+            let mergeBuffer = Buffer.from(uint8Array);
+            downloadPdf(mergeBuffer, this.wave.waveNo + "_" + this.wave.waveName + ".pdf");
+            this.wavePrintOrderPdfDownloadLoading = false;
+          });
+        }catch (error) {
+          this.wavePrintOrderPdfDownloadLoading = false;
+        }
+
+      },
+
+      /**
+       *  获取打印订单的所有PDF文件
+       */
+      getPrintPdfBatch(){
+        // if(this.dataListSelections.size == 0){
+        //   this.$message.error("请至少选择一个订单");
+        //   return ;
+        // }
+        return new Promise((resolve, reject) => {
+          // 获取pdf链接集合
+          // let orderNumberList = this.dataListSelections.map(item=>item['orderNumber'])
+          this.$http({
+            url: this.$http.adornUrl(`/printOrder/printOrder/getPrintPdfBatch`),
+            method: 'POST',
+            // data: this.$http.adornData({printChannel: this.wave.printChannel, waveId: this.wave.waveId, orderNumberList: orderNumberList})
+            data: this.$http.adornData({printChannel: this.wave.printChannel, waveId: this.wave.waveId})
+          }).then(({ data }) => {
+            resolve(data);
+          });
+        })
+
+      },
+
       // 跳转至导入选择
       getUpload () {
         this.uploadVisible = true

+ 1 - 1
src/views/modules/print/wave.vue

@@ -397,7 +397,7 @@
       handleCurrentChange (val) {
         this.page.currentPage = val
         this.getDataList()
-      }
+      },
     }
   }
 </script>