CRM 客户管理 权限优化

pull/853/head
wersd 2025-06-12 22:43:09 +08:00
parent 7bd962b740
commit dc245aa345
2 changed files with 545 additions and 0 deletions

View File

@ -0,0 +1,352 @@
<!-- 某个记录的跟进记录列表目前主要用于 CRM 客户商机等详情界面 -->
<template>
<!-- 搜索栏 -->
<el-form :inline="true" :model="queryParams" class="mb-10px">
<el-form-item label="跟进内容">
<el-input v-model="queryParams.content" placeholder="请输入跟进内容" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="跟进方式">
<el-select v-model="queryParams.type" placeholder="请选择跟进方式" clearable>
<el-option v-for="dict in getIntDictOptions(DICT_TYPE.CRM_FOLLOW_UP_TYPE)" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item>
<el-button v-hasPermi="['crm:follow-up-record:query']" type="primary" @click="handleQuery">
<Icon icon="ep:search" class="mr-5px" />搜索
</el-button>
<el-button @click="resetQuery">
<Icon icon="ep:refresh" class="mr-5px" />重置
</el-button>
<el-button v-hasPermi="['crm:follow-up-record:create']" @click="openForm">
<Icon icon="ep:edit" class="mr-5px" />写跟进
</el-button>
</el-form-item>
</el-form>
<!-- 跟进记录时间线 -->
<el-timeline>
<el-timeline-item
v-for="(item, index) in list"
:key="item.id || index"
:timestamp="formatDate(item.createTime)"
placement="top"
>
<span>跟进人</span>{{ item.creatorName }}
<template #timestamp>
<div style="color:#999;font-size:13px;margin-bottom:2px;">跟进时间</div>
<span>{{ formatDate(item.createTime) }}</span>
</template>
<div class="el-timeline-right-content">
<div class="followup-meta mb-5px">
<template v-if="item.contacts && item.contacts.length">
<span class="meta-label">联系人</span>
<el-link
v-for="contact in item.contacts"
:key="contact.id"
:underline="false"
type="primary"
@click="openContactDetail(contact.id)"
class="ml-5px"
>
{{ contact.name }}
</el-link>
<span style="margin: 0 8px;"> </span>
</template>
<span class="meta-label">跟进方式</span><dict-tag :type="DICT_TYPE.CRM_FOLLOW_UP_TYPE" :value="item.type" class="mr-10px" />
</div>
<!-- 操作按钮统一放右上角 -->
<div class="followup-action-btns">
<el-button v-hasPermi="['crm:follow-up-record:update']" link class="followup-action-btn edit" @click="openForm('update', item.id)">
<Icon icon="ep:edit" class="mr-3px" /> 编辑
</el-button>
<el-button v-hasPermi="['crm:follow-up-record:delete']" link class="followup-action-btn delete" @click="handleDelete(item.id)">
<Icon icon="ep:delete" class="mr-3px" /> 删除
</el-button>
</div>
<span class="follow-row" v-if="!/<[a-z][\s\S]*>/i.test(item.content)">{{ item.content }}</span>
<div class="follow-row" v-else v-html="'跟进内容:' + item.content"></div>
<!-- 图片直接展示 -->
<div v-if="item.picUrls && item.picUrls.length" class="followup-img-list follow-row mt-10px">
<el-image
v-for="url in item.picUrls"
:key="url"
:src="url"
style="width: 120px; height: 120px; object-fit: contain; border: 1px solid #eee; border-radius: 4px; margin-right: 8px;"
:preview-src-list="item.picUrls"
/>
</div>
<!-- 附件链接展示 -->
<div v-if="item.fileUrls && item.fileUrls.length" class="followup-file-list follow-row mt-5px">
<span style="font-weight: bold;">附件:</span>
<el-link
v-for="url in item.fileUrls"
:key="url"
:href="url"
target="_blank"
type="primary"
style="margin-right: 12px;"
>
{{ url.substring(url.lastIndexOf('/')+1) }}
</el-link>
</div>
</div>
<template #dot>
<span style="background-color: #67C23A;" class="dot-node-style">
{{ item.creatorName ? item.creatorName[0] : '' }}
</span>
</template>
</el-timeline-item>
</el-timeline>
<!-- 分页 -->
<Pagination
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList"
/>
<!-- 表单弹窗添加/修改 -->
<FollowUpRecordForm ref="formRef" @success="getList" />
</template>
<script lang="ts" setup>
import { formatDate } from '@/utils/formatTime'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { FollowUpRecordApi, FollowUpRecordVO } from '@/api/crm/followup'
import FollowUpRecordForm from './FollowUpRecordForm.vue'
import { BizTypeEnum } from '@/api/crm/permission'
/** 跟进记录列表 */
defineOptions({ name: 'FollowUpRecord' })
const props = defineProps<{
bizType: number
bizId?: number // bizId
}>()
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const list = ref<FollowUpRecordVO[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
bizType: 0,
bizId: undefined as number | undefined, //
content: '',
type: undefined
})
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await FollowUpRecordApi.getFollowUpRecordPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 添加/修改操作 */
const formRef = ref<InstanceType<typeof FollowUpRecordForm>>()
//
const openForm = (type: 'create' | 'update' = 'create', id?: number) => {
// bizId
if (typeof props.bizId === 'number') {
if (type === 'update' && id) {
formRef.value?.open(props.bizType, props.bizId, id)
} else {
formRef.value?.open(props.bizType, props.bizId)
}
} else {
if (type === 'update' && id) {
formRef.value?.open(props.bizType, undefined, id)
} else {
formRef.value?.open(props.bizType, undefined)
}
}
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await FollowUpRecordApi.deleteFollowUpRecord(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 打开联系人详情 */
const { push } = useRouter()
const openContactDetail = (id: number) => {
push({ name: 'CrmContactDetail', params: { id } })
}
/** 打开商机详情 */
const openBusinessDetail = (id: number) => {
push({ name: 'CrmBusinessDetail', params: { id } })
}
/** 文件查看弹窗 */
const fileDialogVisible = ref(false)
const fileDialogList = ref<string[]>([])
const fileDialogType = ref<'图片' | '附件'>('图片')
const fileDialogTitle = computed(() => fileDialogType.value === '图片' ? '查看图片' : '查看附件')
function openFileDialog(list: string[], type: '图片' | '附件') {
fileDialogList.value = list
fileDialogType.value = type
fileDialogVisible.value = true
}
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
const resetQuery = () => {
queryParams.content = ''
queryParams.type = undefined
handleQuery()
}
watch(
() => props.bizId,
() => {
queryParams.bizType = props.bizType
queryParams.bizId = typeof props.bizId === 'number' ? props.bizId : undefined
getList()
},
{ immediate: true }
)
</script>
<style lang="scss" scoped>
// 线 OperateLogV2
:deep(.el-timeline) {
margin: 10px 0 0 30px;
}
:deep(.el-timeline-item__wrapper) {
position: relative;
top: 0;
}
:deep(.el-timeline-item__timestamp) {
position: static !important;
display: block;
margin-bottom: 4px;
color: #999;
font-size: 13px;
left: unset;
top: unset;
text-align: left;
}
:deep(.el-timeline-right-content) {
display: flex;
flex-direction: column;
align-items: flex-start;
min-height: 30px;
padding: 10px;
background-color: #fff;
border-radius: 4px;
margin-bottom: 8px;
position: relative;
}
.followup-img-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.followup-file-list {
margin-top: 5px;
}
.followup-meta {
display: flex;
flex-wrap: wrap;
align-items: center;
margin-bottom: 5px;
}
.follow-row {
margin-bottom: 5px;
color: #333;
font-size: 14px;
}
.dot-node-style {
position: absolute;
left: 0px;
display: flex;
width: 20px;
height: 20px;
font-size: 10px;
color: #fff;
border-radius: 50%;
justify-content: center;
align-items: center;
}
.meta-label {
margin-right: 4px;
font-weight: bold;
}
.followup-delete-btn {
color: #f56c6c !important;
font-weight: bold;
font-size: 14px;
transition: background 0.2s, color 0.2s;
border: none;
background: #fef0f0;
border-radius: 4px;
padding: 2px 10px;
margin: 10px 0 0 0;
&:hover {
background: #fef0f0;
color: #c0392b !important;
}
.icon {
font-size: 15px;
vertical-align: middle;
}
}
.followup-action-btns {
position: absolute;
top: 10px;
right: 16px;
display: flex;
gap: 8px;
z-index: 2;
}
.followup-action-btn {
font-weight: bold;
font-size: 14px;
border: none;
background: transparent;
border-radius: 4px;
padding: 2px 10px;
transition: background 0.2s, color 0.2s;
box-shadow: none;
&.edit {
color: #409eff !important;
&:hover {
color: #337ecc !important;
background: #ecf5ff;
}
}
&.delete {
color: #f56c6c !important;
&:hover {
color: #c0392b !important;
background: #fef0f0;
}
}
.icon {
font-size: 15px;
vertical-align: middle;
}
}
</style>

View File

@ -0,0 +1,193 @@
<!-- 跟进记录的添加表单 -->
<template>
<Dialog v-model="dialogVisible" title="添加跟进记录" width="50%">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
:rules="formRules"
label-width="120px"
>
<el-row>
<el-col :span="12">
<el-form-item label="跟进方式" prop="type">
<el-select v-model="formData.type" placeholder="请选择跟进">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_FOLLOW_UP_TYPE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12" v-if="formData.bizType == BizTypeEnum.CRM_CUSTOMER">
<el-form-item label="选择联系人" prop="contactIds">
<el-select v-model="formData.contactIds" filterable placeholder="请选择联系人">
<el-option v-for="item in contactOptions" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="跟进内容" prop="content">
<Editor v-model="formData.content" height="150px" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="附件" prop="fileUrls">
<UploadFile v-model="formData.fileUrls" class="min-w-80px" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { FollowUpRecordApi, FollowUpRecordVO } from '@/api/crm/followup'
import { BizTypeEnum } from '@/api/crm/permission'
import * as ContactApi from '@/api/crm/contact'
defineOptions({ name: 'FollowUpRecordForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
//
interface FollowUpFormData {
bizType?: number;
bizId?: number;
type?: number;
content?: string;
nextTime?: any;
picUrls?: string[];
fileUrls?: string[];
businesses?: any[];
contacts?: any[];
contactIds?: number[];
}
const formData = ref<FollowUpFormData>({
bizType: undefined,
bizId: undefined,
type: undefined,
content: '',
nextTime: undefined,
picUrls: [],
fileUrls: [],
businesses: [],
contacts: [],
contactIds: []
})
const formRules = reactive({
type: [{ required: true, message: '跟进类型不能为空', trigger: 'change' }],
content: [{ required: true, message: '跟进内容不能为空', trigger: 'blur' }],
contactIds: [{ required: true, message: '联系人不能为空', trigger: 'change' }]
})
const formRef = ref() // Ref
const contactOptions = ref<ContactApi.ContactVO[]>([])
const formType = ref('') // create - update -
watch(
() => formData.value.bizId,
async (val) => {
if (formData.value.bizType === BizTypeEnum.CRM_CUSTOMER && val) {
//
const res = await ContactApi.getContactPageByCustomer({ customerId: val, pageSize: 100 })
contactOptions.value = res.list || []
//
if (contactOptions.value.length > 0) {
formData.value.contactIds = [contactOptions.value[0].id]
} else {
formData.value.contactIds = []
}
} else {
contactOptions.value = []
formData.value.contactIds = []
}
},
{ immediate: true }
)
/** 打开弹窗 */
const open = async (bizType: number, bizId: number, id?: number) => {
dialogVisible.value = true
resetForm()
formData.value.bizType = bizType
formData.value.bizId = bizId
if (id) {
formType.value = 'update'
formLoading.value = true
try {
const data = await FollowUpRecordApi.getFollowUpRecord(id)
Object.assign(formData.value, data)
} finally {
formLoading.value = false
}
} else {
formType.value = 'create'
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
// contactIds
const submitForm = async () => {
await formRef.value.validate()
formLoading.value = true
try {
// contactIds
let contactIds = formData.value.contactIds
if (!Array.isArray(contactIds)) {
contactIds = contactIds !== undefined && contactIds !== null ? [contactIds] : []
}
const data = {
...formData.value,
contactIds,
businessIds: (formData.value.businesses || []).map((item: any) => item.id)
} as unknown as FollowUpRecordVO
if (formType.value === 'create') {
await FollowUpRecordApi.createFollowUpRecord(data)
message.success(t('common.createSuccess'))
} else {
await FollowUpRecordApi.updateFollowUpRecord(data)
message.success(t('common.updateSuccess'))
}
message.success(t('common.createSuccess'))
dialogVisible.value = false
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formRef.value?.resetFields()
formData.value = {
bizId: undefined,
bizType: undefined,
type: undefined,
content: '',
nextTime: undefined,
picUrls: [],
fileUrls: [],
businesses: [],
contacts: [],
contactIds: []
}
}
</script>