From 3de8b71ee1c6be3e41b77d6633c3f1a1b66c40f2 Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期五, 16 一月 2026 10:59:33 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_天津军泰伟业' into dev_天津军泰伟业

---
 src/views/basicData/product/ProductSelectDialog.vue |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/views/basicData/product/ProductSelectDialog.vue b/src/views/basicData/product/ProductSelectDialog.vue
index 246cd88..9f85785 100644
--- a/src/views/basicData/product/ProductSelectDialog.vue
+++ b/src/views/basicData/product/ProductSelectDialog.vue
@@ -33,12 +33,14 @@
 
     <!-- 鍒楄〃 -->
     <el-table
+        ref="tableRef"
         v-loading="loading"
         :data="tableData"
         height="420"
         highlight-current-row
         row-key="id"
         @selection-change="handleSelectionChange"
+        @select="handleSelect"
     >
       <el-table-column type="selection" width="55" />
       <el-table-column type="index" label="#" width="60"/>
@@ -70,7 +72,7 @@
 </template>
 
 <script setup lang="ts">
-import {computed, onMounted, reactive, ref, watch} from "vue";
+import {computed, onMounted, reactive, ref, watch, nextTick} from "vue";
 import {ElMessage} from "element-plus";
 import {productModelList} from '@/api/basicData/productModel'
 
@@ -83,6 +85,7 @@
 
 const props = defineProps<{
   modelValue: boolean;
+  single?: boolean; // 鏄惁鍙兘閫夋嫨涓�涓紝榛樿false锛堝彲閫夋嫨澶氫釜锛�
 }>();
 
 const emit = defineEmits(['update:modelValue', 'confirm']);
@@ -105,14 +108,48 @@
 const loading = ref(false);
 const tableData = ref<ProductRow[]>([]);
 const total = ref(0);
-const multipleSelection = ref<ProductRow[]>([])
+const multipleSelection = ref<ProductRow[]>([]);
+const tableRef = ref();
 
 function close() {
   visible.value = false;
 }
 
 const handleSelectionChange = (val: ProductRow[]) => {
-  multipleSelection.value = val
+  if (props.single && val.length > 1) {
+    // 濡傛灉闄愬埗涓哄崟涓�夋嫨锛屽彧淇濈暀鏈�鍚庝竴涓�変腑鐨�
+    const lastSelected = val[val.length - 1];
+    multipleSelection.value = [lastSelected];
+    // 娓呯┖琛ㄦ牸閫変腑鐘舵�侊紝鐒跺悗閲嶆柊閫変腑鏈�鍚庝竴涓�
+    nextTick(() => {
+      if (tableRef.value) {
+        tableRef.value.clearSelection();
+        tableRef.value.toggleRowSelection(lastSelected, true);
+      }
+    });
+  } else {
+    multipleSelection.value = val;
+  }
+}
+
+// 澶勭悊鍗曚釜閫夋嫨
+const handleSelect = (selection: ProductRow[], row: ProductRow) => {
+  if (props.single) {
+    // 濡傛灉闄愬埗涓哄崟涓紝娓呯┖鍏朵粬閫夋嫨锛屽彧淇濈暀褰撳墠琛�
+    if (selection.includes(row)) {
+      // 閫変腑褰撳墠琛屾椂锛屾竻绌哄叾浠栭�変腑
+      multipleSelection.value = [row];
+      nextTick(() => {
+        if (tableRef.value) {
+          tableData.value.forEach((item) => {
+            if (item.id !== row.id) {
+              tableRef.value.toggleRowSelection(item, false);
+            }
+          });
+        }
+      });
+    }
+  }
 }
 
 function onSearch() {
@@ -136,7 +173,11 @@
     ElMessage.warning("璇烽�夋嫨涓�鏉′骇鍝�");
     return;
   }
-  emit("confirm", multipleSelection.value);
+  if (props.single && multipleSelection.value.length > 1) {
+    ElMessage.warning("鍙兘閫夋嫨涓�涓骇鍝�");
+    return;
+  }
+  emit("confirm", props.single ? [multipleSelection.value[0]] : multipleSelection.value);
   close();
 }
 
@@ -157,6 +198,13 @@
   }
 }
 
+// 鐩戝惉寮圭獥鎵撳紑锛岄噸缃�夋嫨
+watch(() => props.modelValue, (visible) => {
+  if (visible) {
+    multipleSelection.value = [];
+  }
+});
+
 onMounted(() => {
   loadData()
 })

--
Gitblit v1.9.3