crm-团队成员:完善团队成员通用组件封装

This commit is contained in:
puhui999 2023-11-14 11:26:07 +08:00
parent 27c9a0f32d
commit 015a1640c1
4 changed files with 65 additions and 39 deletions

View File

@ -1,14 +1,14 @@
import request from '@/config/axios' import request from '@/config/axios'
export interface PermissionVO { export interface PermissionVO {
id: number // 数据权限编号 id?: number // 数据权限编号
userId: number // 用户编号 userId: number | undefined // 用户编号
bizType: number // Crm 类型 bizType: number | undefined // Crm 类型
bizId: number // Crm 类型数据编号 bizId: number | undefined // Crm 类型数据编号
level: number // 权限级别 level: number | undefined // 权限级别
deptName: string // 部门名称 deptName?: string // 部门名称
nickname: string // 用户昵称 nickname?: string // 用户昵称
postNames: string // 岗位名称数组 postNames?: string // 岗位名称数组
} }
// 查询团队成员列表 // 查询团队成员列表
@ -21,8 +21,8 @@ export const createPermission = async (data: PermissionVO) => {
return await request.post({ url: `/crm/permission/add`, data }) return await request.post({ url: `/crm/permission/add`, data })
} }
// 修改团队成员 // 修改团队成员权限级别
export const updatePermission = async (data: PermissionVO) => { export const updatePermission = async (data) => {
return await request.put({ url: `/crm/permission/update`, data }) return await request.put({ url: `/crm/permission/update`, data })
} }
@ -30,3 +30,18 @@ export const updatePermission = async (data: PermissionVO) => {
export const deletePermission = async (params) => { export const deletePermission = async (params) => {
return await request.delete({ url: '/crm/permission/delete', params }) return await request.delete({ url: '/crm/permission/delete', params })
} }
// 退出团队
export const quitTeam = async (id) => {
return await request.delete({ url: '/crm/permission/quit-team?id=' + id })
}
// 领取公海数据
export const receive = async (data: { bizType: number; bizId: number }) => {
return await request.put({ url: `/crm/permission/receive`, data })
}
// 数据放入公海
export const putPool = async (data: { bizType: number; bizId: number }) => {
return await request.put({ url: `/crm/permission/put-pool`, data })
}

View File

@ -1,5 +1,5 @@
<template> <template>
<Dialog v-model="dialogVisible" :title="dialogTitle"> <Dialog v-model="dialogVisible" :title="dialogTitle" width="30%">
<el-form <el-form
ref="formRef" ref="formRef"
v-loading="formLoading" v-loading="formLoading"
@ -11,16 +11,16 @@
<el-select v-model="formData.userId"> <el-select v-model="formData.userId">
<el-option <el-option
v-for="item in userOptions" v-for="item in userOptions"
:key="parseInt(item.id)" :key="item.id"
:label="item.nickname" :label="item.nickname"
:value="parseInt(item.id)" :value="item.id"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="权限级别" prop="level"> <el-form-item label="权限级别" prop="level">
<el-radio-group v-model="formData.level"> <el-radio-group v-model="formData.level">
<el-radio label="2">只读</el-radio> <el-radio :label="CrmPermissionLevelEnum.READ">只读</el-radio>
<el-radio label="3">读写</el-radio> <el-radio :label="CrmPermissionLevelEnum.WRITE">读写</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -32,6 +32,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import * as UserApi from '@/api/system/user' import * as UserApi from '@/api/system/user'
import * as PermissionApi from '@/api/crm/permission'
import { CrmPermissionLevelEnum } from './index'
defineOptions({ name: 'CrmPermissionForm' }) defineOptions({ name: 'CrmPermissionForm' })
const { t } = useI18n() // const { t } = useI18n() //
@ -42,7 +44,7 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const userOptions = ref<UserApi.UserVO[]>([]) // const userOptions = ref<UserApi.UserVO[]>([]) //
const formData = ref({ const formData = ref<PermissionApi.PermissionVO & { ids?: number[] }>({
userId: undefined, // userId: undefined, //
bizType: undefined, // Crm bizType: undefined, // Crm
bizId: undefined, // Crm bizId: undefined, // Crm
@ -55,17 +57,15 @@ const formRules = reactive({
const formRef = ref() // Ref const formRef = ref() // Ref
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (type: 'create' | 'update', bizType: number, bizId: number, id?: number) => { const open = async (type: 'create' | 'update', bizType: number, bizId: number, ids?: number[]) => {
dialogVisible.value = true dialogVisible.value = true
dialogTitle.value = t('action.' + type) + '团队成员' dialogTitle.value = t('action.' + type) + '团队成员'
formType.value = type formType.value = type
resetForm(bizType, bizId) resetForm(bizType, bizId)
// //
if (id) { if (ids) {
formData.value.id = id formData.value.ids = ids
} }
//
userOptions.value = await UserApi.getSimpleUserList()
} }
defineExpose({ open }) // open defineExpose({ open }) // open
@ -81,8 +81,10 @@ const submitForm = async () => {
try { try {
const data = formData.value const data = formData.value
if (formType.value === 'create') { if (formType.value === 'create') {
await PermissionApi.createPermission(unref(data))
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await PermissionApi.updatePermission(unref(data))
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
dialogVisible.value = false dialogVisible.value = false
@ -95,12 +97,16 @@ const submitForm = async () => {
/** 重置表单 */ /** 重置表单 */
const resetForm = (bizType: number, bizId: number) => { const resetForm = (bizType: number, bizId: number) => {
formRef.value?.resetFields()
formData.value = { formData.value = {
userId: undefined, // userId: undefined, //
bizType, // Crm bizType, // Crm
bizId, // Crm bizId, // Crm
level: undefined // level: undefined //
} }
formRef.value?.resetFields()
} }
onMounted(async () => {
//
userOptions.value = await UserApi.getSimpleUserList()
})
</script> </script>

View File

@ -25,10 +25,10 @@
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
<el-table-column align="center" label="姓名" prop="mobile" /> <el-table-column align="center" label="姓名" prop="nickname" />
<el-table-column align="center" label="部门" prop="detailAddress" /> <el-table-column align="center" label="部门" prop="deptName" />
<el-table-column align="center" label="岗位" prop="detailAddress" /> <el-table-column align="center" label="岗位" prop="postNames" />
<el-table-column align="center" label="权限级别" prop="creatorName" /> <el-table-column align="center" label="权限级别" prop="level" />
<el-table-column :formatter="dateFormatter" align="center" label="加入时间" prop="createTime" /> <el-table-column :formatter="dateFormatter" align="center" label="加入时间" prop="createTime" />
</el-table> </el-table>
<CrmPermissionForm ref="crmPermissionFormRef" /> <CrmPermissionForm ref="crmPermissionFormRef" />
@ -39,6 +39,7 @@ import { ElTable } from 'element-plus'
import * as PermissionApi from '@/api/crm/permission' import * as PermissionApi from '@/api/crm/permission'
import { useUserStoreWithOut } from '@/store/modules/user' import { useUserStoreWithOut } from '@/store/modules/user'
import CrmPermissionForm from './CrmPermissionForm.vue' import CrmPermissionForm from './CrmPermissionForm.vue'
import { CrmPermissionLevelEnum } from './index'
defineOptions({ name: 'CrmTeam' }) defineOptions({ name: 'CrmTeam' })
const props = defineProps<{ const props = defineProps<{
@ -65,14 +66,14 @@ const handleSelectionChange = (val: PermissionApi.PermissionVO[]) => {
multipleSelection.value = val multipleSelection.value = val
} }
const message = useMessage() const message = useMessage()
const crmPermissionFormRef = ref<InstanceType<typeof CrmPermissionForm | null>>(null) const crmPermissionFormRef = ref<InstanceType<typeof CrmPermissionForm>>()
const handleEdit = () => { const handleEdit = () => {
if (multipleSelection.value?.length === 0) { if (multipleSelection.value?.length === 0) {
message.warning('请先选择团队成员后操作!') message.warning('请先选择团队成员后操作!')
return return
} }
const ids = multipleSelection.value?.map((item) => item.id) const ids = multipleSelection.value?.map((item) => item.id)
crmPermissionFormRef.value?.open('update', props.bizType, props.bizId, ids[0]) crmPermissionFormRef.value?.open('update', props.bizType, props.bizId, ids)
} }
const handleRemove = async () => { const handleRemove = async () => {
if (multipleSelection.value?.length === 0) { if (multipleSelection.value?.length === 0) {
@ -81,13 +82,10 @@ const handleRemove = async () => {
} }
await message.delConfirm() await message.delConfirm()
const ids = multipleSelection.value?.map((item) => item.id) const ids = multipleSelection.value?.map((item) => item.id)
ids?.forEach((id) => { await PermissionApi.deletePermission({
// TODO
PermissionApi.deletePermission({
bizType: props.bizType, bizType: props.bizType,
bizId: props.bizId, bizId: props.bizId,
id ids
})
}) })
} }
const handleAdd = () => { const handleAdd = () => {
@ -95,14 +93,16 @@ const handleAdd = () => {
} }
const userStore = useUserStoreWithOut() const userStore = useUserStoreWithOut()
const handleQuit = () => { const handleQuit = async () => {
const permission = list.value.find( const permission = list.value.find(
(item) => item.userId === userStore.getUser.id && item.level === 1 (item) => item.userId === userStore.getUser.id && item.level === CrmPermissionLevelEnum.OWNER
) )
if (permission) { if (permission) {
message.warning('负责人不能退出团队!') message.warning('负责人不能退出团队!')
return return
} }
const userPermission = list.value.find((item) => item.userId === userStore.getUser.id)
await PermissionApi.quitTeam(userPermission?.id)
} }
watch( watch(
@ -113,4 +113,3 @@ watch(
{ immediate: true, deep: true } { immediate: true, deep: true }
) )
</script> </script>
<style lang="scss" scoped></style>

View File

@ -8,4 +8,10 @@ enum CrmBizTypeEnum {
CRM_CONTRACT = 6 // 合同 CRM_CONTRACT = 6 // 合同
} }
export { CrmTeam, CrmBizTypeEnum } enum CrmPermissionLevelEnum {
OWNER = 1, // 负责人
READ = 2, // 读
WRITE = 3 // 写
}
export { CrmTeam, CrmBizTypeEnum, CrmPermissionLevelEnum }