feat:【ele】【crm】初始化界面

This commit is contained in:
YunaiV
2025-11-17 09:28:32 +08:00
parent a273ab2882
commit 32ffc2e556
26 changed files with 2705 additions and 0 deletions

View File

@@ -0,0 +1,194 @@
import type { Ref } from 'vue';
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { DescriptionItemSchema } from '#/components/description';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { formatDateTime } from '@vben/utils';
import { getBusinessPageByCustomer } from '#/api/crm/business';
import { getContactPageByCustomer } from '#/api/crm/contact';
import { BizTypeEnum } from '#/api/crm/permission';
/** 新增/修改的表单 */
export function useFormSchema(
bizId: Ref<number | undefined>,
): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'bizId',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
component: 'Input',
fieldName: 'bizType',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'type',
label: '跟进类型',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.CRM_FOLLOW_UP_TYPE, 'number'),
},
rules: 'required',
},
{
fieldName: 'nextTime',
label: '下次联系时间',
component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'x',
class: '!w-full',
},
rules: 'required',
},
{
fieldName: 'content',
label: '跟进内容',
component: 'Textarea',
rules: 'required',
},
{
fieldName: 'picUrls',
label: '图片',
component: 'ImageUpload',
},
{
fieldName: 'fileUrls',
label: '附件',
component: 'FileUpload',
},
{
fieldName: 'contactIds',
label: '关联联系人',
component: 'ApiSelect',
componentProps: {
api: async () => {
if (!bizId.value) {
return [];
}
const res = await getContactPageByCustomer({
pageNo: 1,
pageSize: 100,
customerId: bizId.value,
});
return res.list;
},
labelField: 'name',
valueField: 'id',
mode: 'multiple',
},
},
{
fieldName: 'businessIds',
label: '关联商机',
component: 'ApiSelect',
componentProps: {
api: async () => {
if (!bizId.value) {
return [];
}
const res = await getBusinessPageByCustomer({
pageNo: 1,
pageSize: 100,
customerId: bizId.value,
});
return res.list;
},
labelField: 'name',
valueField: 'id',
mode: 'multiple',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(
bizType: number,
): VxeTableGridOptions['columns'] {
return [
{
field: 'createTime',
title: '创建时间',
formatter: 'formatDateTime',
},
{ field: 'creatorName', title: '跟进人' },
{
field: 'type',
title: '跟进类型',
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_FOLLOW_UP_TYPE },
},
},
{ field: 'content', title: '跟进内容' },
{
field: 'nextTime',
title: '下次联系时间',
formatter: 'formatDateTime',
},
{
field: 'contacts',
title: '关联联系人',
visible: bizType === BizTypeEnum.CRM_CUSTOMER,
slots: { default: 'contacts' },
},
{
field: 'businesses',
title: '关联商机',
visible: bizType === BizTypeEnum.CRM_CUSTOMER,
slots: { default: 'businesses' },
},
{
field: 'actions',
title: '操作',
slots: { default: 'actions' },
},
];
}
/** 详情页的系统字段 */
export function useFollowUpDetailSchema(): DescriptionItemSchema[] {
return [
{
field: 'ownerUserName',
label: '负责人',
},
{
field: 'contactLastContent',
label: '最后跟进记录',
},
{
field: 'contactLastTime',
label: '最后跟进时间',
render: (val) => formatDateTime(val) as string,
},
{
field: 'creatorName',
label: '创建人',
},
{
field: 'createTime',
label: '创建时间',
render: (val) => formatDateTime(val) as string,
},
{
field: 'updateTime',
label: '更新时间',
render: (val) => formatDateTime(val) as string,
},
];
}

View File

@@ -0,0 +1 @@
export { default as FollowUp } from './index.vue';

View File

@@ -0,0 +1,165 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmFollowUpApi } from '#/api/crm/followup';
import { watch } from 'vue';
import { useRouter } from 'vue-router';
import { useVbenModal } from '@vben/common-ui';
import { ElButton, ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteFollowUpRecord,
getFollowUpRecordPage,
} from '#/api/crm/followup';
import { $t } from '#/locales';
import { useGridColumns } from './data';
import FollowUpRecordForm from './modules/form.vue';
/** 跟进记录列表 */
defineOptions({ name: 'FollowUpRecord' });
const props = defineProps<{
bizId: number;
bizType: number;
}>();
const { push } = useRouter();
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 添加跟进记录 */
function handleCreate() {
formModalApi.setData({ bizId: props.bizId, bizType: props.bizType }).open();
}
/** 删除跟进记录 */
async function handleDelete(row: CrmFollowUpApi.FollowUpRecord) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.id]),
});
try {
await deleteFollowUpRecord(row.id);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 打开联系人详情 */
function openContactDetail(id: number) {
push({ name: 'CrmContactDetail', params: { id } });
}
/** 打开商机详情 */
function openBusinessDetail(id: number) {
push({ name: 'CrmBusinessDetail', params: { id } });
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: FollowUpRecordForm,
destroyOnClose: true,
});
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useGridColumns(props.bizType),
height: 600,
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }) => {
return await getFollowUpRecordPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
bizType: props.bizType,
bizId: props.bizId,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
},
} as VxeTableGridOptions<CrmFollowUpApi.FollowUpRecord>,
});
/** 监听业务 ID 变化 */
watch(
() => props.bizId,
() => {
gridApi.query();
},
);
</script>
<template>
<div>
<FormModal @success="handleRefresh" />
<Grid>
<template #toolbar-tools>
<TableAction
:actions="[
{
label: '写跟进',
type: 'primary',
icon: ACTION_ICON.EDIT,
onClick: handleCreate,
},
]"
/>
</template>
<template #contacts="{ row }">
<ElButton
v-for="contact in row.contacts || []"
:key="`contact-${contact.id}`"
type="primary"
link
class="ml-2"
@click="openContactDetail(contact.id)"
>
{{ contact.name }}
</ElButton>
</template>
<template #businesses="{ row }">
<ElButton
v-for="business in row.businesses || []"
:key="`business-${business.id}`"
type="primary"
link
class="ml-2"
@click="openBusinessDetail(business.id)"
>
{{ business.name }}
</ElButton>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</div>
</template>

View File

@@ -0,0 +1,81 @@
<script lang="ts" setup>
import type { CrmFollowUpApi } from '#/api/crm/followup';
import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { ElMessage } from 'element-plus';
import { useVbenForm } from '#/adapter/form';
import { createFollowUpRecord } from '#/api/crm/followup';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const bizId = ref<number>();
const bizType = ref<number>();
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
formItemClass: 'col-span-2',
labelWidth: 120,
},
layout: 'horizontal',
schema: useFormSchema(bizId),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as CrmFollowUpApi.FollowUpRecord;
try {
await createFollowUpRecord(data);
// 关闭并提示
await modalApi.close();
emit('success');
ElMessage.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
return;
}
// 加载数据
const data = modalApi.getData<CrmFollowUpApi.FollowUpRecord>();
if (!data) {
return;
}
if (data.bizId && data.bizType) {
bizId.value = data.bizId;
bizType.value = data.bizType;
}
modalApi.lock();
try {
// 设置到 values
await formApi.setValues(data);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal title="添加跟进记录" class="w-2/5">
<Form class="mx-4" />
</Modal>
</template>