From fb4db4ae9b6a7f113ba049f6789e6916c0dcc276 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 12 十月 2026 09:15:08 +0800
Subject: [PATCH] feat(mes): 新增业务码支持并优化追溯查询功能

---
 src/views/mes/pro/pallet/index.vue |   86 +++++++++++++++++++++++++------------------
 1 files changed, 50 insertions(+), 36 deletions(-)

diff --git a/src/views/mes/pro/pallet/index.vue b/src/views/mes/pro/pallet/index.vue
index 0d2e0f5..82adce6 100644
--- a/src/views/mes/pro/pallet/index.vue
+++ b/src/views/mes/pro/pallet/index.vue
@@ -5,7 +5,7 @@
   import { Page, useVbenModal } from "@vben/common-ui";
   import { downloadFileFromBlobPart } from "@vben/utils";
 
-  import { message, Modal, Tag } from "ant-design-vue";
+  import { Button, message, Modal, Tag } from "ant-design-vue";
 
   import { ACTION_ICON, TableAction, useVbenVxeGrid } from "#/adapter/vxe-table";
   import {
@@ -13,14 +13,18 @@
     exportPalletExcel,
     exportPalletQr,
     exportPalletQrByIds,
+    exportPalletBusinessQr,
+    generatePalletBusinessCodes,
     getPalletPage,
   } from "#/api/mes/pro/pallet";
+  import { IconifyIcon } from "@vben/icons";
   import { $t } from "#/locales";
 
   import { useGridColumns, useGridFormSchema } from "./data";
   import BindBatchModal from "./modules/bind-batch.vue";
   import GenerateModal from "./modules/generate-form.vue";
   import QrTraceModal from "../components/qr-trace-modal.vue";
+  import BusinessQrModal from "../components/business-qr.vue";
 
   defineOptions({ name: "MesProPallet" });
 
@@ -40,6 +44,28 @@
   });
 
   /** 鍒锋柊琛ㄦ牸 */
+  const [BusinessQrViewModal, businessQrApi] = useVbenModal({ connectedComponent: BusinessQrModal, destroyOnClose: true });
+  function handleBusinessQr(row: MesProPalletApi.Pallet) {
+    businessQrApi.setData({ code: row.businessCode }).open();
+  }
+  function getBusinessIds() {
+    const records = [...(gridApi.grid.getCheckboxReserveRecords?.() || []), ...(gridApi.grid.getCheckboxRecords?.() || [])] as MesProPalletApi.Pallet[];
+    const ids = [...new Set(records.map(row => row.id).filter((id): id is number => id != null))];
+    if (!ids.length || ids.length > 200) { message.warning('璇峰嬀閫� 1 鑷� 200 鏉℃墭鐩樿褰�'); return; }
+    if (records.some(row => row.status === 20)) { message.warning('宸蹭綔搴熸墭鐩樹笉鍙搷浣滀笟鍔$爜'); return; }
+    return ids;
+  }
+  async function handleGenerateBusiness() {
+    const ids = getBusinessIds(); if (!ids) return;
+    const count = await generatePalletBusinessCodes(ids);
+    message.success(`宸茶ˉ鐢熸垚 ${count} 浠戒笟鍔$爜锛屽凡鏈夌爜鍊间繚鎸佷笉鍙榒); handleRefresh();
+  }
+  async function handleExportBusiness() {
+    const ids = getBusinessIds(); if (!ids) return;
+    const data = await exportPalletBusinessQr(ids);
+    downloadFileFromBlobPart({ fileName: '鎵樼洏涓氬姟浜岀淮鐮�.zip', source: data });
+  }
+
   function handleRefresh() {
     gridApi.query();
   }
@@ -177,42 +203,23 @@
     <GenerateFormModal @success="handlePreGenerateSuccess" />
     <BindBatchFormModal @success="handleRefresh" />
     <QrTraceQueryModal />
+    <BusinessQrViewModal />
     <Grid table-title="鎵樼洏鐮佸垪琛�">
+      <template #table-title><span class="text-[1rem] font-bold" style="white-space:nowrap">鎵樼洏鐮佸垪琛�</span></template>
       <template #toolbar-tools>
-        <TableAction :actions="[
-            {
-              label: '棰勭敓鎴愪簩缁寸爜',
-              type: 'primary',
-              icon: ACTION_ICON.ADD,
-              auth: ['mes:pro-pallet:create'],
-              onClick: handleCreate,
-            },
-            {
-              label: '缁戝畾鎵规',
-              icon: ACTION_ICON.EDIT,
-              auth: ['mes:pro-pallet:update'],
-              onClick: handleBindBatch,
-            },
-            {
-              label: '鎵爜杩芥函',
-              icon: ACTION_ICON.SEARCH,
-              auth: ['mes:pro-pallet:query'],
-              onClick: handleTrace,
-            },
-            {
-              label: '瀵煎嚭浜岀淮鐮�',
-              icon: ACTION_ICON.DOWNLOAD,
-              auth: ['mes:pro-pallet:export'],
-              onClick: handleExportQr,
-            },
-            {
-              label: $t('ui.actionTitle.export'),
-              type: 'primary',
-              icon: ACTION_ICON.DOWNLOAD,
-              auth: ['mes:pro-pallet:export'],
-              onClick: handleExport,
-            },
-          ]" />
+        <div class="mes-code-toolbar">
+          <TableAction :actions="[{ label: '棰勭敓鎴愪簩缁寸爜', type: 'primary', icon: ACTION_ICON.ADD, auth: ['mes:pro-pallet:create'], onClick: handleCreate },
+          { label: '缁戝畾鎵规', auth: ['mes:pro-pallet:update'], onClick: handleBindBatch },
+          { label: '鎵爜杩芥函', icon: ACTION_ICON.SEARCH, auth: ['mes:pro-pallet:query'], onClick: handleTrace }]" />
+          <TableAction :dropdown-trigger="['click']" :drop-down-actions="[{ label: '杩芥函浜岀淮鐮侊紙鎸夋壒娆★級', auth: ['mes:pro-pallet:export'], onClick: handleExportQr },
+          { label: '涓氬姟浜岀淮鐮侊紙閫変腑璁板綍锛�', auth: ['mes:pro-pallet:export'], onClick: handleExportBusiness },
+          { label: 'Excel 鏁版嵁', auth: ['mes:pro-pallet:export'], onClick: handleExport }]">
+            <template #more><Button>瀵煎嚭 <IconifyIcon icon="lucide:chevron-down" /></Button></template>
+          </TableAction>
+          <TableAction :dropdown-trigger="['click']" :drop-down-actions="[{ label: '琛ョ敓鎴愪笟鍔$爜锛堥�変腑璁板綍锛�', auth: ['mes:pro-pallet:create'], onClick: handleGenerateBusiness }]">
+            <template #more><Button>鏇村鎿嶄綔 <IconifyIcon icon="lucide:chevron-down" /></Button></template>
+          </TableAction>
+        </div>
       </template>
       <template #code="{ row }">
         <span>{{ getDisplayCode(row) }}</span>
@@ -226,11 +233,12 @@
       <template #actions="{ row }">
         <TableAction :actions="[
             {
-              label: '鏌ョ湅浜岀淮鐮�',
+              label: '杩芥函浜岀淮鐮�',
               type: 'link',
               auth: ['mes:pro-pallet:query'],
               onClick: handleViewQr.bind(null, row),
             },
+            { label: '涓氬姟浜岀淮鐮�', type: 'link', auth: ['mes:pro-pallet:query'], ifShow: !!row.businessCode, onClick: handleBusinessQr.bind(null, row) },
             {
               label: '瀵煎嚭浜岀淮鐮�',
               type: 'link',
@@ -255,3 +263,9 @@
     </Grid>
   </Page>
 </template>
+
+<style scoped>
+.mes-code-toolbar { display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:8px; }
+.mes-code-toolbar :deep(.ant-btn) { white-space:nowrap; }
+.mes-code-toolbar :deep(.ant-btn > .iconify) { display:inline-block;width:14px;height:14px;vertical-align:middle; }
+</style>

--
Gitblit v1.9.3