Skip to content

Commit 441b913

Browse files
committed
feat: CRM/数据统计/客户总量分析
1 parent 0db264d commit 441b913

File tree

3 files changed

+262
-0
lines changed

3 files changed

+262
-0
lines changed

src/api/crm/statistics/customer.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import request from '@/config/axios'
2+
3+
export interface StatisticsCustomerRespVO {
4+
count: number
5+
category: string
6+
}
7+
8+
// 客户总量分析 API
9+
export const StatisticsCustomerApi = {
10+
// 客户总量(新建)
11+
getTotalCustomerCount: (params: any) => {
12+
return request.get({
13+
url: '/crm/statistics-customer/get-total-customer-count',
14+
params
15+
})
16+
},
17+
// 客户总量(成交)
18+
getDealTotalCustomerCount: (params: any) => {
19+
return request.get({
20+
url: '/crm/statistics-customer/get-deal-total-customer-count',
21+
params
22+
})
23+
},
24+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!-- 客户总量分析 -->
2+
<template>
3+
<!-- 柱状图 -->
4+
<el-card shadow="never">
5+
<el-skeleton :loading="loading" animated>
6+
<Echart :height="500" :options="echartsOption" />
7+
</el-skeleton>
8+
</el-card>
9+
10+
<!-- 统计列表 -->
11+
<el-card shadow="never" class="mt-16px">
12+
<el-table v-loading="loading" :data="list">
13+
<el-table-column label="序号" align="center" type="index" width="80" />
14+
<el-table-column label="日期" align="center" prop="category" min-width="200" />
15+
<el-table-column label="新增客户数" align="center" prop="customerCount" min-width="200" />
16+
<el-table-column label="成交客户数" align="center" prop="dealCustomerCount" min-width="200" />
17+
</el-table>
18+
</el-card>
19+
</template>
20+
<script setup lang="ts">
21+
import { StatisticsCustomerApi, StatisticsCustomerRespVO } from '@/api/crm/statistics/customer'
22+
import { EChartsOption } from 'echarts'
23+
import { clone } from 'lodash-es'
24+
25+
defineOptions({ name: 'TotalCustomerCount' })
26+
const props = defineProps<{ queryParams: any }>() // 搜索参数
27+
28+
const loading = ref(false) // 加载中
29+
const list = ref<StatisticsCustomerRespVO[]>([]) // 列表的数据
30+
31+
/** 柱状图配置:纵向 */
32+
const echartsOption = reactive<EChartsOption>({
33+
grid: {
34+
left: 20,
35+
right: 20,
36+
bottom: 20,
37+
containLabel: true
38+
},
39+
legend: { },
40+
series: [
41+
{
42+
name: '新增客户数',
43+
type: 'bar',
44+
data: []
45+
},
46+
{
47+
name: '成交客户数',
48+
type: 'bar',
49+
data: []
50+
},
51+
],
52+
toolbox: {
53+
feature: {
54+
dataZoom: {
55+
xAxisIndex: false // 数据区域缩放:Y 轴不缩放
56+
},
57+
brush: {
58+
type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
59+
},
60+
saveAsImage: { show: true, name: '客户总量分析' } // 保存为图片
61+
}
62+
},
63+
tooltip: {
64+
trigger: 'axis',
65+
axisPointer: {
66+
type: 'shadow'
67+
}
68+
},
69+
yAxis: {
70+
type: 'value',
71+
name: '数量(个)'
72+
},
73+
xAxis: {
74+
type: 'category',
75+
name: '日期',
76+
data: []
77+
}
78+
}) as EChartsOption
79+
80+
/** 获取统计数据 */
81+
const loadData = async () => {
82+
// 1. 加载统计数据
83+
loading.value = true
84+
const customerCount = await StatisticsCustomerApi.getTotalCustomerCount(props.queryParams)
85+
const dealCustomerCount = await StatisticsCustomerApi.getDealTotalCustomerCount(props.queryParams)
86+
// 2.1 更新 Echarts 数据
87+
if (echartsOption.xAxis && echartsOption.xAxis['data']) {
88+
echartsOption.xAxis['data'] = clone(customerCount.map(s => s['category']))
89+
}
90+
if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
91+
echartsOption.series[0]['data'] = clone(customerCount.map(s => s['count']))
92+
}
93+
if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
94+
echartsOption.series[1]['data'] = clone(dealCustomerCount.map(s => s['count']))
95+
}
96+
// 2.2 更新列表数据
97+
const tableData = customerCount.map((item, index) => {
98+
return {
99+
category: item['category'],
100+
customerCount: item['count'],
101+
dealCustomerCount: dealCustomerCount[index]['count'],
102+
}
103+
})
104+
list.value = tableData
105+
loading.value = false
106+
}
107+
defineExpose({ loadData })
108+
109+
/** 初始化 */
110+
onMounted(() => {
111+
loadData()
112+
})
113+
</script>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!-- 数据统计 - 员工客户分析 -->
2+
<template>
3+
<ContentWrap>
4+
<!-- 搜索工作栏 -->
5+
<el-form
6+
class="-mb-15px"
7+
:model="queryParams"
8+
ref="queryFormRef"
9+
:inline="true"
10+
label-width="68px"
11+
>
12+
<el-form-item label="时间范围" prop="orderDate">
13+
<el-date-picker
14+
v-model="queryParams.times"
15+
:shortcuts="defaultShortcuts"
16+
class="!w-240px"
17+
end-placeholder="结束日期"
18+
start-placeholder="开始日期"
19+
type="daterange"
20+
value-format="YYYY-MM-DD HH:mm:ss"
21+
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
22+
/>
23+
</el-form-item>
24+
<el-form-item label="归属部门" prop="deptId">
25+
<el-tree-select
26+
v-model="queryParams.deptId"
27+
:data="deptList"
28+
:props="defaultProps"
29+
check-strictly
30+
node-key="id"
31+
placeholder="请选择归属部门"
32+
@change="queryParams.userId = undefined"
33+
/>
34+
</el-form-item>
35+
<el-form-item label="员工" prop="userId">
36+
<el-select v-model="queryParams.userId" class="!w-240px" placeholder="员工" clearable>
37+
<el-option
38+
v-for="(user, index) in userListByDeptId"
39+
:label="user.nickname"
40+
:value="user.id"
41+
:key="index"
42+
/>
43+
</el-select>
44+
</el-form-item>
45+
<el-form-item>
46+
<el-button @click="handleQuery"> <Icon icon="ep:search" class="mr-5px" /> 搜索 </el-button>
47+
<el-button @click="resetQuery"> <Icon icon="ep:refresh" class="mr-5px" /> 重置 </el-button>
48+
</el-form-item>
49+
</el-form>
50+
</ContentWrap>
51+
52+
<!-- 排行数据 -->
53+
<el-col>
54+
<el-tabs v-model="activeTab">
55+
<!-- 客户总量分析 -->
56+
<el-tab-pane label="客户总量分析" name="totalCustomerCount" lazy>
57+
<TotalCustomerCount :query-params="queryParams" ref="totalCustomerCountRef" />
58+
</el-tab-pane>
59+
</el-tabs>
60+
</el-col>
61+
</template>
62+
<script lang="ts" setup>
63+
import * as DeptApi from '@/api/system/dept'
64+
import * as UserApi from '@/api/system/user'
65+
import { useUserStore } from '@/store/modules/user'
66+
import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
67+
import { defaultProps, handleTree } from '@/utils/tree'
68+
import TotalCustomerCount from './components/TotalCustomerCount.vue'
69+
70+
defineOptions({ name: 'CrmStatisticsCustomer' })
71+
72+
const queryParams = reactive({
73+
deptId: useUserStore().getUser.deptId,
74+
userId: undefined,
75+
times: [
76+
// 默认显示最近一周的数据
77+
formatDate(beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7))),
78+
formatDate(endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)))
79+
]
80+
})
81+
82+
const queryFormRef = ref() // 搜索的表单
83+
const deptList = ref<Tree[]>([]) // 部门树形结构
84+
const userList = ref<UserApi.UserVO[]>([]) // 全量用户清单
85+
// 根据选择的部门筛选员工清单
86+
const userListByDeptId = computed(() =>
87+
queryParams.deptId ? userList.value.filter((u) => u.deptId === queryParams.deptId) : []
88+
)
89+
90+
// 活跃标签
91+
const activeTab = ref('totalCustomerCount')
92+
// 1.客户总量分析
93+
const totalCustomerCountRef = ref()
94+
// 2.客户跟进次数分析
95+
// 3.客户跟进方式分析
96+
// 4.客户转化率分析
97+
// 5.公海客户分析
98+
// 6.成交周期分析
99+
100+
/** 搜索按钮操作 */
101+
const handleQuery = () => {
102+
switch (activeTab.value) {
103+
case 'totalCustomerCount':
104+
totalCustomerCountRef.value?.loadData?.()
105+
break
106+
}
107+
}
108+
109+
// 当 activeTab 改变时,刷新当前活动的 tab
110+
watch(activeTab, () => {
111+
handleQuery()
112+
})
113+
114+
/** 重置按钮操作 */
115+
const resetQuery = () => {
116+
queryFormRef.value.resetFields()
117+
handleQuery()
118+
}
119+
120+
// 加载部门树
121+
onMounted(async () => {
122+
deptList.value = handleTree(await DeptApi.getSimpleDeptList())
123+
userList.value = handleTree(await UserApi.getSimpleUserList())
124+
})
125+
</script>

0 commit comments

Comments
 (0)