FlowVue/src/views/crm/permission/components/PermissionList.vue

146 lines
4.3 KiB
Vue
Raw Normal View History

2023-11-13 17:49:27 +08:00
<template>
<!-- 操作栏 -->
<el-row justify="end">
2023-11-30 13:42:49 +08:00
<el-button @click="openForm">
2024-01-06 12:29:35 +08:00
<Icon class="mr-5px" icon="fluent:people-team-add-20-filled" />
添加团队成员
2023-11-13 17:49:27 +08:00
</el-button>
2023-11-25 10:42:44 +08:00
<el-button @click="handleUpdate">
2023-11-13 17:49:27 +08:00
<Icon class="mr-5px" icon="ep:edit" />
编辑
</el-button>
<el-button @click="handleDelete">
2023-11-13 17:49:27 +08:00
<Icon class="mr-5px" icon="ep:delete" />
移除
</el-button>
<el-button type="danger" @click="handleQuit"> 退出团队</el-button>
</el-row>
2023-11-30 13:42:49 +08:00
<!-- 列表 -->
<ContentWrap class="mt-10px">
<el-table
v-loading="loading"
:data="list"
:show-overflow-tooltip="true"
:stripe="true"
@selection-change="handleSelectionChange"
>
<!-- TODO @puhui999负责人不允许选中 -->
2023-11-30 13:42:49 +08:00
<el-table-column type="selection" width="55" />
<el-table-column align="center" label="姓名" prop="nickname" />
<el-table-column align="center" label="部门" prop="deptName" />
<el-table-column align="center" label="岗位" prop="postNames" />
<el-table-column align="center" label="权限" prop="level">
<template #default="{ row }">
<dict-tag :type="DICT_TYPE.CRM_PERMISSION_LEVEL" :value="row.level" />
</template>
</el-table-column>
<el-table-column
:formatter="dateFormatter"
align="center"
label="加入时间"
prop="createTime"
/>
</el-table>
</ContentWrap>
2023-11-25 10:42:44 +08:00
<!-- 表单弹窗添加/修改 -->
<CrmPermissionForm ref="formRef" @success="getList" />
2023-11-13 17:49:27 +08:00
</template>
<script lang="ts" setup>
import { dateFormatter } from '@/utils/formatTime'
2023-11-30 13:42:49 +08:00
import { DICT_TYPE } from '@/utils/dict'
2023-11-13 17:49:27 +08:00
import * as PermissionApi from '@/api/crm/permission'
2023-11-30 13:42:49 +08:00
import { PermissionLevelEnum } from '@/api/crm/permission'
2023-11-13 17:49:27 +08:00
import { useUserStoreWithOut } from '@/store/modules/user'
2023-11-30 13:42:49 +08:00
import CrmPermissionForm from './PermissionForm.vue'
2023-11-13 17:49:27 +08:00
defineOptions({ name: 'CrmPermissionList' })
2023-11-13 17:49:27 +08:00
const props = defineProps<{
2023-11-30 13:42:49 +08:00
bizType: number // 业务类型
bizId: number // 业务编号
2023-11-13 17:49:27 +08:00
}>()
2023-11-30 13:42:49 +08:00
const message = useMessage() // 消息
2023-11-13 17:49:27 +08:00
const loading = ref(true) // 列表的加载中
const list = ref<PermissionApi.PermissionVO[]>([]) // 列表的数据
2023-11-19 00:28:22 +08:00
/** 查询列表 */
2023-11-13 17:49:27 +08:00
const getList = async () => {
loading.value = true
try {
2023-11-30 13:42:49 +08:00
list.value = await PermissionApi.getPermissionList({
2023-11-13 17:49:27 +08:00
bizType: props.bizType,
bizId: props.bizId
})
} finally {
loading.value = false
}
}
2023-11-30 13:42:49 +08:00
/** 选中团队成员 */
const multipleSelection = ref<PermissionApi.PermissionVO[]>([]) // 选择的团队成员
2023-11-13 17:49:27 +08:00
const handleSelectionChange = (val: PermissionApi.PermissionVO[]) => {
multipleSelection.value = val
}
2023-11-30 13:42:49 +08:00
/** 添加团队成员 */
2023-11-25 10:42:44 +08:00
const formRef = ref<InstanceType<typeof CrmPermissionForm>>() // 权限表单 Ref
2023-11-30 13:42:49 +08:00
const openForm = () => {
formRef.value?.open('create', props.bizType, props.bizId)
}
/** 编辑团队成员 */
2023-11-25 10:42:44 +08:00
const handleUpdate = () => {
2023-11-13 17:49:27 +08:00
if (multipleSelection.value?.length === 0) {
message.warning('请先选择团队成员后操作!')
return
}
2023-11-30 13:42:49 +08:00
const ids = multipleSelection.value?.map((item) => item.id) as number[]
2023-11-25 10:42:44 +08:00
formRef.value?.open('update', props.bizType, props.bizId, ids)
2023-11-13 17:49:27 +08:00
}
2023-11-25 10:42:44 +08:00
/** 移除团队成员 */
const handleDelete = async () => {
2023-11-13 17:49:27 +08:00
if (multipleSelection.value?.length === 0) {
message.warning('请先选择团队成员后操作!')
return
}
2024-01-06 12:29:35 +08:00
await message.delConfirm('是否删除选择的团队成员?')
2023-11-13 17:49:27 +08:00
const ids = multipleSelection.value?.map((item) => item.id)
2023-11-30 13:42:49 +08:00
await PermissionApi.deletePermissionBatch({
bizType: props.bizType,
bizId: props.bizId,
ids
2023-11-13 17:49:27 +08:00
})
2024-01-06 12:29:35 +08:00
message.success('删除成功')
2023-11-13 17:49:27 +08:00
}
2023-11-25 10:42:44 +08:00
/** 退出团队 */
const userStore = useUserStoreWithOut() // 用户信息缓存
const handleQuit = async () => {
2023-11-13 17:49:27 +08:00
const permission = list.value.find(
2023-11-30 13:42:49 +08:00
(item) => item.userId === userStore.getUser.id && item.level === PermissionLevelEnum.OWNER
2023-11-13 17:49:27 +08:00
)
if (permission) {
message.warning('负责人不能退出团队!')
return
}
2024-01-06 12:29:35 +08:00
await message.confirm('确认退出团队吗?')
const userPermission = list.value.find((item) => item.userId === userStore.getUser.id)
2023-11-30 13:42:49 +08:00
await PermissionApi.deleteSelfPermission(userPermission?.id)
2023-11-13 17:49:27 +08:00
}
2023-11-30 13:42:49 +08:00
/** 监听打开的 bizId + bizType从而加载最新的列表 */
2023-11-13 17:49:27 +08:00
watch(
2023-11-30 13:42:49 +08:00
() => [props.bizId, props.bizType],
2024-01-06 12:29:35 +08:00
(val) => {
if (!val[0]) {
return
}
2023-11-13 17:49:27 +08:00
getList()
},
{ immediate: true, deep: true }
)
</script>