Przeglądaj źródła

质检方案选择改成只能单选

hezhanp 8 miesięcy temu
rodzic
commit
449f6edba4

+ 13 - 15
src/views/inspectionPlan/components/new-edit.vue

@@ -1042,21 +1042,19 @@ export default {
       this.$refs.inspectionTemplateRef.open(type);
     },
     async inspectionTemplateSuccess(select) {
-      let data = await getQualityTemplateByIds({
-        templateIds: select.map((item) => item.id)
-      });
-      console.log('---------------------------');
-      this.isScheme = false;
-
-      this.schemeList.push(...data);
-
-      const strings = this.schemeList.map((item) => JSON.stringify(item));
-      const removeDupList = [...new Set(strings)];
-      const result = removeDupList.map((item) => JSON.parse(item));
-      this.schemeList = result;
-
-      this.schemePagination.total = this.schemeList.length;
-    },
+  // 1. 根据子组件选中的质检方案ID,获取完整质检方案数据
+  let data = await getQualityTemplateByIds({
+    templateIds: select.map((item) => item.id) // 子组件已限制单选,select长度为1
+  });
+  
+  this.isScheme = false;
+  // 2. 直接用新数据覆盖原有列表(核心修改:删除push和去重,改为直接赋值)
+  this.schemeList = data || []; 
+  // 3. 更新分页总数(确保表格分页正确)
+  this.schemePagination.total = this.schemeList.length;
+  // 4. 重置分页页码(可选:回到第一页,避免新列表数据不足时页码异常)
+  this.schemePagination.currentPage = 1;
+},
     async handleEditOrDetail(row) {
       console.log('row====', row);
       row.accessory = row.accessory || [];

+ 33 - 21
src/views/inspectionTemplate/components/inspectionTemplateDialog.vue

@@ -17,7 +17,7 @@
       tool-class="ele-toolbar-form"
       row-key="qualityLevelId"
       v-if="equipmentdialog"
-      :selection.sync="selection"
+      @selection-change="handleSelectionChange"
       :initLoad="false"
       @columns-change="handleColumnChange"
       :cache-key="cacheKeyUrl"
@@ -36,18 +36,17 @@
 <script>
 import search from './search.vue';
 import { getList } from '@/api/inspectionTemplate';
-
 import tabMixins from '@/mixins/tableColumnsMixin';
+
 export default {
   components: { search },
   mixins: [tabMixins],
   data() {
     return {
-      cacheKeyUrl:
-        'qms-c2e9664a-inspectionTemplate-components-inspectionTemplateDialog',
+      cacheKeyUrl: 'qms-c2e9664a-inspectionTemplate-components-inspectionTemplateDialog',
       type: '',
       equipmentdialog: false,
-      selection: [],
+      selection: [], // 存储单选结果(仅一条数据)
       tableHeight: 'calc(100vh - 605px)',
       columns: [
         {
@@ -55,7 +54,7 @@ export default {
           type: 'selection',
           columnKey: 'selection',
           align: 'center',
-          reserveSelection: true
+          reserveSelection: false // 关闭保留选中(避免切换页签残留)
         },
         {
           columnKey: 'index',
@@ -104,44 +103,57 @@ export default {
       ]
     };
   },
-
-  watch: {},
   methods: {
     datasource({ page, where, limit }) {
       return getList({
         ...where,
         pageNum: page,
         size: limit
-        // type: this.type
       });
     },
+    // 打开弹窗:清空历史选中
     open(type) {
       this.type = type;
       this.equipmentdialog = true;
+      this.selection = []; // 清空选中状态
       this.$nextTick(() => {
         this.$refs.search.setWhere(type);
         this.$refs.search.search();
+        // 重置表格选中状态
+        if (this.$refs.table) this.$refs.table.clearSelection();
       });
     },
     handleClose() {
       this.equipmentdialog = false;
+      this.selection = []; // 关闭时清空选中
+      if (this.$refs.table) this.$refs.table.clearSelection();
     },
-    // 选择
-    selected() {
-      if (!this.selection.length) {
-        this.$message.error('至少选择一条数据');
-
-        return;
-      }
-      this.$emit('choose', this.selection);
-      this.handleClose();
-    },
-
+    // 单选控制:仅保留最后一个选中项
+    handleSelectionChange(val) {
+  if (val.length > 1) {
+    const lastVal = val[val.length - 1];
+    this.$refs.table.clearSelection();
+    this.$refs.table.toggleRowSelection(lastVal, true);
+    this.selection = [lastVal];
+  } else {
+    this.selection = val;
+  }
+},
+// 子组件:选择按钮(校验并传值)
+selected() {
+  if (this.selection.length !== 1) { 
+    this.$message.error('请选择一条数据');
+    return;
+  }
+  this.$emit('choose', this.selection); // 传递单选结果(数组形式)
+  this.handleClose();
+},
     search(where) {
       this.$refs.table.reload({ page: 1, where });
+      this.selection = []; // 搜索时清空选中
     }
   }
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="scss" scoped></style>