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) {