From 1378fc4cd7abc24ed3a982e09437c2c8a74e9f2f Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期二, 27 一月 2026 19:06:32 +0800
Subject: [PATCH] 代码优化

---
 项目代码/WIDESEA_WMSClient/src/extension/stock/stockView.js |  318 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 273 insertions(+), 45 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js"
index 92ad623..f786268 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js"
@@ -1,8 +1,5 @@
-
-//姝s鏂囦欢鏄敤鏉ヨ嚜瀹氫箟鎵╁睍涓氬姟浠g爜锛屽彲浠ユ墿灞曚竴浜涜嚜瀹氫箟椤甸潰鎴栬�呴噸鏂伴厤缃敓鎴愮殑浠g爜
-
-import { el } from "element-plus/es/locales.mjs";
-
+import { createVNode, render, h, reactive } from 'vue';
+import { ElDialog, ElForm, ElFormItem, ElSelect, ElOption, ElButton, ElMessage, ElLoading } from 'element-plus';
 let extension = {
   components: {
     //鏌ヨ鐣岄潰鎵╁睍缁勪欢
@@ -36,48 +33,48 @@
       //   }
       // }
       this.columns.forEach(column => {
-        if (column.field == 'materielCode') {
-          column.formatter = (row) => {
-            var str = '';
-            var list = row.materielCode.split(',');
-            for (let index = 0; index < list.length; index++) {
-              str += list[index] + '<br>';
-            }
-            return str = list[0] == "" ? "绌虹" : str;
-          }
-        }
-        if (column.field == 'batchNo') {
-          column.formatter = (row) => {
-            var str = '';
-            var list = row.batchNo.split(',');
-            for (let index = 0; index < list.length; index++) {
-              str += list[index] + '<br>';
-            }
-            return str = list[0] == "" ? "鏃�" : str;
-          }
-        }
-        if (column.field == 'materielInfo') {
-          const today = new Date()
-          column.formatter = (row) => {
-            if (row.details.length > 0) {
-              const today = new Date();
-              const closestDate = row.details
-                .map(x => {
-                  const date = new Date(x.effectiveDate);
-                  const diffInDays = Math.ceil(Math.abs((today - date) / (1000 * 60 * 60 * 24)));
-                  return { date, diffInDays };
-                })
-                .reduce((closest, current) => (current.diffInDays < closest.diffInDays ? current : closest))
-                .date;
+        // if (column.field == 'materielCode') {
+        //   column.formatter = (row) => {
+        //     var str = '';
+        //     var list = row.materielCode.split(',');
+        //     for (let index = 0; index < list.length; index++) {
+        //       str += list[index] + '<br>';
+        //     }
+        //     return str = list[0] == "" ? "绌虹" : str;
+        //   }
+        // }
+        // if (column.field == 'batchNo') {
+        //   column.formatter = (row) => {
+        //     var str = '';
+        //     var list = row.batchNo.split(',');
+        //     for (let index = 0; index < list.length; index++) {
+        //       str += list[index] + '<br>';
+        //     }
+        //     return str = list[0] == "" ? "鏃�" : str;
+        //   }
+        // }
+        // if (column.field == 'materielInfo') {
+        //   const today = new Date()
+        //   column.formatter = (row) => {
+        //     if (row.details.length > 0) {
+        //       const today = new Date();
+        //       const closestDate = row.details
+        //         .map(x => {
+        //           const date = new Date(x.effectiveDate);
+        //           const diffInDays = Math.ceil(Math.abs((today - date) / (1000 * 60 * 60 * 24)));
+        //           return { date, diffInDays };
+        //         })
+        //         .reduce((closest, current) => (current.diffInDays < closest.diffInDays ? current : closest))
+        //         .date;
 
-              const daysSinceClosest = Math.ceil(Math.abs((today - closestDate) / (1000 * 60 * 60 * 24)));
-              return '<span style="color: #F56C6C">' + daysSinceClosest + "澶�" + '</span>';
-            } else {
-              return '<span style="color: #F56C6C">' + "鏃犱繚璐ㄦ湡" + '</span>';
-            }
+        //       const daysSinceClosest = Math.ceil(Math.abs((today - closestDate) / (1000 * 60 * 60 * 24)));
+        //       return '<span style="color: #F56C6C">' + daysSinceClosest + "澶�" + '</span>';
+        //     } else {
+        //       return '<span style="color: #F56C6C">' + "鏃犱繚璐ㄦ湡" + '</span>';
+        //     }
 
-          }
-        }
+        //   }
+        // }
         if (column.field == 'sumStock') {
           column.formatter = (row) => {
             if (row.details.length > 0) {
@@ -93,7 +90,238 @@
 
           }
         }
+        if (column.field === 'orderStatistics') {
+          column.formatter = (row) => {
+            // 鏍¢獙details鏄惁瀛樺湪涓旀湁鏁版嵁
+            if (row.details && row.details.length > 0) {
+              // 鎸塨arcode + supplyCode + BatchNo 缁勫悎缁村害鍒嗙粍缁熻stockQuantity鎬诲拰锛屽苟璁板綍鍗曚綅锛堝彇绗竴涓潪绌哄崟浣嶏級
+              const groupSumMap = row.details.reduce((acc, item) => {
+                // 鑾峰彇鍒嗙粍鍏抽敭瀛楁锛屼负绌烘椂璧嬩簣榛樿鍊�
+                const supplyCode = item.supplyCode || '鏈煡渚涘簲鍟嗙紪鐮�';
+                const batchNo = item.batchNo || '鏈煡鎵规鍙�';
+                const materielCode = item.materielCode || '鏈煡鐗╂枡'; // 淇濈暀鍘熸湁鐗╂枡缂栫爜
+                const quantity = Number(item.stockQuantity) || 0;
+                const unit = item.unit || ''; // 鑾峰彇鍗曚綅锛屾棤鍒欎负绌�
+
+                // 缁勫悎鍒嗙粍閿紙鍙牴鎹渶瑕佽皟鏁存樉绀烘牸寮忥級
+                const groupKey = `${supplyCode}|${batchNo}|${materielCode}`;
+
+                // 绱姞鏁伴噺锛屼繚鐣欑涓�涓潪绌哄崟浣�
+                acc[groupKey] = {
+                  total: (acc[groupKey]?.total || 0) + quantity,
+                  unit: acc[groupKey]?.unit || unit,
+                  supplyCode,
+                  batchNo,
+                  materielCode
+                };
+                return acc;
+              }, {});
+
+              // 姣忎釜鍒嗙粍椤圭敓鎴愮嫭绔媎iv锛岃法琛屾樉绀猴紙鍖呭惈鎵�鏈夊垎缁勭淮搴﹀拰鍗曚綅锛�
+              const displayItems = Object.entries(groupSumMap).map(([_, data]) => {
+                // 澶勭悊鍗曚綅鏄剧ず锛氭湁鍗曚綅鍒欏姞绌烘牸鏄剧ず锛屾棤鍒欎笉鏄剧ず
+                const unitText = data.unit ? ` ${data.unit}` : '';
+
+                // 缁勮鏄剧ず鏂囨湰锛堝彲鏍规嵁闇�姹傝皟鏁村瓧娈垫樉绀洪『搴忓拰鏍煎紡锛�
+                return `<div style="line-height: 1.5; white-space: normal; margin-bottom: 4px;">
+                  渚涘簲鍟嗙紪鐮侊細${data.supplyCode} | 鎵规鍙凤細${data.batchNo} | 鐗╂枡缂栫爜锛�${data.materielCode}锛�${data.total}${unitText}
+        </div>`;
+              });
+
+              const displayContent = displayItems.join('');
+              return `<div style="color: #716cf5ff; white-space: normal; word-break: break-all;">${displayContent}</div>`;
+            } else {
+              return '<span style="color: #F56C6C">绌虹</span>';
+            }
+          };
+        }
+        if (column.field == 'stockOrderNo') {
+          column.formatter = (row) => {
+            // 鏈夋槑缁嗘暟鎹椂澶勭悊
+            if (row.details && row.details.length > 0) {
+              // 鎻愬彇鎵�鏈夐潪绌虹殑orderNO骞跺幓閲�
+              const uniqueOrderNOs = [...new Set(
+                row.details.map(item => item.orderNo).filter(no => no) // 杩囨护绌哄崟鎹彿
+              )];
+
+              // 鏈夋湁鏁堝崟鎹彿鍒欐崲琛屾樉绀猴紝鍚﹀垯鏄剧ず榛樿鏂囨湰
+              if (uniqueOrderNOs.length > 0) {
+                return `<span style="color: #F56C6C">${uniqueOrderNOs.join('<br>')}</span>`;
+              } else {
+                return '<span style="color: #F56C6C">鏆傛棤鍗曟嵁</span>';
+              }
+            } else {
+              // 鏃犳槑缁嗘暟鎹椂鏄剧ず榛樿鏂囨湰
+              return '<span style="color: #F56C6C">鏆傛棤鍗曟嵁</span>';
+            }
+          }
+        }
       })
+
+      let SelectTake = this.buttons.find(x => x.value == 'SelectStockTake');
+if (SelectTake) {
+  // 鏀逛负绠ご鍑芥暟纭繚this鎸囧悜Vue缁勪欢瀹炰緥
+  SelectTake.onClick = async () => {
+    // 鑾峰彇閫変腑鏁版嵁锛堜笌鍘熼�昏緫涓�鑷达紝纭繚鏄暟缁勬牸寮忥級
+    let stockViews = this.$refs.table.getSelected();
+    
+    // 鏁版嵁鏍¢獙锛氳嚦灏戦�夋嫨涓�鏉℃暟鎹�
+    if (stockViews.length === 0) return ElMessage.error("璇烽�夋嫨闇�瑕佹搷浣滅殑鏁版嵁!");
+    
+    // 绔欏彴閫夐」锛堝彲鏍规嵁瀹為檯涓氬姟璋冩暣閫夐」鍊硷級
+    const stationOptions = [
+      { label: "绔欏彴2", value: "2-1" },
+      { label: "绔欏彴3", value: "3-1" },
+      { label: "绔欏彴4", value: "4-1" },
+    ];
+    
+    // 鍒涘缓寮圭獥鎸傝浇鑺傜偣
+    const mountNode = document.createElement("div");
+    document.body.appendChild(mountNode);
+    
+    // 琛ㄥ崟鏁版嵁锛堢粦瀹氶�変腑鐨勭珯鍙帮級
+    const formData = reactive({
+      outStation: stationOptions[0].value, // 榛樿閫変腑绗竴涓珯鍙�
+    });
+    
+    // 鍒涘缓寮圭獥VNode
+    const vnode = createVNode(
+      ElDialog,
+      {
+        title: "搴撳瓨鎿嶄綔 - 閫夋嫨鍑哄簱绔欏彴",
+        width: "500px",
+        modelValue: true,
+        appendToBody: true,
+        "onUpdate:modelValue": (isVisible) => {
+          if (!isVisible) {
+            render(null, mountNode);
+            document.body.removeChild(mountNode);
+          }
+        },
+        style: {
+          padding: "20px 0",
+          borderRadius: "8px",
+        },
+      },
+      {
+        default: () =>
+          h(
+            ElForm,
+            {
+              model: formData,
+              rules: {
+                outStation: [
+                  { required: true, message: "璇烽�夋嫨鍑哄簱绔欏彴", trigger: "change" },
+                ],
+              },
+              ref: "stockTakeForm", // 琛ㄥ崟ref鏍囪瘑
+              labelWidth: "100px",
+              style: {
+                padding: "0 30px",
+              },
+            },
+            [
+              // 绔欏彴閫夋嫨涓嬫媺妗�
+              h(ElFormItem, {
+                label: "鍑哄簱绔欏彴",
+                prop: "outStation",
+                style: { marginBottom: "24px" },
+              }, [
+                h(ElSelect, {
+                  placeholder: "璇烽�夋嫨鍑哄簱绔欏彴",
+                  modelValue: formData.outStation,
+                  "onUpdate:modelValue": (val) => {
+                    formData.outStation = val;
+                  },
+                  style: {
+                    width: "100%",
+                    height: "40px",
+                    borderRadius: "4px",
+                    borderColor: "#dcdfe6",
+                  },
+                }, stationOptions.map((station) =>
+                  h(ElOption, { label: station.label, value: station.value })
+                )),
+              ]),
+              // 搴曢儴鎸夐挳鍖哄煙
+              h("div", {
+                style: {
+                  textAlign: "right",
+                  marginTop: "8px",
+                  paddingRight: "4px",
+                },
+              }, [
+                // 鍙栨秷鎸夐挳
+                h(ElButton, {
+                  type: "text",
+                  onClick: () => {
+                    render(null, mountNode);
+                    document.body.removeChild(mountNode);
+                    ElMessage.info("鍙栨秷搴撳瓨鎿嶄綔");
+                  },
+                  style: { marginRight: "8px", color: "#606266" },
+                }, "鍙栨秷"),
+                // 纭畾鎸夐挳
+                h(ElButton, {
+                  type: "primary",
+                  onClick: async () => {
+                    // 纭繚琛ㄥ崟ref宸叉寕杞�
+                    await this.$nextTick();
+                    const formRef = vnode.component.refs.stockTakeForm;
+
+                    if (!formRef) {
+                      ElMessage.error("琛ㄥ崟鍒濆鍖栧け璐ワ紝璇烽噸璇�");
+                      return;
+                    }
+
+                    // 琛ㄥ崟楠岃瘉
+                    try {
+                      await formRef.validate();
+                    } catch (err) {
+                      return;
+                    }
+
+                    const requestBody = stockViews;
+                    const outStation = formData.outStation;
+
+                    try {
+
+                      const url = `api/Task/TakeOutbound?outStation=${encodeURIComponent(outStation)}`;
+                      
+                      const x = await this.http.post(
+                        url, // 甯︽煡璇㈠弬鏁扮殑URL
+                        requestBody, // 璇锋眰浣擄細stockViews鏁扮粍
+                        "鏁版嵁澶勭悊涓�"
+                      );
+
+                      if (!x.status) {
+                        ElMessage.error(x.message || "搴撳瓨鎿嶄綔澶辫触");
+                        return;
+                      }
+
+                      ElMessage.success("鎿嶄綔鎴愬姛");
+                      this.refresh(); // 鍘熷埛鏂伴�昏緫淇濈暀
+                    } catch (error) {
+                      console.error("搴撳瓨鎺ュ彛璇锋眰澶辫触锛�", error);
+                      ElMessage.error("璇锋眰澶辫触锛岃绋嶅悗閲嶈瘯");
+                    } finally {
+                      // 鏃犺鎴愬姛澶辫触锛屽叧闂脊绐�
+                      render(null, mountNode);
+                      document.body.removeChild(mountNode);
+                    }
+                  },
+                  style: { borderRadius: "4px", padding: "8px 20px" },
+                }, "纭畾鎿嶄綔"),
+              ]),
+            ]),
+      }
+    );
+
+    // 缁戝畾app涓婁笅鏂囷紙纭繚寮圭獥鍐呯粍浠舵甯稿伐浣滐級
+    vnode.appContext = this.$.appContext;
+    render(vnode, mountNode);
+  };
+}
     },
     onInited() {
       //妗嗘灦鍒濆鍖栭厤缃悗

--
Gitblit v1.9.3