Преглед изворни кода

修改码单管理自动打印和手动打印逻辑/暂时切换到前端打印

lph пре 1 година
родитељ
комит
b2c53c95b0

+ 30 - 22
zkqy-ui/src/utils/print/codeListPrint.js

@@ -58,43 +58,51 @@ function codeListPrint(data, domId) {
       // let qrCodeData = '123456';
       // let temp = id + '@' + uuid + '@' + canisterNum + '@' + suttle + '@' + grossWeight + '@' + lotNum + '@' + productName + '@' + productSpecifications + '@' + productColor + '@' + levels + '@' + qrCode + '@' + boxNum
       let temp = id + '@' + uuid + '@' + canisterNum + '@' + suttle + '@' + grossWeight + '@' + qrCode
-      let resStr = encodeURIComponent(temp)
+      // let resStr = encodeURIComponent(temp)
       if (printFormat == 3) {//打印英文版
         uuidList.push({
           id: uuid + '' + theNumber,
-          qrCodeData: resStr,//id uuid 筒数 净重 毛重 批次 品种 规格 色号 等级 码单号 箱号 
+          qrCodeData: temp,//id uuid 筒数 净重 毛重 批次 品种 规格 色号 等级 码单号 箱号 
           size: 180,
         })
         res = printEN(uuid + '' + theNumber, item, res)
       } else {//打印中文版
         uuidList.push({
           id: uuid + '' + theNumber,
-          qrCodeData: resStr,//id uuid 筒数 净重 毛重 批次 品种 规格 色号 等级 码单号 箱号
+          qrCodeData: temp,//id uuid 筒数 净重 毛重 批次 品种 规格 色号 等级 码单号 箱号
           size: 120,
         })
         res = printCN(uuid + '' + theNumber, item, res) + endHtml;
       }
     }
   }
-  var printWindow = window.open('', '_blank', 'height=500,width=800');
-  printWindow.document.write('<html><head><title>Print Element</title>');
-  printWindow.document.write('</head><body >');
-  printWindow.document.write(res);
-  printWindow.document.write('</body></html>');
-  // printWindow.document.close();
-  // printWindow.document.body.innerHTML = document.getElementById(domId).innerHTML = res;
-  for (var i = 0; i < uuidList.length; i++) {
-    let data = uuidList[i]
-    new QRCode(printWindow.document.getElementById("" + data.id), {
-      text: sleep(2) + data.qrCodeData,
-      width: data.size,
-      height: data.size,
-      colorDark: "#000000",
-      colorLight: "#ffffff",
-      correctLevel: QRCode.CorrectLevel.H,
-    });
-  }
-  printWindow.print();//打印
+  setTimeout(function () {
+    var printWindow = window.open('', '_blank', 'height=500,width=800');
+    console.log(printWindow);
+    if (printWindow == null) {
+      console.log('弹出窗口被阻止');
+      return
+      // 在这里处理弹出被阻止的情况
+    }
+    printWindow.document.write('<html><head><title>Print Element</title>');
+    printWindow.document.write('</head><body >');
+    printWindow.document.write(res);
+    printWindow.document.write('</body></html>');
+    // printWindow.document.close();
+    // printWindow.document.body.innerHTML = document.getElementById(domId).innerHTML = res;
+    for (var i = 0; i < uuidList.length; i++) {
+      let data = uuidList[i]
+      new QRCode(printWindow.document.getElementById("" + data.id), {
+        text: sleep(2) + data.qrCodeData,
+        width: data.size,
+        height: data.size,
+        colorDark: "#000000",
+        colorLight: "#ffffff",
+        correctLevel: QRCode.CorrectLevel.H,
+      });
+    }
+    printWindow.print();//打印
+  }, 100)
   // window.location.reload();
   return false;
 }

+ 65 - 18
zkqy-ui/src/views/orderMange/codeListManage/index.vue

@@ -317,7 +317,7 @@
                     @click="updateOrderData"
                     >保存修改
                   </el-button>
-                  <el-button
+                  <!-- <el-button
                     :disabled="tableData.length != 1"
                     type="primary"
                     size="mini"
@@ -331,7 +331,7 @@
                     size="mini"
                     @click="chooseOneToPrint"
                     >{{ chooseState ? "退出批箱单" : "批箱单" }}
-                  </el-button>
+                  </el-button> -->
                   <el-switch
                     class="ml10 mr10"
                     v-model="printAuto"
@@ -342,6 +342,13 @@
                   <el-button type="primary" size="mini" @click="readStateChange"
                     >{{ isStartReadNum ? "停止读数" : "开始读数" }}
                   </el-button>
+                  <el-button
+                    v-show="!printAuto"
+                    type="success"
+                    size="mini"
+                    @click="printBtnHandler"
+                    >打印
+                  </el-button>
                 </div>
                 <div class="weightWrap">
                   <h1>实时重量:{{ nowWeight }}</h1>
@@ -395,7 +402,7 @@
                 label="筒数"
               ></el-table-column>
               <el-table-column prop="grossWeight" label="毛重">
-                <template slot-scope="scope">
+                <!-- <template slot-scope="scope">
                   <el-input
                     :disabled="excuteType == 3"
                     v-model="scope.row.grossWeight"
@@ -403,7 +410,7 @@
                     size="mini"
                     clearable
                   ></el-input>
-                </template>
+                </template> -->
               </el-table-column>
               <el-table-column prop="suttle" label="净重"></el-table-column>
               <el-table-column prop="workShifts" label="班次"></el-table-column>
@@ -465,7 +472,7 @@
                 label-width="80px"
                 :inline="false"
                 size="normal"
-                :disabled="isDisabled"
+                :disabled="isDisabled || isStartReadNum"
               >
                 <el-col :span="8">
                   <el-form-item prop="packaging" label="包装">
@@ -697,7 +704,7 @@
                 clearable
                 @input="batchNumChange"
                 @keyup.enter.native="batchNumChange"
-                :disabled="isDisabled"
+                :disabled="isDisabled || isStartReadNum"
               ></el-input>
               <el-button
                 class="ml10"
@@ -710,6 +717,7 @@
             </div>
             <div class="table-wrap">
               <el-table
+                ref="proTableRef"
                 :data="batchTableData"
                 border
                 stripe
@@ -718,6 +726,11 @@
                 highlight-current-row
                 @current-change="handleCurrentChange"
               >
+                <!-- <el-table-column
+                  type="index"
+                  label="序号"
+                  width="50"
+                ></el-table-column> -->
                 <el-table-column
                   v-for="col in columns"
                   :prop="col.id"
@@ -770,6 +783,7 @@ export default {
   ],
   data() {
     return {
+      qrCode: "", //码单号
       isStartReadNum: false, //是否开始读取重量
       printAuto: true, //是否自动打印
       timer: null, //定时器
@@ -965,13 +979,27 @@ export default {
   },
 
   methods: {
-    readStateChange() {
+    // 打印按钮回调
+    async printBtnHandler() {
+      let res = await this.validateAndPrint();
+      if (!res) {
+        this.$message.error("请完善数据");
+      }
+    },
+    async readStateChange() {
       if (this.isStartReadNum) {
         //正在读
         this.closeWebSocket();
         this.isStartReadNum = false;
         this.$message.success("已关闭读数");
       } else {
+        // 开启读数时 先获取码单号
+        let res = await getQrCode();
+        if (res.code == 200) {
+          this.qrCode = res.msg;
+        } else {
+          this.$message.error(res.msg);
+        }
         this.initWebSocket();
       }
     },
@@ -1091,17 +1119,11 @@ export default {
       let directionOfTwistLabel = this.dict.type.direction_of_twist.find(
         (item) => item.value == directionOfTwist
       )?.label;
-      let res = await getQrCode();
-      let qrCode = "";
-      if (res.code == 200) {
-        qrCode = res.msg;
-      } else {
-        this.$message.error(res.msg);
-      }
+
       newData = {
         // qrCode: this.getBoxOrderNum(), //箱单号
         packaging, //包装方式 1:车丝 2:小包装  3:大包装
-        qrCode, //箱单号
+        qrCode: this.qrCode, //箱单号
         levels,
         machineTool,
         boxWeight,
@@ -1191,6 +1213,7 @@ export default {
         if (res.code == 200 && res.status == "success") {
           this.$message.success(res.msg);
           if (this.excuteType == 1 && this.printAuto) {
+            this.changeGrossWeight(printRow);
             this.tableData.push(printRow);
           }
         } else {
@@ -1220,6 +1243,7 @@ export default {
         Number(boxWeight) -
         Number(canisterWeight) * Number(canisterNum)
       ).toFixed(2);
+      console.log(row);
     },
     // 删除表格一条数据回调
     handleDeleteOne(index) {
@@ -1237,10 +1261,10 @@ export default {
         item.qrCodeData = printData + "-" + item.boxNum;
       });
       // 前端打印
-      // codeListPrint(this.printTableData, "printDom");
+      codeListPrint(this.printTableData, "printDom");
       // 后端打印
       console.log("newPrintHandler");
-      this.newPrintHandler();
+      // this.newPrintHandler();
     },
     // 获取机台选项数据
     async getLineOptionLsit() {
@@ -1470,7 +1494,30 @@ export default {
     // 表格点击回调
     async handleCurrentChange(val) {
       console.log("row", val);
-      this.currentRow = JSON.parse(JSON.stringify(val));
+      if (!val) return;
+      if (this.isStartReadNum) {
+        this.$refs.proTableRef.setCurrentRow(this.currentRow);
+        return;
+      }
+      if (val.id != this.currentRow.id) {
+        this.tableData = [];
+        // this.$refs.form.resetFields();
+        this.nowWeight = 0;
+        if (!this.printAuto) {
+          // 手动打印  获取码单号
+          this.getQrCodeHandle();
+        }
+      }
+      this.currentRow = val;
+    },
+    // 获取码单号
+    async getQrCodeHandle() {
+      let res = await getQrCode();
+      if (res.code == 200) {
+        this.qrCode = res.msg;
+      } else {
+        this.$message.error(res.msg);
+      }
     },
     // 选择打印数据回调
     handlePrintOneChange(row) {