From b33517d527aff48ff30eb78d341bbce53d0ed3bb Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期六, 30 十一月 2024 06:42:42 +0800
Subject: [PATCH] 部门、人。回显bug

---
 src/components/Process/panel/taskPanel.vue |   67 +++++++++++-----
 src/components/flow/Dept/index.vue         |   34 +++++---
 src/components/flow/User/index.vue         |  102 ++++++++++++++++++++++---
 src/components/flow/Role/index.vue         |   21 ++++-
 4 files changed, 171 insertions(+), 53 deletions(-)

diff --git a/src/components/Process/panel/taskPanel.vue b/src/components/Process/panel/taskPanel.vue
index 59063a2..51fb63f 100644
--- a/src/components/Process/panel/taskPanel.vue
+++ b/src/components/Process/panel/taskPanel.vue
@@ -5,7 +5,7 @@
         <el-switch v-model="bpmnFormData.async" active-text="鏄�" inactive-text="鍚�" @change="updateElementTask('async')"/>
       </el-form-item>
       <el-form-item label="鐢ㄦ埛绫诲瀷">
-        <el-select v-model="bpmnFormData.userType" placeholder="閫夋嫨浜哄憳" @change="updateUserType">
+        <el-select v-model="bpmnFormData.userType" placeholder="鐢ㄦ埛绫诲瀷" @change="updateUserType">
           <el-option
             v-for="item in userTypeOption"
             :key="item.value"
@@ -87,7 +87,7 @@
       :close-on-press-escape="false"
       :show-close="false"
     >
-      <flow-user v-if="userVisible" :checkType="checkType" :selectValues="selectData.assignee || selectData.candidateUsers" @handleUserSelect="userSelect"></flow-user>
+      <flow-user v-show="userVisible" ref="user" :checkType="checkType" :num="num" :selectValues="selectData.assignee || selectData.candidateUsers" @handleUserSelect="userSelect"></flow-user>
       <div slot="footer" class="dialog-footer">
         <el-button size="small" @click="userVisible = false">鍙� 娑�</el-button>
         <el-button size="small" type="primary" @click="checkUserComplete">纭� 瀹�</el-button>
@@ -109,7 +109,8 @@
       </div>
     </el-dialog>
 
-    <flow-dept :checkeds="selectData.candidateGroups" :show="deptVisible" @close="closeDept" @submit="submitDept"/>
+    <!--  閫夋嫨閮ㄩ棬  -->
+    <flow-dept  ref="dept" :checkeds="selectData.candidateGroups" :show="deptVisible" @close="closeDept" @submit="submitDept"/>
 
     <!--閫夋嫨琛ㄨ揪寮�-->
     <el-dialog
@@ -119,7 +120,7 @@
       :close-on-press-escape="false"
       :show-close="false"
     >
-      <flow-exp v-if="expVisible" :selectValues="selectData.exp" @handleSingleExpSelect="expSelect"></flow-exp>
+      <flow-exp :selectValues="selectData.exp" @handleSingleExpSelect="expSelect"></flow-exp>
       <div slot="footer" class="dialog-footer">
         <el-button size="small" @click="expVisible = false">鍙� 娑�</el-button>
         <el-button size="small" type="primary" @click="checkExpComplete">纭� 瀹�</el-button>
@@ -137,6 +138,8 @@
 import ElInputTag from '@/components/flow/ElInputTag'
 import FlowDept from '@/components/flow/Dept'
 import {StrUtil} from '@/utils/StrUtil'
+
+
 
 export default {
   name: "TaskPanel",
@@ -156,6 +159,7 @@
   },
   data() {
     return {
+      num: 0, // 鐢ㄤ簬瑙﹀彂鐢ㄦ埛閫夋嫨鏇存柊
       userVisible: false,
       roleVisible: false,
       expVisible: false,
@@ -171,7 +175,7 @@
       ],
       checkAll: false,
       bpmnFormData: {
-        userType: "",
+        userType: "candidateDeptGroups",
         assignee: "",
         candidateUsers: "",
         candidateGroups: "",
@@ -184,7 +188,7 @@
       selectData: {
         assignee: null,
         candidateUsers: null,
-        candidateGroups: null,  // 瑙掕壊
+        candidateGroups: [],  // 瑙掕壊
         candidateDeptGroups: [], // 閮ㄩ棬
         exp: null,
       },
@@ -209,14 +213,14 @@
   methods: {
     closeDept() {
       this.deptVisible = false
-      this.selectData.candidateGroups = []
+      this.selectData.candidateGroups = null
     },
 
     // 鍒濆鍖栬〃鍗�
     resetTaskForm() {
       // 鍒濆鍖栬涓虹┖鍊�
       this.bpmnFormData = {
-        userType: "",
+        userType: "candidateDeptGroups",
         assignee: "",
         candidateUsers: "",
         candidateGroups: "",
@@ -256,16 +260,19 @@
 
     // 鏇存柊浜哄憳绫诲瀷
     updateUserType(val) {
+      console.log("worinim", val)
       // 鍒犻櫎xml涓凡閫夋嫨鏁版嵁绫诲瀷鑺傜偣
       this.deleteFlowAttar();
-      delete this.modelerStore.element.businessObject[`userType`]
       // 娓呴櫎宸查�変汉鍛樻暟鎹�
-      this.bpmnFormData[val] = null;
+      if (val === "candidateDeptGroups") {
+        this.bpmnFormData["candidateGroups"] = null;
+      } else {
+        this.bpmnFormData[val] = null;
+      }
       this.selectData = {
         assignee: null,
         candidateUsers: null,
         candidateGroups: null,
-        candidateDeptGroups: null,
         exp: null,
       }
       // 鍐欏叆userType鑺傜偣淇℃伅鍒皒ml
@@ -297,43 +304,54 @@
     // 鑾峰彇浜哄憳淇℃伅
     getUserList(val, key) {
       if (StrUtil.isNotBlank(val)) {
-        const newArr = this.modelerStore.userList?.filter(i => val.split(',').includes(i.userId.toString()))
-        this.bpmnFormData[key] = newArr.map(item => item.nickName).join(',');
+
+
         if ('assignee' === key) {
-          this.selectData[key] = newArr.find(item => item.userId.toString() === val).userId;
+          console.log("杩欓噷寮�濮嬫姤閿欙紝", this.modelerStore.userList)
+          const uList = this.modelerStore.userList.filter(item => item.userId == val);
+          this.bpmnFormData[key] = uList && uList.length > 0 ? uList[0].nickName : "浜哄憳涓嶅瓨鍦�";
+          this.selectData[key] = val;
         } else {
+          const newArr = this.modelerStore.userList?.filter(i => val.split(',').includes(i.userId.toString()))
+          console.log("鎸囧畾浜哄憳", newArr)
+          this.bpmnFormData[key] = newArr.map(item => item.nickName).join(',');
           this.selectData[key] = newArr.map(item => item.userId);
         }
+        // if (this.$refs.user) {
+        //   this.$refs.user.setChecked(this.selectData[key])
+        // }
+
       }
     },
 
     // 鑾峰彇瑙掕壊淇℃伅
     getRoleList(val, key) {
       if (StrUtil.isNotBlank(val)) {
-
         // 鏍规嵁id绛涢�夊嚭鏄鑹茶繕鏄儴闂�
         const roleAndDeptIds = val.split(",");
         const deptIds = roleAndDeptIds.filter(item => item.includes("dept"));
         const roleIds = roleAndDeptIds.filter(item => !item.includes("dept"));
         // 璋佹湁鍊煎氨鏄皝
         if (roleIds && roleIds.length > 0) {
-          console.log("鎴戝幓1", roleIds)
           const newArr = this.modelerStore.roleList?.filter(i => roleIds.includes(i.roleId.toString()))
           this.bpmnFormData[key] = newArr.map(item => item.roleName).join(',');
           if ('assignee' === key) {
+            console.log("涓嶄細鍚э紵")
             this.selectData[key] = newArr.find(item => item.roleId.toString() === val).roleId;
           } else {
             this.selectData[key] = newArr.map(item => item.roleId);
           }
         } else {
-          console.log("鎴戝幓2", deptIds)
+          console.log(deptIds, "閮ㄩ棬IDs")
           const newArr = this.modelerStore.deptList?.filter(i => deptIds.includes(i.id))
           this.bpmnFormData[key] = newArr.map(item => item.label).join(',');
           if ('assignee' === key) {
+            console.log("涓嶄細鍚э紵锛燂紵")
             this.selectData[key] = newArr.find(item => item.id === val).id;
           } else {
             this.selectData[key] = newArr.map(item => item.id);
           }
+          // this.$refs.dept.setCheckList(this.selectData[key])
         }
 
 
@@ -344,12 +362,19 @@
 
     /*鍗曢�変汉鍛�*/
     singleUserCheck() {
+      this.num+=1
       this.userVisible = true;
       this.checkType = "single";
+      // this.$nextTick(() => {
+      //   console.log(typeof this.selectData.assignee, "绫诲瀷")
+      //   this.$refs.user.setChecked(this.selectData.assignee);
+      // });
+
     },
 
     /*澶氶�変汉鍛�*/
     multipleUserCheck() {
+      this.num = this.num + 1
       this.userVisible = true;
       this.checkType = "multiple";
     },
@@ -387,7 +412,7 @@
       if (selection) {
         this.deleteFlowAttar();
         this.updateCustomElement('dataType', 'fixed');
-        if (selection instanceof Array) {
+        if (this.checkType === 'multiple') {
           const userIds = selection.map(item => item.userId);
           const nickName = selection.map(item => item.nickName);
           // userType = candidateUsers
@@ -395,6 +420,7 @@
           this.updateCustomElement(this.bpmnFormData.userType, userIds.join(','));
           this.handleSelectData(this.bpmnFormData.userType, userIds);
         } else {
+          console.log(selection, "杩斿洖鍊�")
           // userType = assignee
           this.bpmnFormData[this.bpmnFormData.userType] = selection.nickName;
           this.updateCustomElement(this.bpmnFormData.userType, selection.userId);
@@ -418,15 +444,16 @@
     // 閮ㄩ棬閫変腑鏁版嵁
     submitDept(checkList, names) {
       this.deptVisible = false
-      // this.selectData.candidateDeptGroups = checkList
       if (checkList && names) {
         this.deleteFlowAttar();
         this.bpmnFormData["candidateGroups"] = names;
         this.updateCustomElement('dataType', 'fixed');
         // userType = candidateGroups
         // 杩欓噷鍙兘鍐欐涓猴細candidateGroups锛屽洜涓篺lowable鐢ㄦ埛缁勭殑鍏抽敭瀛楀氨鏄畠
+        // this.updateCustomElement("candidateGroups", null); // 鍏堟竻绌哄啀璧嬪�硷紝鍥犱负鏄竴娆℃�ф彁浜ょ殑閮ㄩ棬鏁版嵁锛屾墍浠ラ渶瑕佸幓閲嶏紝鐩存帴璧嬪�间负null
         this.updateCustomElement("candidateGroups", checkList);
         this.handleSelectData("candidateGroups", checkList);
+        console.log(checkList, "閮ㄩ棬鍊�")
       }
     },
 
@@ -444,7 +471,7 @@
     /*鐢ㄦ埛閫変腑璧嬪��*/
     checkUserComplete() {
       this.userVisible = false;
-      this.checkType = "";
+      this.checkType = "single";
     },
 
     /*鍊欓�夎鑹查�変腑璧嬪��*/
diff --git a/src/components/flow/Dept/index.vue b/src/components/flow/Dept/index.vue
index 105e6a7..0f23c51 100644
--- a/src/components/flow/Dept/index.vue
+++ b/src/components/flow/Dept/index.vue
@@ -4,16 +4,19 @@
       :title="`閫夋嫨鍊欓�夐儴闂╜"
       :visible.sync="show"
       width="65%"
+
+      :destroy-on-close="true"
       :close-on-click-modal="false"
       :before-close="close">
       <el-tree
+        ref="tree"
         :data="deptTree"
         show-checkbox
         node-key="id"
         :check-strictly="true"
         :default-expanded-keys="['dept:100']"
         @check-change="handleCheckChange"
-        :default-checked-keys="checkeds">
+        >
       </el-tree>
       <span slot="footer" class="dialog-footer">
         <el-button @click="close">鍙� 娑�</el-button>
@@ -34,21 +37,21 @@
       type: Boolean
     },
     checkeds: {
-      required: true,
-      type: Array
+      required: true
     }
   },
-  // watch: {
-  //   checkeds: {
-  //     handler(newV) {
-  //       if (newV) {
-  //         console.log("djjdjdjdjdjdjj")
-  //         this.checkedAfterHandler = newV.map(item => {const arr = item.split(':'); return parseInt(arr[1])})
-  //       }
-  //     },
-  //     deep: true
-  //   }
-  // },
+  watch: {
+    show: {
+      handler(newV) {
+        this.$nextTick(() => {
+          if (this.$refs.tree && this.checkeds) {
+            this.$refs.tree.setCheckedKeys(this.checkeds);
+          }
+        });
+      },
+      deep: true
+    }
+  },
   data() {
     return {
       deptTree: [],
@@ -61,6 +64,9 @@
     })
   },
   methods: {
+    setCheckList(value) {
+      this.checkList = value
+    },
     handleCheckChange(data, checked, indeterminate) {
       if (checked) {
         this.checkList.push(data)
diff --git a/src/components/flow/Role/index.vue b/src/components/flow/Role/index.vue
index fb0446f..e8f2dcf 100644
--- a/src/components/flow/Role/index.vue
+++ b/src/components/flow/Role/index.vue
@@ -121,6 +121,7 @@
             this.radioSelected = newVal
           } else {
             this.selectRoleList = newVal;
+            console.log(this.selectRoleList, "瑙掕壊鍥炴樉")
           }
         }
       },
@@ -128,14 +129,24 @@
     },
     roleList: {
       handler(newVal) {
+        console.log(newVal, "瑙掕壊鍥炴樉11")
         if (StrUtil.isNotBlank(newVal) && this.selectRoleList.length > 0) {
           this.$nextTick(() => {
             this.$refs.dataTable.clearSelection();
-            this.selectRoleList?.split(',').forEach(key => {
-              this.$refs.dataTable.toggleRowSelection(newVal.find(
-                item => key == item.roleId
-              ), true)
-            });
+            if (this.selectRoleList instanceof Array) {
+              this.selectRoleList.forEach(key => {
+                this.$refs.dataTable.toggleRowSelection(newVal.find(
+                  item => key == item.roleId
+                ), true)
+              });
+            } else {
+              this.selectRoleList?.split(',').forEach(key => {
+                this.$refs.dataTable.toggleRowSelection(newVal.find(
+                  item => key == item.roleId
+                ), true)
+              });
+            }
+
           });
         }
       }
diff --git a/src/components/flow/User/index.vue b/src/components/flow/User/index.vue
index 31ce534..33dcb57 100644
--- a/src/components/flow/User/index.vue
+++ b/src/components/flow/User/index.vue
@@ -102,6 +102,10 @@
       default: 'multiple',
       required: true
     },
+    num: {
+      required: true,
+      type: Number
+    }
   },
   data() {
     return {
@@ -163,36 +167,106 @@
     },
     selectValues: {
       handler(newVal) {
-        if (StrUtil.isNotBlank(newVal)) {
-          if (newVal instanceof Number) {
-            this.radioSelected = newVal
+        if (newVal) {
+          if (this.checkType === 'multiple') {
+            this.selectUserList = newVal.map(item => parseInt(item))
           } else {
-            this.selectUserList = newVal;
+            this.radioSelected = parseInt(newVal)
           }
         }
       },
       immediate: true
     },
     userList: {
+      deep: true,
       handler(newVal) {
-        if (StrUtil.isNotBlank(newVal) && this.selectUserList.length > 0) {
+        console.log(newVal, "鏁板瓧")
+        console.log(this.selectValues, "浼犲叆鐨勫�兼槸")
+        if (this.checkType !== 'multiple') {
+          console.log(this.userList, "浼犲叆鐨勫�兼槸")
+          if (this.radioSelected && this.userList.length > 0) {
             this.$nextTick(() => {
               this.$refs.dataTable.clearSelection();
-              this.selectUserList?.split(',').forEach(key => {
-                this.$refs.dataTable.toggleRowSelection(newVal.find(
-                  item => key == item.userId
-                ), true)
-              });
+              newVal.forEach(item => {
+                console.log(this.radioSelected === item.userId, 123)
+                if (this.radioSelected === item.userId) {
+                  this.$refs.dataTable.toggleRowSelection(item)
+                }
+              })
             });
+          }
+        } else {
+          this.$nextTick(() => {
+            this.$refs.dataTable.clearSelection();
+            this.selectUserList.forEach(key => {
+              newVal.forEach(item => {
+                if (key === item.userId) {
+                  this.$refs.dataTable.toggleRowSelection(item)
+                }
+              })
+            });
+          });
         }
-      }
-    }
+
+        // if (StrUtil.isNotBlank(newVal)) {
+        //
+        //   if (typeof newVal == "number" || typeof newVal == "string") {
+        //     console.log("杩涜繖")
+        //
+        //   } else {
+        //     console.log("涓嶅簲璇ヨ繘鐫�")
+        //
+        //     console.log("鐢ㄦ埛鍥炴樉", this.selectUserList)
+        //   }
+        // }
+      },
+      // immediate: true
+    },
+    // userList: {
+    //   // handler(newVal) {
+    //   //   console.log(this.radioSelected, "鍗曢�夊��")
+    //   //   if (this.checkType !== 'multiple') {
+    //   //
+    //   //   } else {
+    //   //     console.log("this.selectUserList",this.selectUserList ,typeof this.selectUserList)
+    //   //
+    //   //   }
+    //   // }
+    // }
   },
-  created() {
+  mounted() {
     this.getList();
     this.getDeptTree();
   },
   methods: {
+    setChecked() {
+      if (this.checkType !== 'multiple') {
+        this.radioSelected = this.selectValues
+        this.$nextTick(() => {
+          this.$refs.dataTable.clearSelection();
+          this.userList.forEach(item => {
+            console.log("鍗曢�夊�硷細", this.radioSelected)
+            console.log(parseInt(this.radioSelected) === item.userId)
+            if (parseInt(this.radioSelected) === item.userId) {
+              this.$refs.dataTable.toggleRowSelection(item)
+            }
+          })
+        });
+      } else {
+        this.selectUserList = this.selectValues;
+        this.$nextTick(() => {
+          this.$refs.dataTable.clearSelection();
+          this.selectUserList.forEach(key => {
+            this.userList.forEach(item => {
+              if (parseInt(key) === item.userId) {
+                this.$refs.dataTable.toggleRowSelection(item)
+              }
+            })
+          });
+        });
+      }
+
+    },
     /** 鏌ヨ鐢ㄦ埛鍒楄〃 */
     getList() {
       this.loading = true;
@@ -229,7 +303,7 @@
     },
     // 鍗曢�夋閫変腑鏁版嵁
     handleSingleUserSelect(selection) {
-      this.radioSelected = selection.userId;//鐐瑰嚮褰撳墠琛屾椂,radio鍚屾牱鏈夐�変腑鏁堟灉
+      // this.radioSelected = selection.userId;//鐐瑰嚮褰撳墠琛屾椂,radio鍚屾牱鏈夐�変腑鏁堟灉
       this.$emit('handleUserSelect', selection);
     },
     /** 鎼滅储鎸夐挳鎿嶄綔 */

--
Gitblit v1.8.0