Эх сурвалжийг харах

feat:前端打印模版数据、优化前端调用打印逻辑、无净重、总码单模版等

韩帛霖 1 жил өмнө
parent
commit
7192ee4612

+ 133 - 84
zkqy-ui/src/utils/print/printUtils.js

@@ -1,22 +1,33 @@
 import moment from 'moment'
 
 export function getServerPrintData(printRow) {
-  let {
-    printFormat, //格式 //备注
-  } = printRow;
   let result = [];
-  if (printFormat == 3) {//英文版
-    result = printEN(printRow)
-  } else {
-    result = printCN(printRow)
+  if (!printRow) {
+    return result
+  }
+  switch (printRow.printFormat) {
+    case 3: //英文码单
+      result = printEN(printRow)
+      break;
+    case 4: //新思维
+      result = printCN_XSW(printRow)
+      break;
+    case 5: //无净重码单(同4)
+      result = printCN_WJZ(printRow)
+      break;
+    case 6: //总码单
+      result = printCN_ZMD(printRow)
+      break;
   }
   return result
 
 }
+
 function removeChineseCharacters(str) {
   return str.replace(/[\u4e00-\u9fa5]/g, '');
 }
 
+// 英文码单
 function printEN(printRow) {
   let {
     id, //id
@@ -31,100 +42,138 @@ function printEN(printRow) {
   } = printRow;
   let ENColor = removeChineseCharacters(productColor) || ''
   let res = []
-  res.push({
-    key1: 'GRADE:',
-    key2: productSpecifications,
-  })
-  res.push({
-    key1: 'LOT NO:',
-    key2: qrCode,
-  })
-  res.push({
-    key1: 'COLOR NO:',
-    key2: ENColor + '    ' + lotNum,
-  })
-  res.push({
-    key1: 'CONE NO:',
-    key2: canisterNum,
-  })
-  res.push({
-    key1: 'NET WEIGHT:',
-    key2: suttle,
-  })
-  res.push({
-    key1: 'GROSS WEIGHT:',
-    key2: grossWeight,
-  })
-  res.push({
-    key1: 'CARTON NO:',
-    key2: boxNum,
-  })
+  res.push({key1: 'GRADE:', key2: productSpecifications,})
+  res.push({key1: 'LOT NO:', key2: qrCode,})
+  res.push({key1: 'COLOR NO:', key2: ENColor + '    ' + lotNum,})
+  res.push({key1: 'CONE NO:', key2: canisterNum,})
+  res.push({key1: 'NET WEIGHT:', key2: suttle,})
+  res.push({key1: 'GROSS WEIGHT:', key2: grossWeight,})
+  res.push({key1: 'CARTON NO:', key2: boxNum,})
   return res
 }
 
-function printCN(printRow) {
+// 新思维码单
+function printCN_XSW(printRow) {
   let {
-    qrCode,//序号
-    machineTool,//机台
-    boxWeight,//箱重-车重
-    canisterweight,//筒重
-    canisterNum,//筒数
-    grossWeight,//毛重
-    suttle,//净重
-    workShifts,//班次
-    tubeColor,//管色
-    boxOrderNum, //生成的随机码
-    myNO,//箱号
-    productionDate, //日期
-    printFormat, //格式
-    productName, //产品名
-    productSpecifications, //规格
-    productColor, //色泽
-    lotNum, //批次
-    levels,//等级
-    directionOfTwist,//捻向
+    qrCode,/*序号*/
+    machineTool,/*机台*/
+    boxWeight,/*箱重-车重*/
+    canisterweight,/*筒重*/
+    canisterNum,/*筒数*/
+    grossWeight,/*毛重*/
+    suttle,/*净重*/
+    workShifts,/*班次*/
+    tubeColor,/*管色*/
+    boxOrderNum, /*生成的随机码*/
+    myNO,/*箱号*/
+    productionDate, /*日期*/
+    printFormat, /*格式*/
+    productName, /*产品名*/
+    productSpecifications, /*规格*/
+    productColor, /*色泽*/
+    lotNum, /*批次*/
+    levels,/*等级*/
+    directionOfTwist,/*捻向*/
     directionOfTwistLabel,
     qrCodeData,
-    boxNum,//箱号
+    boxNum,/*箱号*/
     packaging
   } = printRow;
   let res = [];
+  res.push({key1: '品种', key2: productName, key3: '规格', key4: productSpecifications})
+  res.push({key1: '批号', key2: lotNum, key3: '色号', key4: productColor})
+  res.push({key1: '等级', key2: levels, key3: '箱号', key4: qrCode, key5: boxNum})
+  res.push({key1: '筒数', key2: canisterNum + '    ' + tubeColor, key3: '捻向', key4: directionOfTwistLabel || ' ',})
   res.push({
-    key1: '品种',
-    key2: productName,
-    key3: '规格',
-    key4: productSpecifications
-  })
-  res.push({
-    key1: '批号',
-    key2: lotNum,
-    key3: '色号',
-    key4: productColor
-  })
-  res.push({
-    key1: '等级',
-    key2: levels,
-    key3: '箱号',
-    key4: qrCode,
-    key5: boxNum
-  })
-  res.push({
-    key1: '筒数',
-    key2: canisterNum + '    ' + tubeColor,
-    key3: '捻向',
-    key4: directionOfTwistLabel || ' ',
+    key1: '班次',
+    key2: workShifts + '    ' + machineTool,
+    key3: '日期',
+    key4: moment(new Date(productionDate)).format('YYYY-MM-DD')
   })
+  res.push({key1: '毛重', key2: grossWeight, key3: '净重', key4: suttle})
+  return res
+}
+
+// 无净重码单
+function printCN_WJZ(printRow) {
+  let {
+    qrCode,/*序号*/
+    machineTool,/*机台*/
+    boxWeight,/*箱重-车重*/
+    canisterweight,/*筒重*/
+    canisterNum,/*筒数*/
+    grossWeight,/*毛重*/
+    suttle,/*净重*/
+    workShifts,/*班次*/
+    tubeColor,/*管色*/
+    boxOrderNum, /*生成的随机码*/
+    myNO,/*箱号*/
+    productionDate, /*日期*/
+    printFormat, /*格式*/
+    productName, /*产品名*/
+    productSpecifications, /*规格*/
+    productColor, /*色泽*/
+    lotNum, /*批次*/
+    levels,/*等级*/
+    directionOfTwist,/*捻向*/
+    directionOfTwistLabel,
+    qrCodeData,
+    boxNum,/*箱号*/
+    packaging
+  } = printRow;
+  let res = [];
+  res.push({key1: '品种', key2: productName, key3: '规格', key4: productSpecifications})
+  res.push({key1: '批号', key2: lotNum, key3: '色号', key4: productColor})
+  res.push({key1: '等级', key2: levels, key3: '箱号', key4: qrCode, key5: boxNum})
+  res.push({key1: '筒数', key2: canisterNum + '    ' + tubeColor, key3: '捻向', key4: directionOfTwistLabel || ' ',})
   res.push({
     key1: '班次',
     key2: workShifts + '    ' + machineTool,
     key3: '日期',
     key4: moment(new Date(productionDate)).format('YYYY-MM-DD')
   })
+  res.push({key1: '毛重', key2: grossWeight, key3: '净重', key4: "   "})
+  return res
+}
+
+// 总码单
+function printCN_ZMD(printRow) {
+  let {
+    qrCode,/*序号*/
+    machineTool,/*机台*/
+    boxWeight,/*箱重-车重*/
+    canisterweight,/*筒重*/
+    canisterNum,/*筒数*/
+    grossWeight,/*毛重*/
+    suttle,/*净重*/
+    workShifts,/*班次*/
+    tubeColor,/*管色*/
+    boxOrderNum, /*生成的随机码*/
+    myNO,/*箱号*/
+    productionDate, /*日期*/
+    printFormat, /*格式*/
+    productName, /*产品名*/
+    productSpecifications, /*规格*/
+    productColor, /*色泽*/
+    lotNum, /*批次*/
+    levels,/*等级*/
+    directionOfTwist,/*捻向*/
+    directionOfTwistLabel,
+    qrCodeData,
+    boxNum,/*箱号*/
+    packaging
+  } = printRow;
+  let res = [];
+  res.push({key1: '品种', key2: productName, key3: '规格', key4: productSpecifications})
+  res.push({key1: '批号', key2: lotNum, key3: '色号', key4: productColor})
+  res.push({key1: '等级', key2: levels, key3: '箱号', key4: qrCode, key5: boxNum})
+  res.push({key1: '筒数', key2: canisterNum + '    ' + tubeColor, key3: '捻向', key4: directionOfTwistLabel || ' ',})
   res.push({
-    key1: '毛重',
-    key2: grossWeight,
-    key3: '净重',
-    key4: suttle
+    key1: '班次',
+    key2: workShifts + '    ' + machineTool,
+    key3: '日期',
+    key4: moment(new Date(productionDate)).format('YYYY-MM-DD')
   })
+  res.push({key1: '毛重', key2: grossWeight, key3: '净重', key4: suttle})
   return res
-}
+}

+ 65 - 63
zkqy-ui/src/views/orderMange/codeListManage/printIndex.vue

@@ -15,7 +15,7 @@
                   type="primary"
                   size="mini"
                   @click="updateOrderData"
-                  >保存修改
+                >保存修改
                 </el-button>
                 <!-- <el-button
                     :disabled="tableData.length != 1"
@@ -40,21 +40,21 @@
                 >
                 </el-switch>
                 <el-button type="primary" size="mini" @click="readStateChange"
-                  >{{ isStartReadNum ? "停止读数" : "开始读数" }}
+                >{{ isStartReadNum ? "停止读数" : "开始读数" }}
                 </el-button>
                 <el-button
                   v-show="!printAuto"
                   type="success"
                   size="mini"
                   @click="printBtnHandler"
-                  >打 印
+                >打 印
                 </el-button>
                 <el-button
                   type="info"
                   plain
                   size="mini"
                   @click="continuePrintHandler"
-                  >接 续
+                >接 续
                 </el-button>
               </div>
               <div class="weightWrap" v-show="excuteType == 1">
@@ -129,7 +129,7 @@
                   size="mini"
                   :disabled="chooseState"
                   @click="handleSaveOne(scope.row)"
-                  >保存修改
+                >保存修改
                 </el-button>
                 <el-button
                   v-else-if="excuteType == 3"
@@ -137,7 +137,7 @@
                   size="mini"
                   :disabled="chooseState"
                   @click="handleSuppleOne(scope.row)"
-                  >打印
+                >打印
                 </el-button>
 
                 <el-button
@@ -146,7 +146,7 @@
                   size="mini"
                   :disabled="chooseState"
                   @click="handleDeleteOne(scope.$index, scope.row)"
-                  >删除
+                >删除
                 </el-button>
               </template>
             </el-table-column>
@@ -231,11 +231,11 @@
                       :value="item.id"
                     >
                       <span class="discribe" style="float: left">{{
-                        item.productionLineName
-                      }}</span>
+                          item.productionLineName
+                        }}</span>
                       <span
                         style="float: right; color: #8492a6; font-size: 13px"
-                        >{{ item.productionLineDepartment }}</span
+                      >{{ item.productionLineDepartment }}</span
                       >
                     </el-option>
                   </el-select>
@@ -492,8 +492,8 @@ import {
   listBySaleProductID,
 } from "@/api/codeListManage/productCodeList";
 import codeListPrint from "@/utils/print/codeListPrint";
-import { getServerPrintData } from "@/utils/print/printUtils";
-import { v4 as uuidv4 } from "uuid";
+import {getServerPrintData} from "@/utils/print/printUtils";
+import {v4 as uuidv4} from "uuid";
 import moment from "moment";
 
 export default {
@@ -566,36 +566,36 @@ export default {
       },
       rules: {
         grossWeight: [
-          { required: true, message: "请输入重量", trigger: "change" },
+          {required: true, message: "请输入重量", trigger: "change"},
         ],
         packaging: [
-          { required: true, message: "请选择包装", trigger: "change" },
+          {required: true, message: "请选择包装", trigger: "change"},
         ],
         machineTool: [
-          { required: true, message: "请选择机台", trigger: "change" },
+          {required: true, message: "请选择机台", trigger: "change"},
         ],
         workShifts: [
-          { required: true, message: "请选择班次", trigger: "change" },
+          {required: true, message: "请选择班次", trigger: "change"},
         ],
         productionDate: [
-          { required: true, message: "请选择生产日期", trigger: "change" },
+          {required: true, message: "请选择生产日期", trigger: "change"},
         ],
-        levels: [{ required: true, message: "请选择等级", trigger: "change" }],
+        levels: [{required: true, message: "请选择等级", trigger: "change"}],
         // foreignTradeNumber: [
         //   { required: true, message: "请输入外贸号", trigger: "blur" },
         // ],
         canisterWeight: [
-          { required: true, message: "请选择筒重", trigger: "change" },
+          {required: true, message: "请选择筒重", trigger: "change"},
         ],
         boxWeight: [
-          { required: true, message: "请选择箱重/车重", trigger: "change" },
+          {required: true, message: "请选择箱重/车重", trigger: "change"},
         ],
         tubeColor: [
-          { required: true, message: "请选择管色", trigger: "change" },
+          {required: true, message: "请选择管色", trigger: "change"},
         ],
-        comPort: [{ required: true, message: "请选择端口", trigger: "change" }],
+        comPort: [{required: true, message: "请选择端口", trigger: "change"}],
         printFormat: [
-          { required: true, message: "请选择格式", trigger: "change" },
+          {required: true, message: "请选择格式", trigger: "change"},
         ],
       },
       dropDownData: {},
@@ -714,7 +714,7 @@ export default {
     },
   },
   mounted() {
-    let { excuteType, qrCode } = this.$route.query;
+    let {excuteType, qrCode} = this.$route.query;
     if (excuteType == 2) {
       //修改
       this.handleUpdate(qrCode);
@@ -740,7 +740,7 @@ export default {
     // 接续回调
     async continuePrintHandler() {
       try {
-        let { machineTool, workShifts, levels } = this.form;
+        let {machineTool, workShifts, levels} = this.form;
         if (!this.currentRow || !this.currentRow.lotNum) {
           this.$message.error("请选择产品");
           return;
@@ -924,12 +924,14 @@ export default {
         }
       });
 
-      this.websocket.addEventListener("on", (e) => {});
+      this.websocket.addEventListener("on", (e) => {
+      });
       this.websocket.addEventListener("error", (event) => {
         this.$message.error("WebSocket错误,请重试");
       });
 
-      this.websocket.addEventListener("close", () => {});
+      this.websocket.addEventListener("close", () => {
+      });
     },
     // 用于重置与重量相关的状态
     resetWeightStatus() {
@@ -1039,12 +1041,7 @@ export default {
     // 新的后端打印逻辑
     async newPrintHandler() {
       let printRow = this.printTableData[0];
-      let payload = {
-        qrCodeVal: "",
-        mapList: [],
-        remark: "无",
-        printType: "",
-      };
+      let payload = {qrCodeVal: "", mapList: [], remark: "无", printType: "",};
       let {
         id, //id
         qrCode, //箱单号
@@ -1055,24 +1052,21 @@ export default {
         printFormat,
         qrCodeId,
       } = printRow;
-      let uuid = uuidv4();
-      let temp =
-        id +
-        "@" +
-        qrCodeId +
-        "@" +
-        canisterNum +
-        "@" +
-        suttle +
-        "@" +
-        grossWeight +
-        "@" +
-        qrCode;
-      // payload.qrCodeVal = encodeURIComponent(temp);
+      let temp = id + "@" + qrCodeId + "@" + canisterNum + "@" + suttle + "@" + grossWeight + "@" + qrCode;
       payload.qrCodeVal = temp;
       payload.remark = remark || "注:不同批号,请勿混用";
       payload.mapList = getServerPrintData(printRow);
-      payload.printType = printFormat == 3 ? "export" : "normal";
+      switch (printFormat) {
+        case 3: //英文码单
+          payload.printType = "normal";
+          break;
+        case 4: //新思维
+          payload.printType = "export";
+          break;
+        case 5: //无净重码单(同3)
+          payload.printType = "normal";
+          break;
+      }
       try {
         let res = await AutoPrinting(payload);
         if (res.code == 200 && res.status == "success") {
@@ -1098,7 +1092,7 @@ export default {
     },
     // 毛重改变回调
     changeGrossWeight(row) {
-      let { boxWeight, grossWeight, canisterWeight, canisterNum } = row;
+      let {boxWeight, grossWeight, canisterWeight, canisterNum} = row;
       if (!Number(grossWeight)) {
         row.suttle = 0;
         return;
@@ -1127,7 +1121,7 @@ export default {
     // 确认保存修改一条数据
     async handleSaveOne(row) {
       try {
-        let { sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight } =
+        let {sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight} =
           this.count;
         let rowData = JSON.parse(JSON.stringify(row));
 
@@ -1156,7 +1150,8 @@ export default {
         } else {
           this.$message.error(`${msg}失败`);
         }
-      } catch (error) {}
+      } catch (error) {
+      }
     },
     // 确认打印回调
     printConfirmHandler(printData) {
@@ -1193,7 +1188,8 @@ export default {
           }
         } else {
         }
-      } catch (error) {}
+      } catch (error) {
+      }
     },
     // 补码打印回调
     handleSuppleOne(row) {
@@ -1206,7 +1202,7 @@ export default {
       this.$refs.form.validate(async (valid) => {
         if (valid) {
           try {
-            let { sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight } =
+            let {sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight} =
               this.count;
             let rowData = newData.machineTool
               ? JSON.parse(JSON.stringify(newData))
@@ -1268,7 +1264,8 @@ export default {
             } else {
               this.$message.error(`${msg}箱单失败`);
             }
-          } catch (error) {}
+          } catch (error) {
+          }
         }
       });
     },
@@ -1277,7 +1274,7 @@ export default {
       this.$refs.form.validate(async (valid) => {
         if (valid) {
           try {
-            let { sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight } =
+            let {sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight} =
               this.count;
             let rowData = JSON.parse(JSON.stringify(this.tableData[0]));
             this.printTableData = [rowData];
@@ -1306,7 +1303,8 @@ export default {
             } else {
               this.$message.error(`${msg}箱单失败`);
             }
-          } catch (error) {}
+          } catch (error) {
+          }
         }
       });
     },
@@ -1416,7 +1414,7 @@ export default {
     },
     // 计算净重
     getSuttle() {
-      let { boxWeight, canisterWeight, canisterNum } = this.form;
+      let {boxWeight, canisterWeight, canisterNum} = this.form;
       return (Number(boxWeight) - canisterWeight * canisterNum).toFixed(2);
     },
     // 表格点击回调
@@ -1457,7 +1455,7 @@ export default {
             this.$refs.form.validate(async (valid) => {
               if (valid) {
                 try {
-                  let { sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight } =
+                  let {sumBoxNum, sumCanisterNum, sumSuttle, sumGrossWeight} =
                     this.count;
                   let rowData = JSON.parse(JSON.stringify(row));
                   this.printTableData = [rowData];
@@ -1501,7 +1499,8 @@ export default {
                   } else {
                     this.$message.error(`${msg}箱单失败`);
                   }
-                } catch (error) {}
+                } catch (error) {
+                }
               }
             });
           }
@@ -1511,14 +1510,15 @@ export default {
     // 获取所有批次数据
     async getAllBatchData(id) {
       try {
-        let payload = { machineTool: id };
+        let payload = {machineTool: id};
         let res = await finishedProductList(payload);
         if (res.code == 200) {
           this.batchData = res.data;
           this.batchTableData = res.data;
         } else {
         }
-      } catch (error) {}
+      } catch (error) {
+      }
     },
     // 批号查询接口
     batchNumChange() {
@@ -1568,7 +1568,8 @@ export default {
         } else {
           this.$message.error("网络异常!");
         }
-      } catch (error) {}
+      } catch (error) {
+      }
     },
     /** 查询产品码单列表 */
     getList() {
@@ -1773,7 +1774,8 @@ export default {
           this.getList();
           this.$modal.msgSuccess("删除成功");
         })
-        .catch(() => {});
+        .catch(() => {
+        });
     },
     /** 导出按钮操作 */
     handleExport() {