feat: crm statistics rank

pull/155/head
xingyu4j 2025-06-24 10:28:27 +08:00
parent 83ddc05cf5
commit 51bd200ad8
4 changed files with 774 additions and 21 deletions

View File

@ -11,6 +11,38 @@ export namespace CrmStatisticsRankApi {
}
}
export function getDatas(activeTabName: any, params: any) {
switch (activeTabName) {
case 'contactCountRank': {
return getContactsCountRank(params);
}
case 'contractCountRank': {
return getContractCountRank(params);
}
case 'contractPriceRank': {
return getContractPriceRank(params);
}
case 'customerCountRank': {
return getCustomerCountRank(params);
}
case 'followCountRank': {
return getFollowCountRank(params);
}
case 'followCustomerCountRank': {
return getFollowCustomerCountRank(params);
}
case 'productSalesRank': {
return getProductSalesRank(params);
}
case 'receivablePriceRank': {
return getReceivablePriceRank(params);
}
default: {
return [];
}
}
}
/** 获得合同排行榜 */
export function getContractPriceRank(params: PageParam) {
return requestClient.get<CrmStatisticsRankApi.Rank[]>(

View File

@ -0,0 +1,394 @@
import { cloneDeep } from '@vben/utils';
export function getChartOptions(activeTabName: any, res: any): any {
switch (activeTabName) {
case 'contactCountRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '新增联系人数排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '新增联系人数排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '新增联系人数(个)',
},
yAxis: {
type: 'category',
name: '创建人',
},
};
}
case 'contractCountRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '签约合同排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '签约合同排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '签约合同数(个)',
},
yAxis: {
type: 'category',
name: '签订人',
},
};
}
case 'contractPriceRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '合同金额排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '合同金额排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '合同金额(元)',
},
yAxis: {
type: 'category',
name: '签订人',
},
};
}
case 'customerCountRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '新增客户数排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '新增客户数排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '新增客户数(个)',
},
yAxis: {
type: 'category',
name: '创建人',
},
};
}
case 'followCountRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '跟进次数排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '跟进次数排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '跟进次数(次)',
},
yAxis: {
type: 'category',
name: '员工',
},
};
}
case 'followCustomerCountRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '跟进客户数排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '跟进客户数排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '跟进客户数(个)',
},
yAxis: {
type: 'category',
name: '员工',
},
};
}
case 'productSalesRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '产品销量排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '产品销量排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '产品销量',
},
yAxis: {
type: 'category',
name: '员工',
},
};
}
case 'receivablePriceRank': {
return {
dataset: {
dimensions: ['nickname', 'count'],
source: cloneDeep(res).reverse(),
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true,
},
legend: {
top: 50,
},
series: [
{
name: '回款金额排行',
type: 'bar',
},
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false, // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'], // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '回款金额排行' }, // 保存为图片
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
name: '回款金额(元)',
},
yAxis: {
type: 'category',
name: '签订人',
nameGap: 30,
},
};
}
default: {
return {};
}
}
}

View File

@ -0,0 +1,276 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { useUserStore } from '@vben/stores';
import { beginOfDay, endOfDay, formatDateTime, handleTree } from '@vben/utils';
import { getSimpleDeptList } from '#/api/system/dept';
import { getRangePickerDefaultProps } from '#/utils';
const userStore = useUserStore();
export const customerSummaryTabs = [
{
tab: '合同金额排行',
key: 'contractPriceRank',
},
{
tab: '回款金额排行',
key: 'receivablePriceRank',
},
{
tab: '签约合同排行',
key: 'contractCountRank',
},
{
tab: '产品销量排行',
key: 'productSalesRank',
},
{
tab: '新增客户数排行',
key: 'customerCountRank',
},
{
tab: '新增联系人数排行',
key: 'contactCountRank',
},
{
tab: '跟进次数排行',
key: 'followCountRank',
},
{
tab: '跟进客户数排行',
key: 'followCustomerCountRank',
},
];
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'times',
label: '时间范围',
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
},
defaultValue: [
formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))),
formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))),
] as [Date, Date],
},
{
fieldName: 'deptId',
label: '归属部门',
component: 'ApiTreeSelect',
componentProps: {
api: async () => {
const data = await getSimpleDeptList();
return handleTree(data);
},
labelField: 'name',
valueField: 'id',
childrenField: 'children',
treeDefaultExpandAll: true,
},
defaultValue: userStore.userInfo?.deptId,
},
];
}
/** 列表的字段 */
export function useGridColumns(
activeTabName: any,
): VxeTableGridOptions['columns'] {
switch (activeTabName) {
case 'contactCountRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '创建人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '新增联系人数(个)',
minWidth: 200,
},
];
}
case 'contractCountRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '签约合同数(个)',
minWidth: 200,
},
];
}
case 'contractPriceRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '合同金额(元)',
minWidth: 200,
formatter: 'formatAmount2',
},
];
}
case 'customerCountRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '新增客户数(个)',
minWidth: 200,
},
];
}
case 'followCountRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '跟进次数(次)',
minWidth: 200,
},
];
}
case 'followCustomerCountRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '跟进客户数(个)',
minWidth: 200,
},
];
}
case 'productSalesRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '产品销量',
minWidth: 200,
},
];
}
case 'receivablePriceRank': {
return [
{
type: 'seq',
title: '公司排名',
},
{
field: 'nickname',
title: '签订人',
minWidth: 200,
},
{
field: 'deptName',
title: '部门',
minWidth: 200,
},
{
field: 'count',
title: '回款金额(元)',
minWidth: 200,
formatter: 'formatAmount2',
},
];
}
default: {
return [];
}
}
}

View File

@ -1,28 +1,79 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import type { EchartsUIType } from '@vben/plugins/echarts';
import { Button } from 'ant-design-vue';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmStatisticsCustomerApi } from '#/api/crm/statistics/customer';
import { ref } from 'vue';
import { Page } from '@vben/common-ui';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Tabs } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getDatas } from '#/api/crm/statistics/customer';
import { getChartOptions } from './chartOptions';
import { customerSummaryTabs, useGridColumns, useGridFormSchema } from './data';
const activeTabName = ref('contractPriceRank');
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(activeTabName.value),
height: 'auto',
keepSource: true,
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_, formValues) => {
const res = await getDatas(activeTabName.value, formValues);
renderEcharts(getChartOptions(activeTabName.value, res));
return res;
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
enabled: false,
},
} as VxeTableGridOptions<CrmStatisticsCustomerApi.CustomerSummaryByUser>,
});
async function handleTabChange(key: any) {
activeTabName.value = key;
gridApi.setGridOptions({
columns: useGridColumns(key),
});
gridApi.reload();
}
</script>
<template>
<Page>
<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/statistics/rank/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/crm/statistics/rank/index
代码pull request 贡献给我们
</Button>
<Page auto-content-height>
<Grid>
<template #top>
<Tabs v-model:active-key="activeTabName" @change="handleTabChange">
<Tabs.TabPane
v-for="item in customerSummaryTabs"
:key="item.key"
:tab="item.tab"
:force-render="true"
/>
</Tabs>
<EchartsUI class="mb-20 h-full w-full" ref="chartRef" />
</template>
</Grid>
</Page>
</template>