From ff0ae974a1c561eaf2915988dac63cd066af189f Mon Sep 17 00:00:00 2001
From: yinbangzhong <zhongbangyin@126.com>
Date: 星期四, 12 九月 2024 09:23:44 +0800
Subject: [PATCH] bug fix

---
 src/views/authority/users/index.vue |  102 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 80 insertions(+), 22 deletions(-)

diff --git a/src/views/authority/users/index.vue b/src/views/authority/users/index.vue
index de2d8b7..37aeefe 100644
--- a/src/views/authority/users/index.vue
+++ b/src/views/authority/users/index.vue
@@ -123,7 +123,7 @@
       @ok="editHandleOk"
       width="48%"
     >
-      <a-form ref="formRefPaw" :model="editform">
+      <a-form ref="formRef" :model="editform" auto-label-width>
         <a-row :gutter="20">
           <a-col :span="10">
             <a-form-item
@@ -171,12 +171,11 @@
           </a-col>
           <a-col :span="10">
             <a-form-item
-              required
               field="role"
               label="瑙掕壊"
-              :rules="[{ required: true, message: '瑙掕壊蹇呴��' }]"
             >
               <a-select
+                multiple
                 v-model="editform.role"
                 :options="roles"
                 :field-names="fieldNames"
@@ -217,17 +216,28 @@
           >
           </a-tree>
         </a-card>
-        <a-card class="card-demo" title="鐢ㄦ埛鎵�灞炴満鏋�" hoverable>
-          <a-space wrap>
-            <a-tag
-              v-for="(tag, index) of checkStrictly"
-              :key="tag.deptId"
-              @close="handleRemove(tag)"
-            >
-              {{ tag.deptName }}
-            </a-tag>
-          </a-space>
-        </a-card>
+        <div :style="{ 'display': 'flex', 'flex-direction': 'column' }">
+          <a-card class="card-demo" title="鐢ㄦ埛鎵�灞為儴闂�" :style="{ 'width': '460px', 'height': '500px', 'overflow-y': 'auto' }">
+            <a-space wrap>
+              <a-tag
+                v-for="(tag, index) of checkStrictly"
+                :key="tag.deptId"
+              >
+                {{ tag.deptName }}
+              </a-tag>
+            </a-space>
+            <a-divider />
+            <a-space wrap>
+              閮ㄩ棬瑙掕壊:
+              <a-tag
+                v-for="(tag, index) of checkStrictlyDeptRole"
+                :key="tag.roleId"
+              >
+                {{ tag.roleName }}
+              </a-tag>
+            </a-space>
+          </a-card>
+        </div>
       </div>
     </a-modal>
     <a-modal
@@ -326,8 +336,8 @@
   let checkStrictlyKnowledge = ref([]);
   let checkStrictlyDialog = ref([]);
   let checkStrictlyAgent = ref([]);
+  let checkStrictlyDeptRole = ref([]);
   let formRef = ref();
-  const formRefPaw = ref();
 
   let menuTips = ref(['鏉冮檺绠$悊', '璐﹀彿']);
   type SizeProps = 'mini' | 'small' | 'medium' | 'large';
@@ -355,7 +365,7 @@
     loginName: '',
     userName: '',
     psw: '',
-    role: '',
+    role: [],
   });
 
   let size = ref<SizeProps>('medium');
@@ -377,12 +387,22 @@
   const onCheck = (newCheckedKeys, event) => {
     let o = { deptId: event.node.deptId, deptName: event.node.deptName };
     if (event.checked) {
+      event.node.roles.forEach(
+        (val) => {
+          checkStrictlyDeptRole.value.push(val);
+        }
+      );
       checkStrictly.value.push(o);
     } else {
       checkStrictly.value.forEach((val, idx, array) => {
         // val: 褰撳墠鍊�
         if (val.deptId == event.node.deptId) {
           checkStrictly.value.splice(idx, 1);
+          checkStrictlyDeptRole.value.forEach((val2, idx2, array2) => {
+            if (val2.deptId == event.node.deptId) {
+              checkStrictlyDeptRole.value.splice(idx2, 1);
+            }
+          });
           return true;
         }
       });
@@ -447,7 +467,15 @@
   ]);
 
   const statusChange = async (value, record) => {
-    await Userstatus(record.userId, value).then((res) => {});
+    if (record?.dept) {
+      await Userstatus(record.userId, value).then((res) => {});
+    } else {
+      record.status = '0';
+      Modal.warning({
+        title: '鎻愮ず',
+        content: '濡傛兂鍚敤鐢ㄦ埛锛岄渶杩涜閮ㄩ棬閰嶇疆.',
+      });
+    }
   };
 
   const handleCancel = (type) => {
@@ -475,18 +503,28 @@
     if (err) {
       visible.value = true;
     } else {
+      let uuu;
       if (editform.value.userId.length > 0) {
         await UserEdit({
           ...editform.value,
         } as unknown as User).then((res) => {
           fetchData();
+          uuu = res.data;
         });
       } else {
         await UserAdd({
           ...editform.value,
         } as unknown as User).then((res) => {
           fetchData();
+          uuu = res.data;
         });
+      }
+      if (uuu.dept?false:true) {
+        deptvisible.value = true;
+        checkedKeys.value = [];
+        expandKdys.value = [];
+        checkStrictly.value = [];
+        selectUser.value = uuu;
       }
     }
   };
@@ -524,7 +562,8 @@
     //缂栬緫
     if (t == 2) {
       visible.value = true;
-      formRefPaw.value?.resetFields();
+      formRef.value?.resetFields();
+      editform.value.role=[];
       save.value = '缂栬緫';
       editform.value.userId = record.userId;
       editform.value.userName = record.userName;
@@ -532,7 +571,10 @@
       editform.value.email = record.email;
       editform.value.phoneNumber = record.phoneNumber;
       if (record.roles?.length > 0) {
-        editform.value.role = record.roles[0].roleId;
+        //閬嶅巻record.roles
+        record.roles.forEach((val) => {
+          editform.value.role.push(val.roleId);
+        })
       }
     }
     //鍒犻櫎
@@ -610,16 +652,32 @@
       checkedKeys.value = [];
       expandKdys.value = [];
       checkStrictly.value = [];
+      checkStrictlyDeptRole.value=[];
       selectUser.value = record;
-      expandKdys.value.push('0');
-      if (record.dept) {
+      expandKdys.value.push("0");
+      if (record?.dept) {
         record.dept.forEach((val) => {
           checkStrictly.value.push({
             deptId: val.deptId,
-            deptName: val.deptName,
+            deptName: val.deptName
           });
           checkedKeys.value.push(val.deptId);
           expandKdys.value.push(val.deptId);
+          record.roles.forEach(
+            (r) => {
+              if (r.dept) {
+                r.dept.forEach((d) => {
+                  if (d.deptId == val.deptId) {
+                    checkStrictlyDeptRole.value.push({
+                      roleId: r.roleId,
+                      roleName: r.roleName,
+                      deptId:d.deptId,
+                    });
+                  }
+                });
+              }
+            }
+          );
         });
       }
     }

--
Gitblit v1.8.0