From fdd158306bf6dc3584f5110a385323f4a8dfb463 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 02 九月 2026 14:25:10 +0800
Subject: [PATCH] feat(wms): 重构仓库管理系统并优化图表显示

---
 src/views/wls/salesnotice/data.ts |  135 ++++++++++++++++++++++++++++++++------------
 1 files changed, 97 insertions(+), 38 deletions(-)

diff --git a/src/views/wls/salesnotice/data.ts b/src/views/wls/salesnotice/data.ts
index 6818446..dc2d2a7 100644
--- a/src/views/wls/salesnotice/data.ts
+++ b/src/views/wls/salesnotice/data.ts
@@ -8,6 +8,7 @@
 import {
   DICT_TYPE,
   MesAutoCodeRuleCode,
+  MesWmWarehouseTypeEnum,
 } from '@vben/constants';
 
 import { Button } from 'ant-design-vue';
@@ -15,8 +16,11 @@
 import { z } from '#/adapter/form';
 import { generateAutoCode } from '#/api/mes/md/autocode/record';
 import CrmCustomerSelect from '#/components/crm-customer-select.vue';
-import { ErpSaleOrderSelect } from '#/views/erp/sale/order/components';
-import { MdItemSelect } from '#/views/mes/md/item/components';
+import {
+  getStockSummaryByBatch,
+  getStockSummaryByItem,
+  type MesWmMaterialStockApi,
+} from '#/api/mes/wm/materialstock';
 
 /** 琛ㄥ崟绫诲瀷 */
 export type FormType = 'create' | 'detail' | 'update';
@@ -83,26 +87,11 @@
       rules: 'required',
     },
     {
-      fieldName: 'saleOrderId',
-      label: '閿�鍞鍗�',
-      component: markRaw(ErpSaleOrderSelect),
-      componentProps: {
-        placeholder: '璇烽�夋嫨閿�鍞鍗�',
-        // 閫夋嫨閿�鍞鍗曞悗锛岃嚜鍔ㄥ洖濉鎴蜂俊鎭�
-        onChange: (item: any) => {
-          if (item?.customerId && formApi) {
-            formApi.setFieldValue('clientId', item.customerId);
-          }
-        },
-      },
-    },
-    {
       fieldName: 'clientId',
       label: '瀹㈡埛',
       component: markRaw(CrmCustomerSelect),
       componentProps: {
         placeholder: '璇烽�夋嫨瀹㈡埛',
-        disabled: true,
       },
       rules: 'selectRequired',
     },
@@ -177,15 +166,6 @@
       },
     },
     {
-      fieldName: 'saleOrderCode',
-      label: '閿�鍞鍗曠紪鍙�',
-      component: 'Input',
-      componentProps: {
-        allowClear: true,
-        placeholder: '璇疯緭鍏ラ攢鍞鍗曠紪鍙�',
-      },
-    },
-    {
       fieldName: 'clientId',
       label: '瀹㈡埛',
       component: markRaw(CrmCustomerSelect),
@@ -209,11 +189,6 @@
       field: 'name',
       title: '閫氱煡鍗曞悕绉�',
       minWidth: 150,
-    },
-    {
-      field: 'saleOrderCode',
-      title: '閿�鍞鍗曠紪鍙�',
-      minWidth: 140,
     },
     {
       field: 'clientName',
@@ -349,15 +324,98 @@
   ];
 }
 
-/** 閫氱煡鍗曡鏂板/淇敼鐨勮〃鍗� */
+/** 姝e紡搴擄紙鍚堟牸搴撳簱瀛橈紝stockState = 20锛夋湁搴撳瓨鐨勭墿鏂欓�夐」 */
+export async function loadQualifiedStockItemOptions(): Promise<
+  { label: string; value: number }[]
+> {
+  const list = await getStockSummaryByItem({
+    stockState: 20,
+    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
+  });
+  return list.map((item: MesWmMaterialStockApi.MaterialStockSummary) => ({
+    label: [item.itemName, item.itemCode, `搴撳瓨 ${item.totalQuantity}`]
+      .filter(Boolean)
+      .join(' '),
+    value: item.itemId as number,
+  }));
+}
+
+/** 鎸囧畾鐗╂枡鐨勬寮忓簱瀛樻壒娆¢�夐」 */
+export async function loadQualifiedStockBatchOptions(
+  itemId: number,
+): Promise<{ label: string; value: number }[]> {
+  const list = await getStockSummaryByBatch({
+    stockState: 20,
+    itemId,
+    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
+  });
+  return list.map((item: MesWmMaterialStockApi.MaterialStockSummary) => ({
+    label: [item.batchCode, `搴撳瓨 ${item.totalQuantity}`].filter(Boolean).join(' '),
+    value: item.batchId as number,
+  }));
+}
+
+/**
+ * 鍙彂璐ф暟閲忥細鎵�閫夌墿鏂�/鎵规鐨勬寮忓簱瀛橈紙stockState = 20锛夋眹鎬汇��
+ *
+ * 鎸囧畾鎵规鏃剁簿纭埌璇ユ壒娆★紝鍚﹀垯杩斿洖鐗╂枡鍏ㄩ儴姝e紡搴撳瓨銆�
+ */
+export async function loadAvailableQuantity(
+  itemId?: number,
+  batchId?: number,
+): Promise<number> {
+  if (!itemId) {
+    return 0;
+  }
+  if (batchId) {
+    const list = await getStockSummaryByBatch({
+    stockState: 20,
+    itemId,
+    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
+  });
+    return list.find((item) => item.batchId === batchId)?.totalQuantity ?? 0;
+  }
+  const list = await getStockSummaryByItem({
+    stockState: 20,
+    itemId,
+    warehouseType: MesWmWarehouseTypeEnum.QUALIFIED,
+  });
+  return list.find((item) => item.itemId === itemId)?.totalQuantity ?? 0;
+}
+
+/**
+ * 閫氱煡鍗曡鏂板/淇敼鐨勮〃鍗曘��
+ *
+ * 鐗╂枡銆佹壒娆″潎浠庢寮忓簱搴撳瓨锛坰tockState = 20锛変腑閫夋嫨锛�
+ * 鎵规閫夐」闅忕墿鏂欒仈鍔ㄥ姞杞斤紝鍙敤搴撳瓨涓嶈冻鐢卞悗绔繚瀛樻椂鏍¢獙銆�
+ */
 export function useLineFormSchema(): VbenFormSchema[] {
   return [
     {
       fieldName: 'itemId',
       label: '鐗╂枡',
-      component: markRaw(MdItemSelect),
+      component: 'Select',
       componentProps: {
-        placeholder: '璇烽�夋嫨鐗╂枡',
+        allowClear: true,
+        filterOption: true,
+        optionFilterProp: 'label',
+        options: [],
+        placeholder: '璇烽�夋嫨鐗╂枡锛堜粎姝e紡搴撳簱瀛橈級',
+        showSearch: true,
+      },
+      rules: 'selectRequired',
+    },
+    {
+      fieldName: 'batchId',
+      label: '鎵规',
+      component: 'Select',
+      componentProps: {
+        allowClear: true,
+        filterOption: true,
+        optionFilterProp: 'label',
+        options: [],
+        placeholder: '璇烽�夋嫨鎵规锛堜粎姝e紡搴撳簱瀛橈級',
+        showSearch: true,
       },
       rules: 'selectRequired',
     },
@@ -368,17 +426,18 @@
       componentProps: {
         class: '!w-full',
         min: 0.01,
-        placeholder: '璇疯緭鍏ュ彂璐ф暟閲�',
+        placeholder: '璇疯緭鍏ュ彂璐ф暟閲忥紙涓嶅彲瓒呰繃姝e紡搴撳瓨锛�',
         precision: 2,
       },
       rules: 'required',
     },
     {
-      fieldName: 'batchCode',
-      label: '鎵规鍙�',
+      fieldName: 'availableQuantity',
+      label: '鍙彂璐ф暟閲�',
       component: 'Input',
       componentProps: {
-        placeholder: '璇疯緭鍏ユ壒娆″彿',
+        disabled: true,
+        placeholder: '閫夋嫨鐗╂枡/鎵规鍚庤嚜鍔ㄥ甫鍑�',
       },
     },
     {

--
Gitblit v1.9.3