Просмотр исходного кода

称重打印添加总码单打印功能

lph 1 год назад
Родитель
Сommit
05cb7ba81a

+ 38 - 33
zkqy-ui/src/utils/print/printUtils.js

@@ -1,21 +1,22 @@
 import moment from 'moment'
 
 export function getServerPrintData(printRow) {
+  console.log('printRow', printRow);
   let result = [];
   if (!printRow) {
     return result
   }
   switch (printRow.printFormat) {
-    case 3: //英文码单
+    case '3': //英文码单
       result = printEN(printRow)
       break;
-    case 4: //新思维
+    case '4': //新思维
       result = printCN_XSW(printRow)
       break;
-    case 5: //无净重码单(同4)
+    case '5': //无净重码单(同4)
       result = printCN_WJZ(printRow)
       break;
-    case 6: //总码单
+    case '6': //总码单
       result = printCN_ZMD(printRow)
       break;
   }
@@ -42,13 +43,13 @@ 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
 }
 
@@ -80,17 +81,17 @@ function printCN_XSW(printRow) {
     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 || ' ', })
   res.push({
     key1: '班次',
     key2: workShifts + '    ' + machineTool,
     key3: '日期',
     key4: moment(new Date(productionDate)).format('YYYY-MM-DD')
   })
-  res.push({key1: '毛重', key2: grossWeight, key3: '净重', key4: suttle})
+  res.push({ key1: '毛重', key2: grossWeight, key3: '净重', key4: suttle })
   return res
 }
 
@@ -122,22 +123,23 @@ function printCN_WJZ(printRow) {
     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 || ' ', })
   res.push({
     key1: '班次',
     key2: workShifts + '    ' + machineTool,
     key3: '日期',
     key4: moment(new Date(productionDate)).format('YYYY-MM-DD')
   })
-  res.push({key1: '毛重', key2: grossWeight, key3: '净重', key4: "   "})
+  res.push({ key1: '毛重', key2: grossWeight, key3: '净重', key4: "   " })
   return res
 }
 
 // 总码单
 function printCN_ZMD(printRow) {
+  console.log('总码单', printRow);
   let {
     qrCode,/*序号*/
     machineTool,/*机台*/
@@ -161,19 +163,22 @@ function printCN_ZMD(printRow) {
     directionOfTwistLabel,
     qrCodeData,
     boxNum,/*箱号*/
-    packaging
+    packaging,
+    boxSumNum, /* 箱总数 */
   } = 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: suttle})
+  res.push({ key1: '品种', key2: productName, key3: '规格', key4: productSpecifications })
+  res.push({ key1: '色泽', key2: productColor, key3: '等级', key4: levels })
+  res.push({ key1: '批号', key2: lotNum, key3: '管色', key4: tubeColor })
+  res.push({ key1: '单号', key2: qrCode, key3: '日期', key4: moment(new Date(productionDate)).format('YYYY-MM-DD') })
+  res.push({ key1: '箱数', key2: boxSumNum + '', key3: '筒数', key4: canisterNum })
+  // 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: suttle })
   return res
 }

+ 155 - 69
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,23 +40,31 @@
                 >
                 </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>
+              <el-button
+                :disabled="tableData.length == 0"
+                type="primary"
+                plain
+                size="mini"
+                @click="summeryPrintHandler"
+                >总码单
+              </el-button>
               <div class="weightWrap" v-show="excuteType == 1">
                 <h1>实时重量:{{ nowWeight }}</h1>
               </div>
@@ -129,7 +137,7 @@
                   size="mini"
                   :disabled="chooseState"
                   @click="handleSaveOne(scope.row)"
-                >保存修改
+                  >保存修改
                 </el-button>
                 <el-button
                   v-else-if="excuteType == 3"
@@ -137,7 +145,7 @@
                   size="mini"
                   :disabled="chooseState"
                   @click="handleSuppleOne(scope.row)"
-                >打印
+                  >打印
                 </el-button>
 
                 <el-button
@@ -146,7 +154,7 @@
                   size="mini"
                   :disabled="chooseState"
                   @click="handleDeleteOne(scope.$index, scope.row)"
-                >删除
+                  >删除
                 </el-button>
               </template>
             </el-table-column>
@@ -231,11 +239,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 +500,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 {
@@ -507,6 +515,7 @@ export default {
   ],
   data() {
     return {
+      summertId: "", //总码单id
       qrCode: "", //码单号
       isStartReadNum: false, //是否开始读取重量
       printAuto: true, //是否自动打印
@@ -566,36 +575,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 +723,8 @@ export default {
     },
   },
   mounted() {
-    let {excuteType, qrCode} = this.$route.query;
+    this.summertId = new Date().getTime();
+    let { excuteType, qrCode } = this.$route.query;
     if (excuteType == 2) {
       //修改
       this.handleUpdate(qrCode);
@@ -737,10 +747,70 @@ export default {
   },
 
   methods: {
+    // 总码单打印回调
+    async summeryPrintHandler() {
+      console.log("this.tableData", this.tableData);
+      console.log("this.currentRow", this.currentRow);
+      // return;
+      let payload = { qrCodeVal: "", mapList: [], remark: "无", printType: "" };
+      let firstRowData = JSON.parse(JSON.stringify(this.tableData[0])); //以第一条数据为基础
+      let sumObj = {
+        canisterNum: 0, //筒数
+        grossWeight: 0, //毛重
+        suttle: 0, //净重
+      }; //需要累加的数据
+      this.tableData.forEach((item) => {
+        sumObj.canisterNum += Number(item.canisterNum) || 0;
+        sumObj.grossWeight += Number(item.grossWeight) || 0;
+        sumObj.suttle += Number(item.suttle) || 0;
+      });
+      sumObj.canisterNum = sumObj.canisterNum.toFixed(0);
+      sumObj.grossWeight = sumObj.grossWeight.toFixed(2);
+      sumObj.suttle = sumObj.suttle.toFixed(2);
+      // 添加产品信息
+      sumObj.productName = this.currentRow.productName;
+      sumObj.lotNum = this.currentRow.lotNum;
+      sumObj.productColor = this.currentRow.productColor;
+      sumObj.productColur = this.currentRow.productColor;
+      sumObj.saleProductId = this.currentRow.id;
+      sumObj.productSpecifications = this.currentRow.productSpecifications;
+
+      Object.assign(firstRowData, sumObj);
+      // let timeStemp = new Date().getTime();
+      firstRowData.id = this.summertId;
+      firstRowData.otherStates = 1;
+      firstRowData.printFormat = "6"; //打印类型为总码单
+      firstRowData.boxSumNum = this.tableData.length; //箱子总数
+      firstRowData.machineToolNo = this.lineOptions.find(
+        (item) => item.id == this.form.machineTool
+      ).productionLineNo;
+      this.printTableData = [firstRowData];
+
+      // 保存打印数据
+      let payLoad = {
+        ...firstRowData,
+      };
+      let res = await productCodeList(payLoad);
+      if (res.code !== 200) {
+        this.$message.error("网络异常请稍后再试");
+        return;
+      }
+      let msg = this.isEdit ? "编辑" : "新增";
+      if (res.code == 200) {
+        // 后端打印
+        await this.newPrintHandler();
+        this.tableData = [];
+        this.$message.success(`总码单打印成功!`);
+        // 前端打印
+        // codeListPrint(this.printTableData, "printDom");
+      } else {
+        this.$message.error(`${msg}箱单失败`);
+      }
+    },
     // 接续回调
     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;
@@ -757,8 +827,10 @@ export default {
         if (res.code == 200) {
           console.log(res);
           this.tableData = res.rows;
+
           if (res.rows.length > 0) {
             let lastRow = res.rows[res.rows.length - 1];
+            this.summertId = lastRow.parentCode; //取最后一条数据的总码单code为当前总码单code
             this.qrCode = lastRow.qrCode;
             let {
               packaging,
@@ -802,6 +874,7 @@ export default {
     },
     // 等级改变回调
     async levelChangeHandler() {
+      // return;
       // 等级发生变化,重新获取码单号
       this.tableData = []; //清空打印记录
       let res = await getQrCode();
@@ -924,14 +997,12 @@ 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() {
@@ -1041,7 +1112,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, //箱单号
@@ -1051,21 +1122,40 @@ export default {
         remark, //备注
         printFormat,
         qrCodeId,
+        otherStates,
       } = printRow;
-      let temp = id + "@" + qrCodeId + "@" + canisterNum + "@" + suttle + "@" + grossWeight + "@" + qrCode;
+      let temp =
+        id +
+        "@" +
+        qrCodeId +
+        "@" +
+        canisterNum +
+        "@" +
+        suttle +
+        "@" +
+        grossWeight +
+        "@" +
+        qrCode;
+      if (otherStates == 1) {
+        temp += "@" + 1; //总码单标识
+      }
+      console.log("二维码数据", temp);
       payload.qrCodeVal = temp;
       payload.remark = remark || "注:不同批号,请勿混用";
       payload.mapList = getServerPrintData(printRow);
       switch (printFormat) {
-        case 3: //英文码单
-          payload.printType = "normal";
-          break;
-        case 4: //新思维
+        case "3": //英文码单
           payload.printType = "export";
           break;
-        case 5: //无净重码单(同3)
+        case "4": //新思维
           payload.printType = "normal";
           break;
+        case "5": //无净重码单(同3)
+          payload.printType = "normal";
+          break;
+        case "6": //总码单
+          payload.printType = "assembleNormal";
+          break;
       }
       try {
         let res = await AutoPrinting(payload);
@@ -1092,7 +1182,7 @@ export default {
     },
     // 毛重改变回调
     changeGrossWeight(row) {
-      let {boxWeight, grossWeight, canisterWeight, canisterNum} = row;
+      let { boxWeight, grossWeight, canisterWeight, canisterNum } = row;
       if (!Number(grossWeight)) {
         row.suttle = 0;
         return;
@@ -1121,7 +1211,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));
 
@@ -1150,8 +1240,7 @@ export default {
         } else {
           this.$message.error(`${msg}失败`);
         }
-      } catch (error) {
-      }
+      } catch (error) {}
     },
     // 确认打印回调
     printConfirmHandler(printData) {
@@ -1165,13 +1254,13 @@ export default {
       });
       this.changeGrossWeight(this.printTableData[0]);
       // 前端打印
-      codeListPrint(this.printTableData, "printDom");
+      // codeListPrint(this.printTableData, "printDom");
 
-      if (this.excuteType == 1) {
-        this.tableData.push(this.printTableData[0]);
-      }
+      // if (this.excuteType == 1) {
+      //   this.tableData.push(this.printTableData[0]);
+      // }
       // 后端打印
-      // this.newPrintHandler();
+      this.newPrintHandler();
     },
     // 获取机台选项数据
     async getLineOptionLsit() {
@@ -1188,8 +1277,7 @@ export default {
           }
         } else {
         }
-      } catch (error) {
-      }
+      } catch (error) {}
     },
     // 补码打印回调
     handleSuppleOne(row) {
@@ -1202,7 +1290,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))
@@ -1213,12 +1301,12 @@ export default {
             // 先打印
             this.changeGrossWeight(this.printTableData[0]);
             // 后端打印
-            // await this.newPrintHandler();
+            await this.newPrintHandler();
             // 前端打印
-            codeListPrint(this.printTableData, "printDom");
-            if (this.excuteType == 1) {
-              this.tableData.push(this.printTableData[0]);
-            }
+            // codeListPrint(this.printTableData, "printDom");
+            // if (this.excuteType == 1) {
+            //   this.tableData.push(this.printTableData[0]);
+            // }
             // 后保存数据
             let payLoad = {
               ...this.form,
@@ -1235,6 +1323,10 @@ export default {
               productCodeListInfoList: this.tableData,
               productColour: rowData.productColor,
               saleProductId: this.currentRow.id,
+              // 总码单相关数据  start
+              otherStates: 0,
+              parentCode: this.summertId,
+              // 总码单相关数据  end
             };
             if (rowData.id) {
               payLoad.id = rowData.id;
@@ -1264,8 +1356,7 @@ export default {
             } else {
               this.$message.error(`${msg}箱单失败`);
             }
-          } catch (error) {
-          }
+          } catch (error) {}
         }
       });
     },
@@ -1274,7 +1365,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];
@@ -1303,8 +1394,7 @@ export default {
             } else {
               this.$message.error(`${msg}箱单失败`);
             }
-          } catch (error) {
-          }
+          } catch (error) {}
         }
       });
     },
@@ -1414,7 +1504,7 @@ export default {
     },
     // 计算净重
     getSuttle() {
-      let {boxWeight, canisterWeight, canisterNum} = this.form;
+      let { boxWeight, canisterWeight, canisterNum } = this.form;
       return (Number(boxWeight) - canisterWeight * canisterNum).toFixed(2);
     },
     // 表格点击回调
@@ -1455,7 +1545,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];
@@ -1499,8 +1589,7 @@ export default {
                   } else {
                     this.$message.error(`${msg}箱单失败`);
                   }
-                } catch (error) {
-                }
+                } catch (error) {}
               }
             });
           }
@@ -1510,15 +1599,14 @@ 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,8 +1656,7 @@ export default {
         } else {
           this.$message.error("网络异常!");
         }
-      } catch (error) {
-      }
+      } catch (error) {}
     },
     /** 查询产品码单列表 */
     getList() {
@@ -1774,8 +1861,7 @@ export default {
           this.getList();
           this.$modal.msgSuccess("删除成功");
         })
-        .catch(() => {
-        });
+        .catch(() => {});
     },
     /** 导出按钮操作 */
     handleExport() {