From ee7ac8df8bce38add1f75baf876b49de94b9e00a Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 16 十月 2026 17:58:33 +0800
Subject: [PATCH] feat(mes): 赋码管理绑定托盘支持未录入批次的袋码

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

diff --git a/src/views/wls/salesnotice/data.ts b/src/views/wls/salesnotice/data.ts
index f9a1931..dc2d2a7 100644
--- a/src/views/wls/salesnotice/data.ts
+++ b/src/views/wls/salesnotice/data.ts
@@ -5,21 +5,29 @@
 
 import { h, markRaw } from 'vue';
 
-import { DICT_TYPE, MesAutoCodeRuleCode } from '@vben/constants';
+import {
+  DICT_TYPE,
+  MesAutoCodeRuleCode,
+  MesWmWarehouseTypeEnum,
+} from '@vben/constants';
 
 import { Button } from 'ant-design-vue';
 
 import { z } from '#/adapter/form';
 import { generateAutoCode } from '#/api/mes/md/autocode/record';
-import { MdClientSelect } from '#/views/mes/md/client/components';
-import { MdItemSelect } from '#/views/mes/md/item/components';
+import CrmCustomerSelect from '#/components/crm-customer-select.vue';
+import {
+  getStockSummaryByBatch,
+  getStockSummaryByItem,
+  type MesWmMaterialStockApi,
+} from '#/api/mes/wm/materialstock';
 
 /** 琛ㄥ崟绫诲瀷 */
-export type FormType = 'create' | 'detail' | 'finish' | 'update';
+export type FormType = 'create' | 'detail' | 'update';
 
-/** 琛ㄥ崟澶撮儴鏄惁鍙锛堣鎯呫�佹墽琛屽嚭搴撴�侊級 */
+/** 琛ㄥ崟澶撮儴鏄惁鍙锛堣鎯呮�侊級 */
 function isHeaderReadonly(formType: FormType): boolean {
-  return formType === 'detail' || formType === 'finish';
+  return formType === 'detail';
 }
 
 /** 鏂板/淇敼鐨勮〃鍗� */
@@ -79,17 +87,9 @@
       rules: 'required',
     },
     {
-      fieldName: 'salesOrderCode',
-      label: '閿�鍞鍗曠紪鍙�',
-      component: 'Input',
-      componentProps: {
-        placeholder: '璇疯緭鍏ラ攢鍞鍗曠紪鍙�',
-      },
-    },
-    {
       fieldName: 'clientId',
       label: '瀹㈡埛',
-      component: markRaw(MdClientSelect),
+      component: markRaw(CrmCustomerSelect),
       componentProps: {
         placeholder: '璇烽�夋嫨瀹㈡埛',
       },
@@ -103,7 +103,7 @@
         class: '!w-full',
         format: 'YYYY-MM-DD',
         placeholder: '璇烽�夋嫨鍙戣揣鏃ユ湡',
-        valueFormat: 'x',
+        valueFormat: 'YYYY-MM-DD',
       },
       rules: 'required',
     },
@@ -166,18 +166,9 @@
       },
     },
     {
-      fieldName: 'salesOrderCode',
-      label: '閿�鍞鍗曠紪鍙�',
-      component: 'Input',
-      componentProps: {
-        allowClear: true,
-        placeholder: '璇疯緭鍏ラ攢鍞鍗曠紪鍙�',
-      },
-    },
-    {
       fieldName: 'clientId',
       label: '瀹㈡埛',
-      component: markRaw(MdClientSelect),
+      component: markRaw(CrmCustomerSelect),
       componentProps: {
         placeholder: '璇烽�夋嫨瀹㈡埛',
       },
@@ -198,11 +189,6 @@
       field: 'name',
       title: '閫氱煡鍗曞悕绉�',
       minWidth: 150,
-    },
-    {
-      field: 'salesOrderCode',
-      title: '閿�鍞鍗曠紪鍙�',
-      minWidth: 140,
     },
     {
       field: 'clientName',
@@ -238,6 +224,12 @@
         name: 'CellDict',
         props: { type: DICT_TYPE.MES_WM_SALES_NOTICE_STATUS },
       },
+    },
+    {
+      field: 'outStatus',
+      title: '鍑哄簱鐘舵��',
+      minWidth: 100,
+      slots: { default: 'outStatus' },
     },
     {
       title: '鎿嶄綔',
@@ -279,6 +271,28 @@
       width: 100,
     },
     {
+      field: 'outCount',
+      title: '宸插嚭搴撴暟閲�',
+      width: 100,
+      formatter: ({ cellValue }: { cellValue: number }) => (cellValue || 0).toFixed(2),
+    },
+    {
+      field: 'outProgress',
+      title: '鍑哄簱杩涘害',
+      width: 120,
+      cellRender: {
+        name: 'CellText',
+        props: {
+          formatter: ({ row }: { row: MesWmSalesNoticeLineApi.SalesNoticeLine }) => {
+            const quantity = row.quantity || 0;
+            const outCount = row.outCount || 0;
+            const percent = quantity > 0 ? Math.round((outCount / quantity) * 100) : 0;
+            return `${outCount.toFixed(2)} / ${quantity.toFixed(2)} (${percent}%)`;
+          },
+        },
+      },
+    },
+    {
       field: 'batchCode',
       title: '鎵规鍙�',
       minWidth: 120,
@@ -310,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',
     },
@@ -329,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