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
<script lang="ts" setup>
import type { EchartsUIType } from '../../../../packages/effects/plugins/src/echarts';
 
import type {
  VxeGridListeners,
  VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { CrmStatisticsFunnelApi } from '#/api/crm/statistics/funnel';
 
import { reactive, ref } from 'vue';
 
import { ContentWrap, Page } from '../../../../packages/effects/common-ui/src';
import { EchartsUI, useEcharts } from '../../../../packages/effects/plugins/src/echarts';
 
import { Button, ButtonGroup, Tabs } from 'ant-design-vue';
 
import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getChartDatas, getDatas } from '#/api/crm/statistics/funnel';
import { $t } from '#/locales';
 
import { getChartOptions } from './chartOptions';
import { customerSummaryTabs, useGridColumns, useGridFormSchema } from './data';
 
const activeTabName = ref('funnel');
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
 
const active = ref(true);
const pagerVO = reactive({
  total: 0,
  pageNo: 1,
  pageSize: 10,
});
 
const gridEvents: VxeGridListeners = {
  async pageChange({ pageSize, currentPage }) {
    pagerVO.pageNo = currentPage;
    pagerVO.pageSize = pageSize;
    await handleTabChange(activeTabName.value);
  },
};
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: useGridColumns(activeTabName.value),
    height: 'auto',
    keepSource: true,
    pagerConfig: {
      enabled: false,
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions<CrmStatisticsFunnelApi.BusinessSummaryByDateRespVO>,
});
 
/** tab 切换 */
async function handleTabChange(key: any) {
  activeTabName.value = key;
  gridApi.setGridOptions({
    columns: useGridColumns(key),
    height: '400px',
    keepSource: true,
    pagerConfig: {
      enabled: activeTabName.value !== 'funnel',
    },
  });
  const queryParams = await formApi.getValues();
  const res = await getChartDatas(activeTabName.value, queryParams);
  await renderEcharts(getChartOptions(activeTabName.value, active.value, res));
  const data: any = await getDatas(activeTabName.value, queryParams);
  await gridApi.grid.reloadData(
    activeTabName.value === 'funnel' ? data : data.list,
  );
}
 
/** 视角切换 */
async function handleActive(value: boolean) {
  active.value = value;
  const queryParams = await formApi.getValues();
  renderEcharts(
    getChartOptions(activeTabName.value, active.value, queryParams),
  );
}
</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>
      <ButtonGroup>
        <Button
          :type="active ? 'primary' : 'default'"
          v-if="activeTabName === 'funnel'"
          @click="handleActive(true)"
        >
          客户视角
        </Button>
        <Button
          :type="active ? 'default' : 'primary'"
          v-if="activeTabName === 'funnel'"
          @click="handleActive(false)"
        >
          动态视角
        </Button>
      </ButtonGroup>
      <EchartsUI class="mb-20 h-2/5 w-full" ref="chartRef" />
      <Grid v-on="gridEvents" />
    </ContentWrap>
  </Page>
</template>