From d2cd585f4d3b015789a5f6c8d75e352605932f85 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 21 八月 2026 13:44:30 +0800
Subject: [PATCH] feat(mes): 新增袋码作废时间和原因字段及破损替换功能

---
 src/views/mes/pro/bagCode/index.vue |   97 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/src/views/mes/pro/bagCode/index.vue b/src/views/mes/pro/bagCode/index.vue
index f4ffa22..910602c 100644
--- a/src/views/mes/pro/bagCode/index.vue
+++ b/src/views/mes/pro/bagCode/index.vue
@@ -6,7 +6,7 @@
   import { MesProBagCodeStatusEnum } from "@vben/constants";
   import { downloadFileFromBlobPart } from "@vben/utils";
 
-  import { message } from "ant-design-vue";
+  import { message, Modal } from "ant-design-vue";
 
   import { ACTION_ICON, TableAction, useVbenVxeGrid } from "#/adapter/vxe-table";
   import {
@@ -21,6 +21,7 @@
   import { useGridColumns, useGridFormSchema } from "./data";
   import BindPalletModal from "./modules/bind-pallet.vue";
   import GenerateModal from "./modules/generate-form.vue";
+  import ReplaceModal from "./modules/replace-form.vue";
   import QrTraceModal from "../components/qr-trace-modal.vue";
 
   defineOptions({ name: "MesProBagCode" });
@@ -32,6 +33,11 @@
 
   const [BindPalletFormModal, bindPalletFormModalApi] = useVbenModal({
     connectedComponent: BindPalletModal,
+    destroyOnClose: true,
+  });
+
+  const [ReplaceFormModal, replaceFormModalApi] = useVbenModal({
+    connectedComponent: ReplaceModal,
     destroyOnClose: true,
   });
 
@@ -48,6 +54,12 @@
   /** 鐢熸垚鏁版嵁鍖� */
   function handleGenerate() {
     generateFormModalApi.open();
+  }
+
+  /** 鏇挎崲鎴愬姛鍚庡睍绀虹粨鏋滃苟鍒锋柊鍒楄〃 */
+  function handleReplaceSuccess(result: MesProBagCodeApi.ReplaceResult) {
+    showReplaceResult(result);
+    handleRefresh();
   }
 
   /** 鎵爜杩芥函 */
@@ -88,12 +100,82 @@
 
   /** 鑾峰彇鍕鹃�夌殑琚嬬爜璁板綍 */
   function getSelectedRecords(): MesProBagCodeApi.BagCode[] | undefined {
-    const records = gridApi.grid.getCheckboxRecords() as MesProBagCodeApi.BagCode[];
-    if (records.length === 0) {
+    const records = [
+      ...(gridApi.grid.getCheckboxReserveRecords?.() ?? []),
+      ...(gridApi.grid.getCheckboxRecords?.() ?? []),
+    ] as MesProBagCodeApi.BagCode[];
+    const uniqueRecords = [
+      ...new Map(records.map((record) => [record.id, record])).values(),
+    ];
+    if (uniqueRecords.length === 0) {
       message.warning("璇疯嚦灏戝嬀閫変竴鏉¤鐮佽褰�");
       return undefined;
     }
-    return records;
+    return uniqueRecords;
+  }
+
+  /** 灞曠ず鏇挎崲缁撴灉 */
+  function showReplaceResult(result: MesProBagCodeApi.ReplaceResult) {
+    const items = result.items ?? [];
+    const content = items.length
+      ? items
+          .map(
+            (item) =>
+              `${item.oldCode ?? "-"} 鈫� ${item.newCode ?? "-"}${
+                item.newPalletCode ? `锛堟墭鐩橈細${item.newPalletCode}锛塦 : ""
+              }`,
+          )
+          .join("\n")
+      : "鏇挎崲鏄庣粏鏆傛棤";
+    Modal.success({
+      title: "鐮存崯琚嬬爜鏇挎崲鎴愬姛",
+      content: `鎵规锛�${result.batchCode ?? "-"}\n鏇挎崲鏁伴噺锛�${
+        result.count ?? items.length
+      }\n${content}`,
+      centered: true,
+    });
+  }
+
+  /** 鎵归噺鏇挎崲鐮存崯琚嬬爜 */
+  async function handleReplace() {
+    const records = getSelectedRecords();
+    if (!records) return;
+    if (records.length > 200) {
+      message.warning("鍗曟鏈�澶氭浛鎹� 200 涓鐮�");
+      return;
+    }
+    const batchIds = new Set(records.map((record) => record.batchId));
+    if (batchIds.size > 1 || !records[0]?.batchId) {
+      message.warning("璇烽�夋嫨鍚屼竴鎵规涓嬬殑琚嬬爜杩涜鏇挎崲");
+      return;
+    }
+    if (
+      records.some(
+        (record) =>
+          record.status !== MesProBagCodeStatusEnum.GENERATED &&
+          record.status !== MesProBagCodeStatusEnum.PRINTED,
+      )
+    ) {
+      message.warning("浠呭凡鐢熸垚鎴栧凡瀵煎嚭鍗板埛鐨勮鐮佸厑璁告浛鎹�");
+      return;
+    }
+    if (records.some((record) => !record.id)) {
+      message.warning("鎵�閫夎鐮佺己灏戠紪鍙凤紝鏃犳硶鏇挎崲");
+      return;
+    }
+    try {
+      await confirm(`纭浣滃簾鎵�閫� ${records.length} 涓鐮佸苟鐢熸垚绛夐噺鏂扮爜鍚楋紵`);
+    } catch {
+      return;
+    }
+    const first = records[0]!;
+    replaceFormModalApi
+      .setData({
+        batchId: first.batchId!,
+        batchCode: first.batchCode,
+        ids: records.map((record) => record.id!),
+      })
+      .open();
   }
 
   /** 鎵归噺缁戝畾鎵樼洏 */
@@ -200,6 +282,7 @@
   <Page auto-content-height>
     <GenerateFormModal @success="handleRefresh" />
     <BindPalletFormModal @success="handleRefresh" />
+    <ReplaceFormModal @success="handleReplaceSuccess" />
     <QrTraceQueryModal />
     <Grid table-title="琚嬬爜鍒楄〃锛堜竴琚嬩竴鐮侊級">
       <template #toolbar-tools>
@@ -218,6 +301,12 @@
               onClick: handleBindPallet,
             },
             {
+              label: '鐮存崯鏇挎崲',
+              type: 'primary',
+              auth: ['mes:pro-bag-code:replace'],
+              onClick: handleReplace,
+            },
+            {
               label: '瑙g粦鎵樼洏',
               auth: ['mes:pro-bag-code:update'],
               onClick: handleUnbindPallet,

--
Gitblit v1.9.3