From ec59e476a82c10b25e0ad7687ae0e4cbfa6905d0 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期一, 17 八月 2026 15:10:16 +0800
Subject: [PATCH] 转移商机传参错误

---
 src/views/basicData/mdm/index.vue |   89 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 81 insertions(+), 8 deletions(-)

diff --git a/src/views/basicData/mdm/index.vue b/src/views/basicData/mdm/index.vue
index 16b34d4..8995f78 100644
--- a/src/views/basicData/mdm/index.vue
+++ b/src/views/basicData/mdm/index.vue
@@ -1,13 +1,14 @@
 <script lang="ts" setup>
 import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 import type { MdmItemApi } from '#/api/mdm/item';
+import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
 
-import { ref } from 'vue';
+import { computed, ref } from 'vue';
 
 import { confirm, Page, useVbenModal } from '#/packages/effects/common-ui/src';
 import { downloadFileFromBlobPart, isEmpty } from '#/packages/utils/src';
 
-import { message, Tag } from 'ant-design-vue';
+import { message, Switch, Tag } from 'ant-design-vue';
 
 import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
 import {
@@ -16,10 +17,12 @@
   // exportItem,
   getItemPage,
   updateItemStatus,
+  updateItemSync,
 } from '#/api/mdm/item';
+import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
 import { $t } from '#/locales';
 
-import { useGridColumns, useGridFormSchema, ITEM_TYPE_MAP, ITEM_TYPE_COLOR_MAP } from './data';
+import { useGridColumns, useGridFormSchema } from './data';
 import Form from './modules/form.vue';
 
 defineOptions({ name: 'MdmItem' });
@@ -28,6 +31,44 @@
   connectedComponent: Form,
   destroyOnClose: true,
 });
+
+// 鍒嗙被鍒楄〃缂撳瓨
+const categoryList = ref<MesMdItemTypeApi.ItemType[]>([]);
+
+const TAG_COLORS = [
+  'green',
+  'orange',
+  'blue',
+  'purple',
+  'cyan',
+  'magenta',
+  'geekblue',
+  'volcano',
+  'gold',
+  'lime',
+] as const;
+
+/** 鍒嗙被ID 鈫� 棰滆壊鏄犲皠锛堝熀浜庡垎绫诲湪鍒楄〃涓殑绱㈠紩寰幆鍒嗛厤锛� */
+const categoryColorMap = computed(() => {
+  const map = new Map<number, string>();
+  categoryList.value.forEach((item, index) => {
+    map.set(item.id!, TAG_COLORS[index % TAG_COLORS.length]!);
+  });
+  return map;
+});
+
+/** 鑾峰彇鍒嗙被Tag棰滆壊 */
+function getCategoryColor(categoryId?: number): string {
+  if (!categoryId) return '';
+  return categoryColorMap.value.get(categoryId) || '';
+}
+
+/** 鑾峰彇鍒嗙被鍚嶇О */
+function getCategoryName(categoryId?: number) {
+  if (!categoryId || !categoryList.value.length) return '';
+  const category = categoryList.value.find((item) => item.id === categoryId);
+  return category?.name || '';
+}
 
 /** 鍒锋柊琛ㄦ牸 */
 function handleRefresh() {
@@ -98,6 +139,23 @@
   }
 }
 
+const syncingId = ref<number | null>(null);
+
+/** 鍒囨崲鍚屾鐘舵�侊細鍏抽棴寮�鍏充細浠� MES 鍒犻櫎鐗╂枡锛岄渶纭 */
+async function handleSyncChange(row: MdmItemApi.Item, checked: boolean) {
+  if (!checked) {
+    await confirm('鍏抽棴鍚屾灏嗕粠 MES 鍒犻櫎璇ョ墿鏂欏強鍏宠仈閰嶇疆锛圔OM/SOP/SIP/鎵规閰嶇疆锛夛紝纭缁х画锛�');
+  }
+  syncingId.value = row.id!;
+  try {
+    await updateItemSync(row.id!, checked);
+    message.success(checked ? '宸插悓姝ュ埌 MES' : '宸插彇娑堝悓姝�');
+    handleRefresh();
+  } finally {
+    syncingId.value = null;
+  }
+}
+
 const checkedIds = ref<number[]>([]);
 function handleRowCheckboxChange({
   records,
@@ -118,6 +176,14 @@
     proxyConfig: {
       ajax: {
         query: async ({ page }, formValues) => {
+          // 鍔犺浇鍒嗙被鍒楄〃锛堢敤浜庢樉绀哄垎绫诲悕绉帮級
+          if (!categoryList.value.length) {
+            try {
+              categoryList.value = await getItemTypeSimpleList();
+            } catch {
+              categoryList.value = [];
+            }
+          }
           return await getItemPage({
             pageNo: page.currentPage,
             pageSize: page.pageSize,
@@ -175,16 +241,23 @@
           ]"
         />
       </template>
-      <template #itemType="{ row }">
-        <Tag v-if="row.itemType === 1" color="green">鍘熸枡</Tag>
-        <Tag v-else-if="row.itemType === 2" color="orange">鍗婃垚鍝�</Tag>
-        <Tag v-else-if="row.itemType === 3" color="blue">鎴愬搧</Tag>
-        <Tag v-else-if="row.itemType === 4" color="purple">杈呮枡</Tag>
+      <template #categoryName="{ row }">
+        <Tag v-if="getCategoryColor(row.categoryId)" :color="getCategoryColor(row.categoryId)">{{ getCategoryName(row.categoryId) }}</Tag>
+        <span v-else>{{ getCategoryName(row.categoryId) }}</span>
       </template>
       <template #isBatchManaged="{ row }">
         <Tag v-if="row.isBatchManaged" color="success">鏄�</Tag>
         <Tag v-else>鍚�</Tag>
       </template>
+      <template #syncedMes="{ row }">
+        <Switch
+          :checked="row.syncedMes"
+          :loading="syncingId === row.id"
+          checkedChildren="宸插悓姝�"
+          unCheckedChildren="鏈悓姝�"
+          @change="handleSyncChange(row, $event)"
+        />
+      </template>
       <template #actions="{ row }">
         <TableAction
           :actions="[

--
Gitblit v1.9.3