Files
iot-device-management-frontend/apps/web-antd/src/views/crm/statistics/performance/index.vue

177 lines
4.9 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
2025-06-23 21:14:48 +08:00
import type { EchartsUIType } from '@vben/plugins/echarts';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmStatisticsCustomerApi } from '#/api/crm/statistics/customer';
import { onMounted, ref } from 'vue';
2025-10-22 12:29:44 +08:00
import { ContentWrap, Page } from '@vben/common-ui';
2025-06-23 21:14:48 +08:00
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Tabs } from 'ant-design-vue';
2025-10-22 12:29:44 +08:00
import { useVbenForm } from '#/adapter/form';
2025-06-23 21:14:48 +08:00
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
getContractCountPerformance,
getContractPricePerformance,
getReceivablePricePerformance,
} from '#/api/crm/statistics/performance';
2025-10-22 12:29:44 +08:00
import { $t } from '#/locales';
2025-06-23 21:14:48 +08:00
import { getChartOptions } from './chartOptions';
import { customerSummaryTabs, useGridFormSchema } from './data';
const activeTabName = ref('ContractCountPerformance');
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
2025-10-22 12:29:44 +08:00
const [QueryForm, formApi] = useVbenForm({
commonConfig: {
// 所有表单项
componentProps: {
class: 'w-full',
2025-06-23 21:14:48 +08:00
},
},
2025-10-22 12:29:44 +08:00
schema: useGridFormSchema(),
// 是否可展开
showCollapseButton: true,
submitButtonOptions: {
content: $t('common.query'),
},
wrapperClass: 'grid-cols-1 md:grid-cols-2',
handleSubmit: async () => {
await handleTabChange(activeTabName.value);
},
});
const [Grid, gridApi] = useVbenVxeGrid({
2025-06-23 21:14:48 +08:00
gridOptions: {
columns: [],
height: 'auto',
keepSource: true,
pagerConfig: {
enabled: false,
},
proxyConfig: {
enabled: false,
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
enabled: false,
},
} as VxeTableGridOptions<CrmStatisticsCustomerApi.CustomerSummaryByUser>,
});
2025-04-22 22:10:33 +08:00
/** tab 切换 */
2025-06-23 21:14:48 +08:00
async function handleTabChange(key: any) {
activeTabName.value = key;
2025-10-22 12:29:44 +08:00
const queryParams = (await formApi.getValues()) as any;
2025-06-23 21:14:48 +08:00
let data: any[] = [];
const columnsData: any[] = [];
let tableData: any[] = [];
switch (key) {
case 'ContractCountPerformance': {
tableData = [
{ title: '当月合同数量统计(个)' },
{ title: '上月合同数量统计(个)' },
{ title: '去年当月合同数量统计(个)' },
{ title: '环比增长率(%' },
{ title: '同比增长率(%' },
];
2025-10-22 12:29:44 +08:00
data = await getContractCountPerformance(queryParams);
2025-06-23 21:14:48 +08:00
break;
}
case 'ContractPricePerformance': {
tableData = [
{ title: '当月合同金额统计(元)' },
{ title: '上月合同金额统计(元)' },
{ title: '去年当月合同金额统计(元)' },
{ title: '环比增长率(%' },
{ title: '同比增长率(%' },
];
2025-10-22 12:29:44 +08:00
data = await getContractPricePerformance(queryParams);
2025-06-23 21:14:48 +08:00
break;
}
case 'ReceivablePricePerformance': {
tableData = [
{ title: '当月回款金额统计(元)' },
{ title: '上月回款金额统计(元)' },
{ title: '去年当月回款金额统计(元)' },
{ title: '环比增长率(%' },
{ title: '同比增长率(%' },
];
2025-10-22 12:29:44 +08:00
data = await getReceivablePricePerformance(queryParams);
2025-06-23 21:14:48 +08:00
break;
}
default: {
break;
}
}
const columnObj = {
title: '日期',
field: 'title',
minWidth: 200,
align: 'left',
};
columnsData.splice(0); // 清空数组
columnsData.push(columnObj);
data.forEach((item: any, index: number) => {
const columnObj = { title: item.time, field: `field${index}` };
columnsData.push(columnObj);
tableData[0][`field${index}`] = item.currentMonthCount;
tableData[1][`field${index}`] = item.lastMonthCount;
tableData[2][`field${index}`] = item.lastYearCount;
tableData[3][`field${index}`] =
item.lastMonthCount === 0
? 'NULL'
: (
((item.currentMonthCount - item.lastMonthCount) /
item.lastMonthCount) *
100
).toFixed(2);
tableData[4][`field${index}`] =
item.lastYearCount === 0
? 'NULL'
: (
((item.currentMonthCount - item.lastYearCount) /
item.lastYearCount) *
100
).toFixed(2);
});
await renderEcharts(getChartOptions(key, data), true);
await gridApi.grid.reloadColumn(columnsData);
await gridApi.grid.reloadData(tableData);
2025-06-23 21:14:48 +08:00
}
/** 初始化加载 */
2025-06-23 21:14:48 +08:00
onMounted(() => {
handleTabChange(activeTabName.value);
});
</script>
<template>
2025-06-23 21:14:48 +08:00
<Page auto-content-height>
2025-10-22 12:29:44 +08:00
<ContentWrap>
<QueryForm />
<Tabs
v-model:active-key="activeTabName"
class="w-full"
@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" />
<Grid class="min-h-[400px]" />
</ContentWrap>
</Page>
2025-04-22 22:10:33 +08:00
</template>