Sfoglia il codice sorgente

【修改】添加打印异常处理

howie 2 anni fa
parent
commit
2f11065726

+ 198 - 195
src/mixin/print.js

@@ -1,107 +1,107 @@
 import {
   disAutoConnect,
   hiprint,
-  defaultElementTypeProvider,
-} from "vue-plugin-hiprint";
-disAutoConnect();
-import panel from "@/utils/panel";
-import { addPrint, getDtailPrintDis } from "@/api/supply/pickup";
-import { getDeliverDetail } from "@/api/supply/deliver";
-import { addPrints } from "@/api/supply/pickup";
-import { getCompanyList } from "@/api/user";
+  defaultElementTypeProvider
+} from 'vue-plugin-hiprint'
+disAutoConnect()
+import panel from '@/utils/panel'
+import { addPrint, getDtailPrintDis } from '@/api/supply/pickup'
+import { getDeliverDetail } from '@/api/supply/deliver'
+import { addPrints } from '@/api/supply/pickup'
+import { getCompanyList } from '@/api/user'
 
 export default {
   data() {
     return {
-      company: "", // 公司名称
+      company: '', // 公司名称
       clonelData: [], // 克隆数据
       outputData: [], // 打印数据
       curPaper: {
-        type: "A5",
+        type: 'A5',
         width: 500,
-        height: 147.6,
+        height: 147.6
       },
       paperTypes: {
         A3: {
           width: 420,
-          height: 296.6,
+          height: 296.6
         },
         A4: {
           width: 210,
-          height: 296.6,
+          height: 296.6
         },
         A5: {
           width: 210,
-          height: 147.6,
+          height: 147.6
         },
         B3: {
           width: 500,
-          height: 352.6,
+          height: 352.6
         },
         B4: {
           width: 250,
-          height: 352.6,
+          height: 352.6
         },
         B5: {
           width: 250,
-          height: 175.6,
-        },
+          height: 175.6
+        }
       },
       scaleValue: 1,
       scaleMax: 5,
       scaleMin: 0.5,
       loading: false,
-      hiprintTemplate: "",
-      addIds: [],
-    };
+      hiprintTemplate: '',
+      addIds: []
+    }
   },
   computed: {
     curPaperType() {
-      let type = "other";
-      let types = this.paperTypes;
+      let type = 'other'
+      const types = this.paperTypes
       for (const key in types) {
-        let item = types[key];
-        let { width, height } = this.curPaper;
+        const item = types[key]
+        const { width, height } = this.curPaper
         if (item.width === width && item.height === height) {
-          type = key;
+          type = key
         }
       }
-      return type;
-    },
+      return type
+    }
   },
   created() {
-    this.getCompanyLists();
+    this.getCompanyLists()
   },
   methods: {
     // 初始化打印模板
     initPrint() {
       hiprint.init({
-        providers: [new defaultElementTypeProvider()],
-      });
+        providers: [new defaultElementTypeProvider()]
+      })
       // 替换配置
       hiprint.setConfig({
         movingDistance: 2.5,
         text: {
           supportOptions: [
             {
-              name: "styler",
-              hidden: true,
+              name: 'styler',
+              hidden: true
             },
             {
-              name: "formatter",
-              hidden: true,
-            },
-          ],
-        },
-      });
+              name: 'formatter',
+              hidden: true
+            }
+          ]
+        }
+      })
       // eslint-disable-next-line no-undef
-      hiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
+      hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'))
       this.hiprintTemplate = new hiprint.PrintTemplate({
         template: panel,
-        settingContainer: "#PrintElementOptionSetting",
-        paginationContainer: ".hiprint-printPagination",
-      });
-      this.hiprintTemplate.design("#hiprint-printTemplate");
+        settingContainer: '#PrintElementOptionSetting',
+        paginationContainer: '.hiprint-printPagination'
+      })
+      this.hiprintTemplate.design('#hiprint-printTemplate')
       // 获取当前放大比例, 当zoom时传true 才会有
       // this.scaleValue = hiprintTemplate.editingPanel.scale || 1;
     },
@@ -109,136 +109,139 @@ export default {
      * 获取需要打印数据详情
      * @param {Array} ids
      */
-    async getDateil(ids, funcType = "getDeliverDetail",check=null) {
-      this.$startLoading();
-      let loadingLen;
+    async getDateil(ids, funcType = 'getDeliverDetail', check = null) {
+      this.$startLoading()
+      let loadingLen
       // 兼容多个打印数据
-      ids = ids instanceof Array ? ids : [ids];
-      console.log(ids);
+      ids = ids instanceof Array ? ids : [ids]
+      console.log(ids)
       // 清空之前打印的数据
-      this.outputData = [];
+      this.outputData = []
       // 筛选id
-      let formatting = [];
+      let formatting = []
 
       // 仓库认证请求接口参数
-      let params = [];
+      const params = []
 
       // 获取数据id
       for (let i = ids.length; i > 0; i--) {
-        formatting.push(ids[i - 1].id || ids[i - 1]);
-        if (funcType === "getDtailPrintDis") {
+        formatting.push(ids[i - 1].id || ids[i - 1])
+        if (funcType === 'getDtailPrintDis') {
           params.push({
             id: ids[i - 1].id,
-            invoiceId: ids[i - 1].invoiceId,
-          });
-          this.addIds.push(ids[i - 1].id);
+            invoiceId: ids[i - 1].invoiceId
+          })
+          this.addIds.push(ids[i - 1].id)
         }
       }
 
-      if (funcType === "getDtailPrintDis") {
-        const requestParams = params;
+      if (funcType === 'getDtailPrintDis') {
+        const requestParams = params
         try {
-          const { data } = await getDtailPrintDis(requestParams);
-          loadingLen = data.length;
+          const { data } = await getDtailPrintDis(requestParams)
+          loadingLen = data.length
           for (let i = data.length; i > 0; i--) {
-            const newData = data[i - 1];
-            await this.setPrintData(newData,funcType,check);
-            loadingLen--;
+            const newData = data[i - 1]
+            await this.setPrintData(newData, funcType, check)
+            loadingLen--
           }
         } catch (error) {
-          this.$endLoading();
-          console.error("获取打印数据失败");
+          this.$endLoading()
+          console.error('获取打印数据失败')
         }
       } else {
         // id 去重
-        formatting = [...new Set(formatting)];
-        loadingLen = formatting.length;
+        formatting = [...new Set(formatting)]
+        loadingLen = formatting.length
         for (let i = formatting.length; i > 0; i--) {
           const requestParams = {
-            id: formatting[i - 1],
-          };
+            id: formatting[i - 1]
+          }
           try {
-            const { data } = await getDeliverDetail(requestParams);
-            this.setPrintData(data);
+            const { data } = await getDeliverDetail(requestParams)
+            this.setPrintData(data)
           } catch (error) {
-            this.$endLoading();
-            this.$errorMsg(error);
-            console.error("获取打印数据失败");
+            this.$endLoading()
+            this.$errorMsg(error)
+            console.error('获取打印数据失败')
           }
-          loadingLen--;
+          loadingLen--
         }
       }
       if (loadingLen == 0) {
-        return Promise.resolve();
+        return Promise.resolve()
       }
     },
     // 获取公司名称
     async getCompanyLists() {
       try {
-        const { data } = await getCompanyList();
-        this.company = data ? data[0].companyName : "";
+        const { data } = await getCompanyList()
+        this.company = data ? data[0].companyName : ''
       } catch (error) {
-        console.error("获取公司名称失败");
+        console.error('获取公司名称失败')
       }
     },
     // 获取当前时间
     nowDate() {
-      var date = new Date();
-      var seperator1 = "-";
-      var year = date.getFullYear();
-      var month = date.getMonth() + 1;
-      var strDate = date.getDate();
+      var date = new Date()
+      var seperator1 = '-'
+      var year = date.getFullYear()
+      var month = date.getMonth() + 1
+      var strDate = date.getDate()
       if (month >= 1 && month <= 9) {
-        month = "0" + month;
+        month = '0' + month
       }
       if (strDate >= 0 && strDate <= 9) {
-        strDate = "0" + strDate;
+        strDate = '0' + strDate
       }
-      var currentdate = year + seperator1 + month + seperator1 + strDate;
-      return currentdate;
+      var currentdate = year + seperator1 + month + seperator1 + strDate
+      return currentdate
     },
     // 格式化时间
     dateToDayFilter(date) {
       if (!date) {
-        return "";
+        return ''
       }
-      return date.slice(0, 10);
+      return date.slice(0, 10)
     },
     // 添加次数
-    async addPrint(funcType = "getDeliverDetail") {
-      let ids = [];
+    async addPrint(funcType = 'getDeliverDetail') {
+      let ids = []
       for (let i = this.clonelData.length; i > 0; i--) {
-        const tempData = this.clonelData[i - 1].invoicePickBeans;
+        const tempData = this.clonelData[i - 1].invoicePickBeans
         if (tempData.length) {
           for (let e = tempData.length; e > 0; e--) {
-            const newTempData = tempData[e - 1];
-            ids.push(newTempData.id);
+            const newTempData = tempData[e - 1]
+            ids.push(newTempData.id)
           }
         } else {
           return (
             this.clonelData[i - 1].invoiceOrderId || this.clonelData[i - 1].id
-          );
+          )
         }
       }
+      let requestParams = {}
       try {
-        let requestParams = {};
-        if (funcType === "getDtailPrintDis") {
-          ids = [...new Set(this.addIds)];
+        if (funcType === 'getDtailPrintDis') {
+          ids = [...new Set(this.addIds)]
           requestParams = {
-            ids: ids.join(","),
-          };
-          funcType = addPrint;
+            ids: ids.join(',')
+          }
+          funcType = addPrint
         } else {
           requestParams = {
-            ids: ids.join(","),
-          };
-          funcType = addPrints;
+            ids: ids.join(',')
+          }
+          funcType = addPrints
         }
-        await funcType(requestParams);
-        //清空当前克隆数据,避免重复添加次数
-        this.clonelData = [];
+
+        await funcType(requestParams)
+        // 清空当前克隆数据,避免重复添加次数
+        this.clonelData = []
       } catch (error) {
-        console.error("添加打印次数失败");
+        // console.error('添加打印次数失败')
+        this.clonelData = []
+        this.$errorMsg('添加打印次数失败' + JSON.stringify(requestParams))
       }
     },
     /**
@@ -252,19 +255,19 @@ export default {
           this.curPaper = {
             type: type,
             width: value.width,
-            height: value.height,
-          };
-          this.hiprintTemplate.setPaper(value.width, value.height);
+            height: value.height
+          }
+          this.hiprintTemplate.setPaper(value.width, value.height)
         } else {
           this.curPaper = {
-            type: "other",
+            type: 'other',
             width: value.width,
-            height: value.height,
-          };
-          this.hiprintTemplate.setPaper(value.width, value.height);
+            height: value.height
+          }
+          this.hiprintTemplate.setPaper(value.width, value.height)
         }
       } catch (error) {
-        this.$message.error(`操作失败: ${error}`);
+        this.$message.error(`操作失败: ${error}`)
       }
     },
     /**
@@ -273,59 +276,59 @@ export default {
      * @param {object} data
      * this.outputData 打印数据
      */
-    setPrintData(data,funcType,check) {
-      let salesOrderId, invoiceId; //出库单号,发货单号 默认数据中的第一个
-      salesOrderId = data.invoicePickBeans[0].salesOrderId;
-      invoiceId = data.invoicePickBeans[0].invoiceId;
-      let refUseUnit, refEnginRecordNo;
-      refUseUnit = data.refUseUnit || data.invoicePickBeans[0].refUseUnit || "";
+    setPrintData(data, funcType, check) {
+      let salesOrderId, invoiceId // 出库单号,发货单号 默认数据中的第一个
+      salesOrderId = data.invoicePickBeans[0].salesOrderId
+      invoiceId = data.invoicePickBeans[0].invoiceId
+      let refUseUnit, refEnginRecordNo
+      refUseUnit = data.refUseUnit || data.invoicePickBeans[0].refUseUnit || ''
       refEnginRecordNo =
         data.refEnginRecordNo ||
         data.invoicePickBeans[0].refEnginRecordNo ||
-        "";
-      let remark;
-      remark = funcType==='getDtailPrintDis'?data.invoicePickBeans[0].remark || "" : data.remark||"";
-      console.log(data.invoicePickBeans[0],'oo');
-      let tuiHuoRen = data.createBy;
+        ''
+      let remark
+      remark = funcType === 'getDtailPrintDis' ? data.invoicePickBeans[0].remark || '' : data.remark || ''
+      console.log(data.invoicePickBeans[0], 'oo')
+      const tuiHuoRen = data.createBy
       // 数量合计
-      let total = 0;
+      let total = 0
       // 初始化打印次数
-      let printNum = 0;
-      //避免数据发生改变
-      this.clonelData.push(JSON.parse(JSON.stringify(data)));
+      let printNum = 0
+      // 避免数据发生改变
+      this.clonelData.push(JSON.parse(JSON.stringify(data)))
       // 需要计算长度和数据裁切
-      let invoicePickBeans = data.invoicePickBeans;
+      const invoicePickBeans = data.invoicePickBeans
       // 获取length向上取整
-      let len = Math.ceil(invoicePickBeans.length / 5);
+      const len = Math.ceil(invoicePickBeans.length / 5)
       for (let index = 0; index < len; index++) {
-        const table = [];
+        const table = []
         //  length <= 0 则不执行打印
         if (invoicePickBeans.length) {
           // 取第一个条数据printNum
-          printNum = invoicePickBeans[0].printNum;
-          const newInvoicePickBeans = invoicePickBeans.splice(0, 5);
+          printNum = invoicePickBeans[0].printNum
+          const newInvoicePickBeans = invoicePickBeans.splice(0, 5)
           for (let e = newInvoicePickBeans.length; e > 0; e--) {
-            const tempData = newInvoicePickBeans[e - 1];
-            total += Math.abs(+tempData.refundableQty);
+            const tempData = newInvoicePickBeans[e - 1]
+            total += Math.abs(+tempData.refundableQty)
 
-            //添加表格数据
+            // 添加表格数据
             table.push({
               id: tempData.id,
               createTime: tempData.id
                 ? this.dateToDayFilter(data.createTime)
-                : "",
+                : '',
               enginOrderType:
-                tempData.orderType == "HOME" ||
-                tempData.orderType == "TRADE" ||
-                tempData.orderType === "REQUISITION_TRADE" ||
-                tempData.orderType === "REQUISITION_HOME"
+                tempData.orderType == 'HOME' ||
+                tempData.orderType == 'TRADE' ||
+                tempData.orderType === 'REQUISITION_TRADE' ||
+                tempData.orderType === 'REQUISITION_HOME'
                   ? tempData.enginOrderNo
                   : tempData.mainOrderId,
               materialName: tempData.materialName,
               specification: tempData.specification,
               refundableQty: tempData.refundableQty,
-              pjxh1Text: tempData.pjxh1Text,
-            });
+              pjxh1Text: tempData.pjxh1Text
+            })
           }
         }
         // 添加print输出数据
@@ -338,7 +341,7 @@ export default {
           refEnginRecordNo: refEnginRecordNo,
           type: data.type,
           tiTui: data.type === 2 ? `退货人` : `提货人`,
-          takerPhone: data.takerPhone || "",
+          takerPhone: data.takerPhone || '',
           headerRemark: remark,
           total_num: data.total_num,
           total: total,
@@ -348,19 +351,19 @@ export default {
               : `${this.company}销售发货单`,
           pickOrderWater: data.pickOrderWater,
           customerNumber: data.customerNumber,
-          takerDa: "",
+          takerDa: '',
           nowDate: this.nowDate(),
           takerName:
             data.type === 2
-              ? `退货人:${check ==0 ?data.pickLogistics||'':tuiHuoRen || ""}`
-              : `提货人:${check ==0 ?data.pickLogistics||'':data.takerName || ""}`,
-          customerName: data.customerName || "",
+              ? `退货人:${check == 0 ? data.pickLogistics || '' : tuiHuoRen || ''}`
+              : `提货人:${check == 0 ? data.pickLogistics || '' : data.takerName || ''}`,
+          customerName: data.customerName || '',
           correspondName: data.correspondName,
-          correspondNames: "",
-          pickCar: data.pickCar || "",
-          createBy: JSON.parse(localStorage.getItem("supply_user")).nickName,
-          table,
-        });
+          correspondNames: '',
+          pickCar: data.pickCar || '',
+          createBy: JSON.parse(localStorage.getItem('supply_user')).nickName,
+          table
+        })
       }
     },
     /**
@@ -440,75 +443,75 @@ export default {
                 </div>
             </div>
          </div>
-        `;
+        `
     },
     /**
      * 备份方法
      * 获取需要打印数据详情
      * @param {Array} ids
      */
-    async getDateils(ids, funcType = "getDeliverDetail") {
-      this.$startLoading();
-      let loadingLen;
+    async getDateils(ids, funcType = 'getDeliverDetail') {
+      this.$startLoading()
+      let loadingLen
       // 兼容多个打印数据
-      ids = ids instanceof Array ? ids : [ids];
-      console.log(ids);
+      ids = ids instanceof Array ? ids : [ids]
+      console.log(ids)
       // 清空之前打印的数据
-      this.outputData = [];
+      this.outputData = []
       // 筛选id
-      let formatting = [];
+      let formatting = []
 
       // 仓库认证请求接口参数
-      let params = [];
+      const params = []
 
       // 获取数据id
       for (let i = ids.length; i > 0; i--) {
-        formatting.push(ids[i - 1].id || ids[i - 1]);
-        if (funcType === "getDtailPrintDis") {
+        formatting.push(ids[i - 1].id || ids[i - 1])
+        if (funcType === 'getDtailPrintDis') {
           params.push({
             id: ids[i - 1].id,
-            invoiceId: ids[i - 1].invoiceId,
-          });
-          this.addIds.push(ids[i - 1].id);
+            invoiceId: ids[i - 1].invoiceId
+          })
+          this.addIds.push(ids[i - 1].id)
         }
       }
 
-      if (funcType === "getDtailPrintDis") {
-        const requestParams = params;
+      if (funcType === 'getDtailPrintDis') {
+        const requestParams = params
         try {
-          const { data } = await getDtailPrintDis(requestParams);
-          loadingLen = data.length;
+          const { data } = await getDtailPrintDis(requestParams)
+          loadingLen = data.length
           for (let i = data.length; i > 0; i--) {
-            const newData = data[i - 1];
-            await this.setPrintData(newData);
-            loadingLen--;
+            const newData = data[i - 1]
+            await this.setPrintData(newData)
+            loadingLen--
           }
         } catch (error) {
-          this.$endLoading();
-          console.error("获取打印数据失败");
+          this.$endLoading()
+          console.error('获取打印数据失败')
         }
       } else {
         // id 去重
-        formatting = [...new Set(formatting)];
-        loadingLen = formatting.length;
+        formatting = [...new Set(formatting)]
+        loadingLen = formatting.length
         for (let i = formatting.length; i > 0; i--) {
           const requestParams = {
-            id: formatting[i - 1],
-          };
+            id: formatting[i - 1]
+          }
           try {
-            const { data } = await getDeliverDetail(requestParams);
-            this.setPrintData(data);
+            const { data } = await getDeliverDetail(requestParams)
+            this.setPrintData(data)
           } catch (error) {
-            this.$endLoading();
-            this.$errorMsg(error);
-            console.error("获取打印数据失败");
+            this.$endLoading()
+            this.$errorMsg(error)
+            console.error('获取打印数据失败')
           }
-          loadingLen--;
+          loadingLen--
         }
       }
       if (loadingLen == 0) {
-        return Promise.resolve();
+        return Promise.resolve()
       }
-    },
-  },
-};
+    }
+  }
+}

+ 38 - 37
src/views/supply/deliver/components/design/preview.vue

@@ -3,13 +3,13 @@
     class="sub-main"
     :visible.sync="visible"
     :show-close="false"
-    :maskClosable="false"
+    :mask-closable="false"
     :close-on-click-modal="false"
-    @cancel="hideModal"
     :width="350 + 'mm'"
+    @cancel="hideModal"
   >
     <div v-loading="spinning" style="min-height: 100px">
-      <div id="preview_content" ref="printDom"></div>
+      <div id="preview_content" ref="printDom" />
     </div>
     <template slot="title">
       <div>
@@ -19,8 +19,7 @@
           type="primary"
           icon="printer"
           @click.stop="print"
-          >打印</el-button
-        >
+        >打印</el-button>
         <!-- <el-button type="primary" icon="printer" @click.stop="toPdf">pdf</el-button> -->
       </div>
     </template>
@@ -32,10 +31,10 @@
 
 <script>
 // import { downloadPDF } from '@/utils/pdf'
-import { addPrint } from "./print-data";
-import { detailArr } from "./print-data";
+import { addPrint } from './print-data'
+import { detailArr } from './print-data'
 export default {
-  name: "printPreview",
+  name: 'PrintPreview',
   props: {},
   data() {
     return {
@@ -48,8 +47,8 @@ export default {
       hiprintTemplate: {},
       // 数据
       printData: {},
-      loading:true
-    };
+      loading: true
+    }
   },
   computed: {},
   watch: {},
@@ -60,50 +59,53 @@ export default {
     //   downloadPDF(this.$refs.printDom);
     // },
     hideModal() {
-      this.visible = false;
-      this.waitShowPrinter = false;
-      this.$parent.initPrint();
+      this.visible = false
+      this.waitShowPrinter = false
+      this.$parent.initPrint()
       // console.log(this.$parent);
     },
-    show(hiprintTemplate, printData, width = "210") {
-      this.visible = true;
-      this.width = width;
-      this.hiprintTemplate = hiprintTemplate;
-      this.printData = printData;
+    show(hiprintTemplate, printData, width = '210') {
+      this.visible = true
+      this.width = width
+      this.hiprintTemplate = hiprintTemplate
+      this.printData = printData
 
       setTimeout(() => {
         // eslint-disable-next-line no-undef
-        $("#preview_content").html(hiprintTemplate.getHtml(printData));
-        this.spinning = false;
-      }, 500);
+        $('#preview_content').html(hiprintTemplate.getHtml(printData))
+        this.spinning = false
+      }, 500)
     },
     print() {
       this.hiprintTemplate.print(
         this.printData,
         {},
         {
-          callback: () => {
-            this.$parent.addPrint('addPrints');
-            this.hiprintTemplate = {};
-            this.$parent.tableSelection = [];
+          callback: async() => {
+            try {
+              await this.$parent.addPrint('addPrints')
+            } catch (e) {
+              console.log('调用打印次数接口失败')
+            }
+            this.hiprintTemplate = {}
+            this.$parent.tableSelection = []
+            await this.$parent.getList()
             setTimeout(() => {
-              this.$parent.getList();
-              console.error("更新发货汇总列表");
-            }, 1000);
-
-          },
+              console.error('更新发货汇总列表')
+            }, 1000)
+          }
         }
-      );
+      )
       setTimeout(() => {
-        this.hideModal();
-      }, 2000);
-    },
+        this.hideModal()
+      }, 2000)
+    }
     // toPdf() {
     //   downloadPDF(this.$refs.printDom);
     //   this.hiprintTemplate.toPdf({}, '打印预览');
     // },
-  },
-};
+  }
+}
 </script>
 
 <style scoped>
@@ -124,7 +126,6 @@ export default {
  -webkit-box-orient: vertical;
 }
 
-
 ::v-deep .hiprint-printPaper {
   margin: 0 auto;
 }

+ 3 - 4
src/views/supply/deliver/components/sum_print.vue

@@ -60,7 +60,8 @@ export default {
       printObj: {
         id: 'printMe',
         closeCallback: () => {
-          this.addPrint()
+          console.log('添加打印次数')
+          // this.addPrint()
         }
       },
       detailData: {},
@@ -91,7 +92,6 @@ export default {
     getDetail(id) {
       getDeliverDetail({ id: id }).then(res => {
         this.detailArr.push(res.data)
-
       })
     },
 
@@ -106,13 +106,12 @@ export default {
       const ids = this.detailArr.map(item => {
         if (item.invoicePickBeans && item.invoicePickBeans.length) {
           for (let index = 0; index < item.invoicePickBeans.length; index++) {
-            const element = item.invoicePickBeans[index];
+            const element = item.invoicePickBeans[index]
             return item.invoiceOrderId || element.invoiceOrderId || element.id
           }
         } else {
           return item.invoiceOrderId || item.id
         }
-
       })
 
       // console.log(document.execCommand('print'),'4545');

+ 36 - 33
src/views/supply/pickup/components/design/preview.vue

@@ -2,13 +2,13 @@
   <el-dialog
     :visible.sync="visible"
     :show-close="false"
-    :maskClosable="false"
+    :mask-closable="false"
     :close-on-click-modal="false"
-    @cancel="hideModal"
     :width="350 + 'mm'"
+    @cancel="hideModal"
   >
     <div :spinning="spinning" style="min-height: 100px">
-      <div id="preview_content" ref="printDom"></div>
+      <div id="preview_content" ref="printDom" />
     </div>
     <template slot="title">
       <div>
@@ -18,8 +18,7 @@
           type="primary"
           icon="printer"
           @click.stop="print"
-          >打印</el-button
-        >
+        >打印</el-button>
         <!-- <el-button type="primary" icon="printer" @click.stop="toPdf">pdf</el-button> -->
       </div>
     </template>
@@ -31,7 +30,7 @@
 
 <script>
 export default {
-  name: "printPreview",
+  name: 'PrintPreview',
   props: {},
   data() {
     return {
@@ -43,8 +42,8 @@ export default {
       // 模板
       hiprintTemplate: {},
       // 数据
-      printData: {},
-    };
+      printData: {}
+    }
   },
   computed: {},
   watch: {},
@@ -55,44 +54,48 @@ export default {
     //   downloadPDF(this.$refs.printDom);
     // },
     hideModal() {
-      this.visible = false;
-      this.waitShowPrinter = false;
-      this.$parent.initPrint();
+      this.visible = false
+      this.waitShowPrinter = false
+      this.$parent.initPrint()
       // console.log(this.$parent);
     },
-    show(hiprintTemplate, printData, width = "210") {
-      this.visible = true;
-      this.width = width;
-      this.hiprintTemplate = hiprintTemplate;
-      this.printData = printData;
+    show(hiprintTemplate, printData, width = '210') {
+      this.visible = true
+      this.width = width
+      this.hiprintTemplate = hiprintTemplate
+      this.printData = printData
       setTimeout(() => {
         // eslint-disable-next-line no-undef
-        $("#preview_content").html(hiprintTemplate.getHtml(printData));
-        this.spinning = false;
-      }, 500);
+        $('#preview_content').html(hiprintTemplate.getHtml(printData))
+        this.spinning = false
+      }, 500)
     },
     print() {
       this.hiprintTemplate.print(
         this.printData,
         {},
         {
-          callback: () => {
-            this.$parent.addPrint("getDtailPrintDis");
-            this.hiprintTemplate = {};
-            this.$parent.tableSelection = [];
+          callback: async() => {
+            try {
+              await this.$parent.addPrint('getDtailPrintDis')
+            } catch (e) {
+              console.log('调用打印次数接口失败')
+            }
+            this.hiprintTemplate = {}
+            this.$parent.tableSelection = []
+            await this.$parent.getList()
             setTimeout(() => {
-              this.$parent.getList();
-              console.error("更新发货汇总列表");
-            }, 1000);
-          },
+              console.error('更新发货汇总列表')
+            }, 1000)
+          }
         }
-      );
+      )
       setTimeout(() => {
-        this.hideModal();
-      }, 2000);
-    },
-  },
-};
+        this.hideModal()
+      }, 2000)
+    }
+  }
+}
 </script>
 
 <style scoped>