lxf 1 year ago
parent
commit
bd4180f769

+ 1 - 1
src/views/production/express-delivery/network-location/index.vue

@@ -196,7 +196,7 @@ const formConfig = computed(() => {
     },
     {
       type: "input",
-      prop: "name",
+      prop: "phone",
       label: "电话",
       itemType: "text",
     },

+ 93 - 12
src/views/production/shipment/print-order/index.vue

@@ -445,6 +445,7 @@ const getDemandData = () => {
     if (res.rows && res.rows.length > 0) {
       expressDeliveryList.value = res.rows.map((item) => {
         return {
+          ...item,
           dictKey: item.id,
           dictValue: item.expressage,
         };
@@ -729,17 +730,6 @@ const submitExpress = () => {
     }
   });
 };
-const ws = ref("");
-const initWebSocket = (status, request) => {
-  ws.value = new WebSocket("ws://localhost:13528");
-  ws.value.onopen = (e) => {
-    console.log("建立连接", e);
-    if (status) {
-      this.send(request);
-    }
-  };
-};
-initWebSocket();
 const openPrint = ref(false);
 const orderEncasementList = ref([]);
 const clickPrint = () => {
@@ -759,9 +749,100 @@ const getAssemblyDetail = () => {
     orderEncasementList.value = res.orderEncasementList;
   });
 };
+const ws = ref("");
+const initWebSocket = (status, request) => {
+  ws.value = new WebSocket("ws://localhost:13528");
+  ws.value.onopen = (e) => {
+    console.log("建立连接", e);
+    if (status) {
+      send(request);
+    }
+  };
+};
+initWebSocket();
+const send = (request) => {
+  ws.value.send(JSON.stringify(request));
+};
+const getUUID = (len, radix) => {
+  var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
+  var uuid = [],
+    i;
+  radix = radix || chars.length;
+  if (len) {
+    for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
+  } else {
+    var r;
+    uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
+    uuid[14] = "4";
+    for (i = 0; i < 36; i++) {
+      if (!uuid[i]) {
+        r = 0 | (Math.random() * 16);
+        uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
+      }
+    }
+  }
+  return uuid.join("");
+};
+const getRequestObject = (cmd = "print") => {
+  var request = new Object();
+  request.requestID = getUUID(8, 16);
+  request.version = "1.0";
+  request.cmd = cmd;
+  return request;
+};
 const clickNewbiePrint = (row) => {
+  if (selectData.value[0].expressDeliveryId) {
+    let printer = "";
+    let list = expressDeliveryList.value.filter((item) => item.id === selectData.value[0].expressDeliveryId);
+    if (list && list.length > 0) {
+      if (list[0].printer) {
+        printer = list[0].printer;
+      } else {
+        return ElMessage("该快递网点暂未设置打印机");
+      }
+    }
+  } else {
+    return ElMessage("请先设置快递");
+  }
   proxy.post("/cainiao/takeNum", { id: row.id }).then((res) => {
-    console.log(res);
+    let request = getRequestObject();
+    request.task = new Object();
+    request.task.taskID = getUUID(8, 10);
+    request.task.preview = false;
+    request.task.printer = printer;
+    let documents = [];
+    let list = res;
+    for (let i = 0; i < list.length; i++) {
+      if (list[i].packingList && list[i].packingList.length > 0) {
+        for (let j = 0; j < list[i].packingList.length; j++) {
+          if (list[i].packingList[j].detail || list[i].packingList[j].customTemplateUrl) {
+            documents.push({
+              documentID: list[i].packingList[j].data.waybillCode,
+              contents: [
+                list[i].packingList[j],
+                {
+                  data: {
+                    detail: list[i].packingList[j].detail,
+                  },
+                  templateURL: list[i].packingList[j].customTemplateUrl,
+                },
+              ],
+            });
+          } else {
+            documents.push({
+              documentID: list[i].packingList[j].data.waybillCode,
+              contents: [list[i].packingList[j]],
+            });
+          }
+        }
+      }
+    }
+    request.task.documents = documents;
+    if (ws.value.readyState !== 1) {
+      initWebSocket(true, request);
+    } else {
+      send(request);
+    }
   });
 };
 const openExpressCode = ref(false);