fix: 人选选择穿梭框组件切换部门不过滤已选中数据逻辑,优化布局样式

pull/586/MERGE
GoldenZqqq 2024-11-12 13:25:50 +08:00
parent e451f483c5
commit d03fdecc26
1 changed files with 79 additions and 35 deletions

View File

@ -1,25 +1,27 @@
<template>
<Dialog v-model="dialogVisible" title="人员选择" width="900">
<el-row>
<Dialog v-model="dialogVisible" title="人员选择" width="800">
<el-row class="gap2" v-loading="formLoading">
<el-col :span="6">
<el-tree
ref="treeRef"
:data="deptList"
:expand-on-click-node="false"
:props="defaultProps"
default-expand-all
highlight-current
node-key="id"
@node-click="handleNodeClick"
/>
<ContentWrap class="h-1/1">
<el-tree
ref="treeRef"
:data="deptList"
:expand-on-click-node="false"
:props="defaultProps"
default-expand-all
highlight-current
node-key="id"
@node-click="handleNodeClick"
/>
</ContentWrap>
</el-col>
<el-col :span="17" :offset="1">
<el-col :span="17">
<el-transfer
v-model="selectedUserIdList"
:titles="['未选', '已选']"
filterable
filter-placeholder="搜索成员"
:data="userList"
:data="transferUserList"
:props="{ label: 'nickname', key: 'id' }"
/>
</el-col>
@ -47,62 +49,87 @@ const emit = defineEmits<{
}>()
const { t } = useI18n() //
const message = useMessage() //
const deptList = ref<Tree[]>([]) //
const userList: any = ref([]) //
const allUserList = ref<UserApi.UserVO[]>([]) //
const filteredUserList = ref<UserApi.UserVO[]>([]) //
const selectedUserIdList: any = ref([]) //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const activityId = ref() // TODO @goldenzqqq activityId 使 @submitForm="xxx()"
const activityId = ref()
//
const transferUserList = computed(() => {
//
const selectedUsers = allUserList.value.filter((user: any) =>
selectedUserIdList.value.includes(user.id)
)
//
const filteredUnselectedUsers = filteredUserList.value.filter(
(user: any) => !selectedUserIdList.value.includes(user.id)
)
//
return [...selectedUsers, ...filteredUnselectedUsers]
})
/** 打开弹窗 */
const open = async (id: number, selectedList?: any[]) => {
activityId.value = id
//
resetForm()
//
deptList.value = handleTree(await DeptApi.getSimpleDeptList())
await getUserList()
//
selectedUserIdList.value = selectedList?.map((item: any) => item.id)
//
//
await getAllUserList()
//
filteredUserList.value = [...allUserList.value]
selectedUserIdList.value = selectedList?.map((item: any) => item.id) || []
dialogVisible.value = true
}
/** 获取用户列表 */
const getUserList = async (deptId?: number) => {
/** 获取所有用户列表 */
const getAllUserList = async () => {
try {
// @ts-ignore
// TODO @ simple List
const data = await UserApi.getUserPage({ pageSize: 100, pageNo: 1, deptId })
userList.value = data.list
const data = await UserApi.getSimpleUserList()
allUserList.value = data
} finally {
}
}
/** 获取部门过滤后的用户列表 */
const getUserList = async (deptId?: number) => {
formLoading.value = true
try {
// @ts-ignore
// TODO @ simple List deptId
const data = await UserApi.getUserPage({ pageSize: 100, pageNo: 1, deptId })
//
filteredUserList.value = data.list
} finally {
formLoading.value = false
}
}
/** 提交选择 */
const submitForm = async () => {
//
formLoading.value = true
try {
message.success(t('common.updateSuccess'))
dialogVisible.value = false
const emitUserList = userList.value.filter((user: any) =>
//
const emitUserList = allUserList.value.filter((user: any) =>
selectedUserIdList.value.includes(user.id)
)
//
emit('confirm', activityId.value, emitUserList)
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
deptList.value = []
userList.value = []
allUserList.value = []
filteredUserList.value = []
selectedUserIdList.value = []
}
@ -113,3 +140,20 @@ const handleNodeClick = (row: { [key: string]: any }) => {
defineExpose({ open }) // open
</script>
<style lang="scss" scoped>
:deep() {
.el-transfer {
display: flex;
}
.el-transfer__buttons {
display: flex !important;
flex-direction: column-reverse;
justify-content: center;
gap: 20px;
.el-transfer__button:nth-child(2) {
margin: 0;
}
}
}
</style>