2023-11-13 17:49:27 +08:00
|
|
|
|
<template>
|
|
|
|
|
<!-- 操作栏 -->
|
2024-01-14 21:48:20 +08:00
|
|
|
|
<el-row v-if="showAction" justify="end">
|
|
|
|
|
<el-button v-if="validateOwnerUser" type="primary" @click="openForm">
|
|
|
|
|
<Icon class="mr-5px" icon="ep:plus" />
|
|
|
|
|
新增
|
2023-11-13 17:49:27 +08:00
|
|
|
|
</el-button>
|
2024-01-14 21:48:20 +08:00
|
|
|
|
<el-button v-if="validateOwnerUser" @click="handleUpdate">
|
2023-11-13 17:49:27 +08:00
|
|
|
|
<Icon class="mr-5px" icon="ep:edit" />
|
|
|
|
|
编辑
|
|
|
|
|
</el-button>
|
2024-01-14 21:48:20 +08:00
|
|
|
|
<el-button v-if="validateOwnerUser" @click="handleDelete">
|
2023-11-13 17:49:27 +08:00
|
|
|
|
<Icon class="mr-5px" icon="ep:delete" />
|
|
|
|
|
移除
|
|
|
|
|
</el-button>
|
2024-01-14 21:48:20 +08:00
|
|
|
|
<el-button v-if="!validateOwnerUser && list.length > 0" type="danger" @click="handleQuit">
|
|
|
|
|
退出团队
|
|
|
|
|
</el-button>
|
2023-11-13 17:49:27 +08:00
|
|
|
|
</el-row>
|
2024-01-14 21:48:20 +08:00
|
|
|
|
<!-- 团队成员展示 -->
|
|
|
|
|
<el-table
|
|
|
|
|
ref="elTableRef"
|
|
|
|
|
v-loading="loading"
|
|
|
|
|
:data="list"
|
|
|
|
|
:show-overflow-tooltip="true"
|
|
|
|
|
:stripe="true"
|
|
|
|
|
class="mt-20px"
|
|
|
|
|
@selection-change="handleSelectionChange"
|
|
|
|
|
>
|
|
|
|
|
<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>
|
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'
|
2024-01-14 21:48:20 +08:00
|
|
|
|
import { ElTable } from 'element-plus'
|
2023-11-13 17:49:27 +08:00
|
|
|
|
import * as PermissionApi from '@/api/crm/permission'
|
|
|
|
|
import { useUserStoreWithOut } from '@/store/modules/user'
|
2023-11-30 13:42:49 +08:00
|
|
|
|
import CrmPermissionForm from './PermissionForm.vue'
|
2024-01-14 21:48:20 +08:00
|
|
|
|
import { DICT_TYPE } from '@/utils/dict'
|
2023-11-13 17:49:27 +08:00
|
|
|
|
|
2023-11-22 15:44:42 +08:00
|
|
|
|
defineOptions({ name: 'CrmPermissionList' })
|
2023-11-30 13:42:49 +08:00
|
|
|
|
|
|
|
|
|
const message = useMessage() // 消息
|
2024-01-14 21:48:20 +08:00
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
bizType: number // 模块类型
|
|
|
|
|
bizId: number | undefined // 模块数据编号
|
|
|
|
|
showAction: boolean //是否展示操作按钮
|
|
|
|
|
}>()
|
2023-11-13 17:49:27 +08:00
|
|
|
|
const loading = ref(true) // 列表的加载中
|
2023-11-22 15:44:42 +08:00
|
|
|
|
const list = ref<PermissionApi.PermissionVO[]>([]) // 列表的数据
|
2024-01-14 21:48:20 +08:00
|
|
|
|
const formData = ref({
|
|
|
|
|
ownerUserId: 0
|
|
|
|
|
})
|
|
|
|
|
const userStore = useUserStoreWithOut() // 用户信息缓存
|
2023-11-19 00:28:22 +08:00
|
|
|
|
|
|
|
|
|
/** 查询列表 */
|
2023-11-13 17:49:27 +08:00
|
|
|
|
const getList = async () => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
2024-01-14 21:48:20 +08:00
|
|
|
|
const data = await PermissionApi.getPermissionList({
|
2023-11-13 17:49:27 +08:00
|
|
|
|
bizType: props.bizType,
|
|
|
|
|
bizId: props.bizId
|
|
|
|
|
})
|
2024-01-14 21:48:20 +08:00
|
|
|
|
list.value = data
|
|
|
|
|
const permission = list.value.find(
|
|
|
|
|
(item) =>
|
|
|
|
|
item.userId === userStore.getUser.id &&
|
|
|
|
|
item.level === PermissionApi.PermissionLevelEnum.OWNER
|
|
|
|
|
)
|
|
|
|
|
if (permission) {
|
|
|
|
|
formData.value.ownerUserId = userStore.getUser.id
|
|
|
|
|
}
|
2023-11-13 17:49:27 +08:00
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-22 15:44:42 +08:00
|
|
|
|
const multipleSelection = ref<PermissionApi.PermissionVO[]>([]) // 选择的团队成员
|
2024-01-14 21:48:20 +08:00
|
|
|
|
const elTableRef = ref<InstanceType<typeof ElTable>>()
|
2023-11-13 17:49:27 +08:00
|
|
|
|
const handleSelectionChange = (val: PermissionApi.PermissionVO[]) => {
|
2024-01-14 21:48:20 +08:00
|
|
|
|
if (val.findIndex((item) => item.level === PermissionApi.PermissionLevelEnum.OWNER) !== -1) {
|
|
|
|
|
message.warning('不能选择负责人!')
|
|
|
|
|
elTableRef.value?.clearSelection()
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-11-13 17:49:27 +08:00
|
|
|
|
multipleSelection.value = val
|
|
|
|
|
}
|
2023-11-22 15:44:42 +08:00
|
|
|
|
|
2023-11-30 13:42:49 +08:00
|
|
|
|
/** 编辑团队成员 */
|
2024-01-14 21:48:20 +08:00
|
|
|
|
const formRef = ref<InstanceType<typeof CrmPermissionForm>>() // 权限表单 Ref
|
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
|
|
|
|
|
}
|
2024-01-14 21:48:20 +08:00
|
|
|
|
const ids = multipleSelection.value?.map((item) => item.id) as unknown as number[]
|
|
|
|
|
formRef.value?.open('update', props.bizType, props.bizId!, ids)
|
2023-11-13 17:49:27 +08:00
|
|
|
|
}
|
2023-11-22 15:44:42 +08:00
|
|
|
|
|
2023-11-25 10:42:44 +08:00
|
|
|
|
/** 移除团队成员 */
|
2023-11-22 15:44:42 +08:00
|
|
|
|
const handleDelete = async () => {
|
2023-11-13 17:49:27 +08:00
|
|
|
|
if (multipleSelection.value?.length === 0) {
|
|
|
|
|
message.warning('请先选择团队成员后操作!')
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-01-14 21:48:20 +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({
|
2023-11-14 11:26:07 +08:00
|
|
|
|
bizType: props.bizType,
|
|
|
|
|
bizId: props.bizId,
|
|
|
|
|
ids
|
2023-11-13 17:49:27 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
2023-11-22 15:44:42 +08:00
|
|
|
|
|
2024-01-14 21:48:20 +08:00
|
|
|
|
/** 添加团队成员 */
|
|
|
|
|
const openForm = () => {
|
|
|
|
|
formRef.value?.open('create', props.bizType, props.bizId!)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验负责人权限和编辑权限
|
|
|
|
|
const validateOwnerUser = ref(false)
|
|
|
|
|
const validateWrite = ref(false)
|
|
|
|
|
const isPool = ref(false)
|
|
|
|
|
watch(
|
|
|
|
|
list,
|
|
|
|
|
(newArr) => {
|
|
|
|
|
isPool.value = false
|
|
|
|
|
if (newArr?.length > 0) {
|
|
|
|
|
isPool.value = !list.value.some(
|
|
|
|
|
(item) => item.level === PermissionApi.PermissionLevelEnum.OWNER
|
|
|
|
|
)
|
|
|
|
|
validateOwnerUser.value = false
|
|
|
|
|
validateWrite.value = false
|
|
|
|
|
const userId = userStore.getUser?.id
|
|
|
|
|
list.value
|
|
|
|
|
.filter((item) => item.userId === userId)
|
|
|
|
|
.forEach((item) => {
|
|
|
|
|
if (item.level === PermissionApi.PermissionLevelEnum.OWNER) {
|
|
|
|
|
validateOwnerUser.value = true
|
|
|
|
|
validateWrite.value = true
|
|
|
|
|
} else if (item.level === PermissionApi.PermissionLevelEnum.WRITE) {
|
|
|
|
|
validateWrite.value = true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
isPool.value = true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
defineExpose({ openForm, validateOwnerUser, validateWrite, isPool })
|
2023-11-25 10:42:44 +08:00
|
|
|
|
/** 退出团队 */
|
2023-11-14 11:26:07 +08:00
|
|
|
|
const handleQuit = async () => {
|
2023-11-13 17:49:27 +08:00
|
|
|
|
const permission = list.value.find(
|
2024-01-14 21:48:20 +08:00
|
|
|
|
(item) =>
|
|
|
|
|
item.userId === userStore.getUser.id && item.level === PermissionApi.PermissionLevelEnum.OWNER
|
2023-11-13 17:49:27 +08:00
|
|
|
|
)
|
|
|
|
|
if (permission) {
|
|
|
|
|
message.warning('负责人不能退出团队!')
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-11-14 11:26:07 +08:00
|
|
|
|
const userPermission = list.value.find((item) => item.userId === userStore.getUser.id)
|
2024-01-14 21:48:20 +08:00
|
|
|
|
if (userPermission) {
|
|
|
|
|
await PermissionApi.deleteSelfPermission(userPermission.id!)
|
|
|
|
|
}
|
2023-11-13 17:49:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(
|
2024-01-14 21:48:20 +08:00
|
|
|
|
() => props.bizId,
|
|
|
|
|
(bizId) => {
|
|
|
|
|
if (!bizId) {
|
2024-01-06 12:29:35 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2023-11-13 17:49:27 +08:00
|
|
|
|
getList()
|
|
|
|
|
},
|
|
|
|
|
{ immediate: true, deep: true }
|
|
|
|
|
)
|
|
|
|
|
</script>
|