Parcourir la source

fix: update code

sunqijun il y a 2 mois
Parent
commit
43f15ca1f8

+ 23 - 14
src/views/production-safety/implement-safety-duty/components/IssueSafetyResponsibility.vue

@@ -18,8 +18,7 @@
           :props="cascaderProp"
           :show-all-levels="false"
           placeholder="请选择下发部门"
-          clearable
-          @remove-tag="(val) => handleRemoveTag(val, 'deptId', originDeptId)"
+          :clearable="false"
         />
       </el-form-item>
 
@@ -30,9 +29,14 @@
           v-model="formData.userGroupId"
           placeholder="请选择下发分组"
           style="width: 100%"
-          @remove-tag="(val) => handleRemoveTag(val, 'userGroupId', originUserGroupId)"
         >
-          <el-option v-for="group in groupList" :key="group.id" :label="group.name" :value="group.id" />
+          <el-option
+            v-for="group in groupList"
+            :disabled="originUserGroupId.includes(group.id)"
+            :key="group.id"
+            :label="group.name"
+            :value="group.id"
+          />
         </el-select>
       </el-form-item>
 
@@ -198,6 +202,7 @@
   import { ref, reactive, watch, onMounted } from 'vue';
   import { ElMessage, type FormInstance } from 'element-plus';
   import dayjs from 'dayjs';
+  import { uniqWith, isEqual } from 'lodash-es';
   import {
     queryAvailableUserList,
     safetyResponsibilityAdminQueryDetail,
@@ -241,6 +246,10 @@
     value: 'id',
     label: 'deptName',
     multiple: !/A|B/.test(props.currentDepartmentKey),
+    disabled: (data, node) => {
+      // node.pathValues 是当前节点的完整路径数组,例如 ['zhinan', 'sheji']
+      return originDeptId.value.some((path) => isEqual(path, node.pathValues));
+    },
   };
 
   watch(
@@ -292,17 +301,17 @@
     getUserData(dataName, query);
   };
 
-  const handleRemoveTag = (val, field, originData) => {
-    console.log('has:', originData, val);
+  // const handleRemoveTag = (val, field, originData) => {
+  //   console.log('has:', originData, val);
 
-    const currentId = new Set(originData.flat());
-    const has = Array.isArray(val) ? val.every((v) => currentId.has(v)) : currentId.has(val);
-    if (has) {
-      ElMessage.error('不能删除已有下发部门');
-      formData[field] = [...originData, ...formData[field]];
-      return;
-    }
-  };
+  //   const currentId = new Set(originData.flat());
+  //   const has = Array.isArray(val) ? val.every((v) => currentId.has(v)) : currentId.has(val);
+  //   if (has) {
+  //     ElMessage.error('不能删除已有下发部门');
+  //     formData[field] = [...originData, ...uniqWith(formData[field], isEqual)];
+  //     return;
+  //   }
+  // };
 
   const rules = reactive({
     deptId: [{ required: true, message: '请选择下发部门', trigger: 'change' }],