perf: crm

This commit is contained in:
xingyu4j
2025-05-29 17:33:05 +08:00
parent b4a77266a1
commit 45bcc79241
13 changed files with 785 additions and 283 deletions

View File

@@ -0,0 +1,276 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { getSimpleBusinessList } from '#/api/crm/business';
import { getSimpleContactList } from '#/api/crm/contact';
import { getCustomerSimpleList } from '#/api/crm/customer';
import { floatToFixed2 } from '#/utils';
import { DICT_TYPE } from '#/utils/dict';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'no',
label: '合同编号',
component: 'Input',
rules: 'required',
componentProps: {
placeholder: '请输入合同编号',
},
},
{
fieldName: 'name',
label: '合同名称',
component: 'Input',
rules: 'required',
componentProps: {
placeholder: '请输入合同名称',
},
},
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
rules: 'required',
componentProps: {
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
},
{
fieldName: 'businessId',
label: '商机',
component: 'ApiSelect',
rules: 'required',
componentProps: {
api: getSimpleBusinessList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择商机',
},
},
{
fieldName: 'totalPrice',
label: '合同金额',
component: 'InputNumber',
rules: 'required',
componentProps: {
placeholder: '请输入合同金额',
min: 0,
precision: 2,
},
},
{
fieldName: 'orderDate',
label: '下单时间',
component: 'DatePicker',
rules: 'required',
componentProps: {
placeholder: '请选择下单时间',
},
},
{
fieldName: 'startTime',
label: '合同开始时间',
component: 'DatePicker',
rules: 'required',
componentProps: {
placeholder: '请选择合同开始时间',
},
},
{
fieldName: 'endTime',
label: '合同结束时间',
component: 'DatePicker',
rules: 'required',
componentProps: {
placeholder: '请选择合同结束时间',
},
},
{
fieldName: 'signContactId',
label: '客户签约人',
component: 'ApiSelect',
rules: 'required',
componentProps: {
api: getSimpleContactList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户签约人',
},
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
rows: 4,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'no',
label: '合同编号',
component: 'Input',
},
{
fieldName: 'name',
label: '合同名称',
component: 'Input',
},
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
componentProps: {
api: getCustomerSimpleList,
labelField: 'name',
valueField: 'id',
placeholder: '请选择客户',
},
},
];
}
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
title: '合同编号',
field: 'no',
width: 150,
fixed: 'left',
},
{
title: '合同名称',
field: 'name',
width: 150,
fixed: 'left',
slots: { default: 'name' },
},
{
title: '客户名称',
field: 'customerName',
width: 150,
slots: { default: 'customerName' },
},
{
title: '商机名称',
field: 'businessName',
width: 150,
slots: { default: 'businessName' },
},
{
title: '合同金额(元)',
field: 'totalPrice',
width: 150,
formatter: 'formatNumber',
},
{
title: '下单时间',
field: 'orderDate',
width: 150,
formatter: 'formatDateTime',
},
{
title: '合同开始时间',
field: 'startTime',
width: 150,
formatter: 'formatDateTime',
},
{
title: '合同结束时间',
field: 'endTime',
width: 150,
formatter: 'formatDateTime',
},
{
title: '客户签约人',
field: 'signContactName',
width: 150,
slots: { default: 'signContactName' },
},
{
title: '公司签约人',
field: 'signUserName',
width: 150,
},
{
title: '已回款金额(元)',
field: 'totalReceivablePrice',
width: 150,
formatter: 'formatNumber',
},
{
title: '未回款金额(元)',
field: 'unpaidPrice',
width: 150,
formatter: ({ row }) => {
return floatToFixed2(row.totalPrice - row.totalReceivablePrice);
},
},
{
title: '最后跟进时间',
field: 'contactLastTime',
width: 150,
formatter: 'formatDateTime',
},
{
title: '负责人',
field: 'ownerUserName',
width: 150,
},
{
title: '所属部门',
field: 'ownerUserDeptName',
width: 150,
},
{
title: '更新时间',
field: 'updateTime',
width: 150,
formatter: 'formatDateTime',
},
{
title: '创建时间',
field: 'createTime',
width: 150,
formatter: 'formatDateTime',
},
{
title: '创建人',
field: 'creatorName',
width: 150,
},
{
title: '备注',
field: 'remark',
width: 150,
},
{
title: '合同状态',
field: 'auditStatus',
fixed: 'right',
width: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_AUDIT_STATUS },
},
},
{
title: '操作',
field: 'actions',
fixed: 'right',
width: 130,
slots: { default: 'actions' },
},
];
}

View File

@@ -1,38 +1,265 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmContractApi } from '#/api/crm/contract';
import { Button } from 'ant-design-vue';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message, Tabs } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteContract,
exportContract,
getContractPage,
submitContract,
} from '#/api/crm/contract';
import { DocAlert } from '#/components/doc-alert';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const { push } = useRouter();
const sceneType = ref('1');
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportContract(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '合同.xls', source: data });
}
/** 创建合同 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑合同 */
function handleEdit(row: CrmContractApi.Contract) {
formModalApi.setData(row).open();
}
/** 删除合同 */
async function handleDelete(row: CrmContractApi.Contract) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
});
try {
await deleteContract(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
} finally {
hideLoading();
}
}
/** 提交审核 */
async function handleSubmit(row: CrmContractApi.Contract) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.submitting', [row.name]),
key: 'action_key_msg',
});
try {
await submitContract(row.id as number);
message.success({
content: $t('ui.actionMessage.submitSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
} finally {
hideLoading();
}
}
/** 查看合同详情 */
function handleDetail(row: CrmContractApi.Contract) {
push({ name: 'CrmContractDetail', params: { id: row.id } });
}
/** 查看客户详情 */
function handleCustomerDetail(row: CrmContractApi.Contract) {
push({ name: 'CrmCustomerDetail', params: { id: row.customerId } });
}
/** 查看联系人详情 */
function handleContactDetail(row: CrmContractApi.Contract) {
push({ name: 'CrmContactDetail', params: { id: row.signContactId } });
}
/** 查看商机详情 */
function handleBusinessDetail(row: CrmContractApi.Contract) {
push({ name: 'CrmBusinessDetail', params: { id: row.businessId } });
}
/** 查看审批详情 */
function handleProcessDetail(row: CrmContractApi.Contract) {
push({
name: 'BpmProcessInstanceDetail',
query: { id: row.processInstanceId },
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getContractPage({
page: page.currentPage,
pageSize: page.pageSize,
sceneType: sceneType.value,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<CrmContractApi.Contract>,
});
function onChangeSceneType(key: number | string) {
sceneType.value = key.toString();
gridApi.query();
}
</script>
<template>
<Page>
<DocAlert
title="【合同】合同管理、合同提醒"
url="https://doc.iocoder.cn/crm/contract/"
/>
<DocAlert
title="【通用】数据权限"
url="https://doc.iocoder.cn/crm/permission/"
/>
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
>
该功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/crm/contract/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/crm/contract/index
代码pull request 贡献给我们
</Button>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【合同】合同管理、合同提醒"
url="https://doc.iocoder.cn/crm/contract/"
/>
<DocAlert
title="【通用】数据权限"
url="https://doc.iocoder.cn/crm/permission/"
/>
</template>
<FormModal @success="onRefresh" />
<Grid>
<template #top>
<Tabs class="border-none" @change="onChangeSceneType">
<Tabs.TabPane tab="我负责的" key="1" />
<Tabs.TabPane tab="我参与的" key="2" />
<Tabs.TabPane tab="下属负责的" key="3" />
</Tabs>
</template>
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['合同']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['crm:contract:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['crm:contract:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #name="{ row }">
<Button type="link" @click="handleDetail(row)">
{{ row.name }}
</Button>
</template>
<template #customerName="{ row }">
<Button type="link" @click="handleCustomerDetail(row)">
{{ row.customerName }}
</Button>
</template>
<template #businessName="{ row }">
<Button type="link" @click="handleBusinessDetail(row)">
{{ row.businessName }}
</Button>
</template>
<template #signContactName="{ row }">
<Button type="link" @click="handleContactDetail(row)">
{{ row.signContactName }}
</Button>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['crm:contract:update'],
onClick: handleEdit.bind(null, row),
ifShow: row.auditStatus === 0,
},
]"
:drop-down-actions="[
{
label: '提交审核',
type: 'link',
auth: ['crm:contract:update'],
onClick: handleSubmit.bind(null, row),
ifShow: row.auditStatus === 0,
},
{
label: '查看审批',
type: 'link',
auth: ['crm:contract:update'],
onClick: handleProcessDetail.bind(null, row),
ifShow: row.auditStatus !== 0,
},
{
label: $t('common.detail'),
type: 'link',
auth: ['crm:contract:query'],
onClick: handleDetail.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
auth: ['crm:contract:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,85 @@
<script lang="ts" setup>
import type { CrmContractApi } from '#/api/crm/contract';
import { computed, ref } from 'vue';
import { useVbenForm, useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import {
createContract,
getContract,
updateContract,
} from '#/api/crm/contract';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<CrmContractApi.Contract>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['合同'])
: $t('ui.actionTitle.create', ['合同']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
},
// 一共2列
wrapperClass: 'grid-cols-2',
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as CrmContractApi.Contract;
try {
await (formData.value?.id ? updateContract(data) : createContract(data));
// 关闭并提示
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
// 加载数据
const data = modalApi.getData<CrmContractApi.Contract>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getContract(data.id as number);
// 设置到 values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-[40%]">
<Form class="mx-4" />
</Modal>
</template>