From 11030ffae0eeb84370d91a4b1fdb9c05c1a20f09 Mon Sep 17 00:00:00 2001 From: yunkexin <760754045@qq.com> Date: Tue, 2 Jun 2026 15:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9=E5=A4=9A=E9=80=89=E4=BA=BA?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E5=85=A8=E9=80=89=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/custom/people-selector/index.vue | 83 ++++++++++++++------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/components/custom/people-selector/index.vue b/components/custom/people-selector/index.vue index d23deeb..43cc378 100644 --- a/components/custom/people-selector/index.vue +++ b/components/custom/people-selector/index.vue @@ -202,6 +202,23 @@ getUserLists(json).then(res => { if (res.IsSuccessful) { this.selfDepartmentUsers = res.Data + let num = 0 + for (let task of this.selfDepartmentUsers) { + const itemJson = this.defaultChecked.filter(i => !i.IS_DELETED).find((item) => { + return item.NAME == task.NAME + }) + if (itemJson) { + num = num + 1 + } + } + this.checkedByAll = this.defaultChecked + if (num == this.selfDepartmentUsers.length && num !== 0) { + this.checkedByAll.push({ + NAME: '全选', + IS_DELETED: false, + USER_ID: 'all', + }) + } } }) } @@ -209,23 +226,7 @@ // findAndAddUser(this.orgTree) // } findAndAddUser(this.orgTree) - let num = 0 - for (let task of this.selfDepartmentUsers) { - const itemJson = this.defaultChecked.filter(i => !i.IS_DELETED).find((item) => { - return item.NAME == task.NAME - }) - if (itemJson) { - num = num + 1 - } - } - this.checkedByAll = this.defaultChecked - if (num == this.selfDepartmentUsers.length && num !== 0) { - this.checkedByAll.push({ - NAME: '全选', - IS_DELETED: false, - USER_ID: 'all', - }) - } + }, @@ -385,16 +386,6 @@ }) } } - // arrayC.forEach(item => { - // this.checkedByAll.push({ - // NAME: item.NAME, - // IS_DELETED: item.IS_DELETED, - // USER_ID: item.USER_ID, - // }) - - // }) - - // TODO: } else { if (e.type === 'dep') { this.handleExpandOrg({ @@ -430,6 +421,7 @@ // NAME: e.name // } }) + this.checkAndUpdateAllSelectStatus() } } } else { @@ -471,10 +463,47 @@ item.IS_DELETED = true } }) + this.checkAndUpdateAllSelectStatus() } } } }, + // 检查并更新全选状态(当勾选人员时调用) + checkAndUpdateAllSelectStatus() { + // 只针对本部门人员检查 + if (!this.selfDepartmentUsers || this.selfDepartmentUsers.length === 0) return + + // 获取本部门所有人员的 ID + const allUserIds = this.selfDepartmentUsers.map(user => user.ID) + + // 获取当前已选中(未删除)的本部门人员 ID + // 关键:过滤掉已删除的项 + const selectedUserIds = this.checkedByAll + .filter(item => !item.IS_DELETED && item.USER_ID && item.USER_ID !== 'all') + .map(item => item.USER_ID) + + // 检查是否所有本部门人员都被选中 + const isAllSelected = allUserIds.length > 0 && + allUserIds.every(id => selectedUserIds.includes(id)) + + // 检查全选项是否存在且未被删除 + const allItem = this.checkedByAll.find(item => item.USER_ID === 'all') + const hasAllItem = allItem && !allItem.IS_DELETED + + if (isAllSelected && !hasAllItem) { + // 全部选中了但全选项不存在,添加全选项 + this.checkedByAll.push({ + NAME: '全选', + IS_DELETED: false, + USER_ID: 'all', + }) + } else if (!isAllSelected && hasAllItem) { + // 不是全部选中但全选项存在,移除全选项 + if (allItem) { + allItem.IS_DELETED = true + } + } + }, removeChecked(value) { this.checkedByAll.forEach(item => { if (item.USER_ID === value.USER_ID) {