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

View File

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

View File

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