gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<script lang="ts" setup>
import type { EchartsUIType } from '../../../../packages/effects/plugins/src/echarts';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmStatisticsCustomerApi } from '#/api/crm/statistics/customer';
 
import { onMounted, ref } from 'vue';
 
import { ContentWrap, Page } from '../../../../packages/effects/common-ui/src';
import { EchartsUI, useEcharts } from '../../../../packages/effects/plugins/src/echarts';
import { beginOfDay, endOfDay, formatDateTime } from '../../../../packages/utils/src';
 
import { Tabs } from 'ant-design-vue';
 
import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  getContractCountPerformance,
  getContractPricePerformance,
  getReceivablePricePerformance,
} from '#/api/crm/statistics/performance';
import { $t } from '#/locales';
 
import { getChartOptions } from './chartOptions';
import { customerSummaryTabs, useGridFormSchema } from './data';
 
const activeTabName = ref('ContractCountPerformance');
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
 
const [QueryForm, formApi] = useVbenForm({
  commonConfig: {
    componentProps: {
      class: 'w-full',
    },
  },
  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({
  gridOptions: {
    columns: [],
    height: 'auto',
    keepSource: true,
    pagerConfig: {
      enabled: false,
    },
    proxyConfig: {
      enabled: false,
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions<CrmStatisticsCustomerApi.CustomerSummaryByUserRespVO>,
});
 
/** tab 切换 */
async function handleTabChange(key: any) {
  activeTabName.value = key;
  const queryParams = (await formApi.getValues()) as any;
  // 将年份转换为年初和年末的日期时间
  const selectYear = Number.parseInt(queryParams.time);
  queryParams.times = [];
  queryParams.times[0] = formatDateTime(beginOfDay(new Date(selectYear, 0, 1)));
  queryParams.times[1] = formatDateTime(endOfDay(new Date(selectYear, 11, 31)));
  let data: any[] = [];
  const columnsData: any[] = [];
  let tableData: any[] = [];
  switch (key) {
    case 'ContractCountPerformance': {
      tableData = [
        { title: '当月合同数量统计(个)' },
        { title: '上月合同数量统计(个)' },
        { title: '去年当月合同数量统计(个)' },
        { title: '环比增长率(%)' },
        { title: '同比增长率(%)' },
      ];
      data = await getContractCountPerformance(queryParams);
      break;
    }
    case 'ContractPricePerformance': {
      tableData = [
        { title: '当月合同金额统计(元)' },
        { title: '上月合同金额统计(元)' },
        { title: '去年当月合同金额统计(元)' },
        { title: '环比增长率(%)' },
        { title: '同比增长率(%)' },
      ];
      data = await getContractPricePerformance(queryParams);
      break;
    }
    case 'ReceivablePricePerformance': {
      tableData = [
        { title: '当月回款金额统计(元)' },
        { title: '上月回款金额统计(元)' },
        { title: '去年当月回款金额统计(元)' },
        { title: '环比增长率(%)' },
        { title: '同比增长率(%)' },
      ];
      data = await getReceivablePricePerformance(queryParams);
      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);
}
 
/** 初始化加载 */
onMounted(() => {
  handleTabChange(activeTabName.value);
});
</script>
 
<template>
  <Page auto-content-height>
    <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>
</template>