From e33e77b0eba78f405abbb9ea47aabd10ba0280e0 Mon Sep 17 00:00:00 2001 From: duanliangtao Date: Mon, 6 May 2024 13:47:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=9E=B6=E6=9E=84-=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E4=BA=BA=E5=91=98=E6=B7=BB=E5=8A=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=9D=83=E9=99=90=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/organization/organization.vue | 66 +++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/src/views/modules/base/organization/organization.vue b/src/views/modules/base/organization/organization.vue index eb6b395a7..01473ceb3 100644 --- a/src/views/modules/base/organization/organization.vue +++ b/src/views/modules/base/organization/organization.vue @@ -487,7 +487,7 @@ v-model="peoForm.manageScopes" :options="orgOptions" :props="orgOptionProps" - :show-all-levels="false" + :show-all-levels="true" clearable> @@ -1328,7 +1328,8 @@ export default { // 组织树 orgOptions: [], orgOptionProps :{ - multiple: false, + multiple: true, + emitPath: true, value: 'agencyId', label: 'agencyName', children: 'subAgencyList', @@ -1710,6 +1711,18 @@ export default { }, // 人员修改 async updatePeoDo () { + + const targetAgencyIds = this.peoForm.manageScopes.map(innerArray => innerArray[innerArray.length - 1]); + + // 用于存储提取结果的 Set 对象 + const result = new Set(); + + // 调用递归函数提取 level 与 agencyId 组合成的字符串 + this.extractLevelAndAgencyId(this.orgOptions[0], targetAgencyIds, result); + + // 将 Set 对象转换为数组 + const manageScopeArray = Array.from(result); + const url = "/gov/org/staff/editstaff"; let params = { @@ -1723,7 +1736,7 @@ export default { newRoles: this.peoForm.newRoles, agencyId: this.currentAgencyId, idCard: this.peoForm.idCard, - manageScopes:this.peoForm.manageScopes + manageScopes:manageScopeArray }; const { data, code, msg } = await requestPost(url, params); @@ -1743,6 +1756,20 @@ export default { } }, + // 递归函数,遍历 JSON 对象提取所有的 level 与 agencyId 组合成的字符串 + extractLevelAndAgencyId(obj, agencyIds, result) { + if (obj && typeof obj === 'object') { + if (obj.level && obj.agencyId && agencyIds.includes(obj.agencyId)) { + result.add(`${obj.level}:${obj.agencyId}`); + } + if (Array.isArray(obj.subAgencyList)) { + obj.subAgencyList.forEach(subObj => { + this.extractLevelAndAgencyId(subObj, agencyIds, result); + }); + } + } + }, + // 字典 async getDictionaries () { const url = "/sys/dict/data/dictlist"; @@ -2043,6 +2070,7 @@ export default { }, // 修改网格人员 async xiuGridPeo (row) { + console.log("修改网格人员"); this.modifyPeo = true; this.peoForm.orgType = "grid"; @@ -2085,6 +2113,7 @@ export default { }, // 修改人员 async xiuPeo (row) { + console.log("修改人员"); this.modifyPeo = true; this.peoForm.orgType = "agency"; @@ -2119,13 +2148,42 @@ export default { } }); this.peoForm.newRoles = existedRoleArr; - this.peoForm.manageScopes = data.manageScopes + var paths = this.findParentPath(this.orgOptions[0], data.manageScopes); + this.peoForm.manageScopes = paths; } else { this.$message.error(msg); } }, + findParentPath(data,agencyIds) { + let paths = []; + + function findPathRecursive(agencyId, node, path) { + if (node.agencyId === agencyId) { + path.push(agencyId); + paths.push(path.slice()); // Make a copy of the path array before pushing + return true; + } + + if (node.subAgencyList) { + for (let i = 0; i < node.subAgencyList.length; i++) { + if (findPathRecursive(agencyId, node.subAgencyList[i], path.concat(node.agencyId))) { + return true; + } + } + } + + return false; + } + + agencyIds.forEach(agencyId => { + findPathRecursive(agencyId, data, []); + }); + + return paths; + }, // 修改社区人员 async xiuCommunityPeo (row) { + console.log("修改社区人员"); this.modifyPeo = true; this.peoForm.orgType = "dept";