CRM:优化【客户统计】的代码实现

This commit is contained in:
YunaiV 2024-03-30 09:23:02 +08:00
parent 23150fcfc3
commit b51397fe19
6 changed files with 119 additions and 102 deletions

View File

@ -14,21 +14,21 @@ export interface CrmStatisticsCustomerSummaryByUserRespVO {
receivablePrice: number
}
export interface CrmStatisticsFollowupSummaryByDateRespVO {
export interface CrmStatisticsFollowUpSummaryByDateRespVO {
time: string
followupRecordCount: number
followupCustomerCount: number
followUpRecordCount: number
followUpCustomerCount: number
}
export interface CrmStatisticsFollowupSummaryByUserRespVO {
export interface CrmStatisticsFollowUpSummaryByUserRespVO {
ownerUserName: string
followupRecordCount: number
followupCustomerCount: number
}
export interface CrmStatisticsFollowupSummaryByTypeRespVO {
followupType: string
followupRecordCount: number
export interface CrmStatisticsFollowUpSummaryByTypeRespVO {
followUpType: string
followUpRecordCount: number
}
export interface CrmStatisticsCustomerContractSummaryRespVO {
@ -55,22 +55,6 @@ export interface CrmStatisticsCustomerDealCycleByUserRespVO {
customerDealCount: number
}
export const DATE_INTERVAL_OPTIONS = [
{ value: 1, name: '今天' },
{ value: 2, name: '昨天' },
{ value: 3, name: '本周' },
{ value: 4, name: '上周' },
{ value: 5, name: '本月' },
{ value: 6, name: '上月' },
{ value: 7, name: '本季度' },
{ value: 8, name: '上季度' },
{ value: 9, name: '本年' },
{ value: 10, name: '去年' },
{ value: 11, name: '自定义' }
]
export const CUSTOMER_INTERVAL = 11
// 客户分析 API
export const StatisticsCustomerApi = {
// 1.1 客户总量分析(按日期)
@ -88,23 +72,23 @@ export const StatisticsCustomerApi = {
})
},
// 2.1 客户跟进次数分析(按日期)
getFollowupSummaryByDate: (params: any) => {
getFollowUpSummaryByDate: (params: any) => {
return request.get({
url: '/crm/statistics-customer/get-followup-summary-by-date',
url: '/crm/statistics-customer/get-follow-up-summary-by-date',
params
})
},
// 2.2 客户跟进次数分析(按用户)
getFollowupSummaryByUser: (params: any) => {
getFollowUpSummaryByUser: (params: any) => {
return request.get({
url: '/crm/statistics-customer/get-followup-summary-by-user',
url: '/crm/statistics-customer/get-follow-up-summary-by-user',
params
})
},
// 3.1 获取客户跟进方式统计数
getFollowupSummaryByType: (params: any) => {
getFollowUpSummaryByType: (params: any) => {
return request.get({
url: '/crm/statistics-customer/get-followup-summary-by-type',
url: '/crm/statistics-customer/get-follow-up-summary-by-type',
params
})
},

View File

@ -104,6 +104,7 @@ export enum DICT_TYPE {
USER_TYPE = 'user_type',
COMMON_STATUS = 'common_status',
TERMINAL = 'terminal', // 终端
DATE_INTERVAL = 'date_interval', // 数据间隔
// ========== SYSTEM 模块 ==========
SYSTEM_USER_SEX = 'system_user_sex',

View File

@ -10,11 +10,39 @@
<!-- 统计列表 -->
<el-card shadow="never" class="mt-16px">
<el-table v-loading="loading" :data="list">
<el-table-column label="序号" align="center" type="index" width="80" />
<el-table-column label="客户名称" align="center" prop="customerName" min-width="200" />
<el-table-column label="序号" align="center" type="index" width="80" fixed="left" />
<el-table-column
label="客户名称"
align="center"
prop="customerName"
min-width="200"
fixed="left"
/>
<el-table-column label="合同名称" align="center" prop="contractName" min-width="200" />
<el-table-column label="合同总金额" align="center" prop="totalPrice" min-width="200" />
<el-table-column label="回款金额" align="center" prop="receivablePrice" min-width="200" />
<el-table-column
label="合同总金额"
align="center"
prop="totalPrice"
min-width="200"
:formatter="erpPriceTableColumnFormatter"
/>
<el-table-column
label="回款金额"
align="center"
prop="receivablePrice"
min-width="200"
:formatter="erpPriceTableColumnFormatter"
/>
<el-table-column align="center" label="客户来源" prop="source" width="100">
<template #default="scope">
<dict-tag :type="DICT_TYPE.CRM_CUSTOMER_SOURCE" :value="scope.row.source" />
</template>
</el-table-column>
<el-table-column align="center" label="客户行业" prop="industryId" width="100">
<template #default="scope">
<dict-tag :type="DICT_TYPE.CRM_CUSTOMER_INDUSTRY" :value="scope.row.industryId" />
</template>
</el-table-column>
<el-table-column label="负责人" align="center" prop="ownerUserName" min-width="200" />
<el-table-column label="创建人" align="center" prop="creatorUserName" min-width="200" />
<el-table-column
@ -28,8 +56,9 @@
label="下单日期"
align="center"
prop="orderDate"
:formatter="dateFormatter2"
:formatter="dateFormatter"
min-width="200"
fixed="right"
/>
</el-table>
</el-card>
@ -41,7 +70,9 @@ import {
} from '@/api/crm/statistics/customer'
import { EChartsOption } from 'echarts'
import { round } from 'lodash-es'
import { dateFormatter, dateFormatter2 } from '@/utils/formatTime'
import { dateFormatter } from '@/utils/formatTime'
import { erpPriceTableColumnFormatter } from '@/utils'
import { DICT_TYPE } from '@/utils/dict'
defineOptions({ name: 'CustomerConversionStat' })
const props = defineProps<{ queryParams: any }>() //
@ -97,6 +128,7 @@ const echartsOption = reactive<EChartsOption>({
const loadData = async () => {
// 1.
loading.value = true
// TODO @ddhb52 StatisticsCustomerApi.getCustomerSummaryByDate
const customerCount = await StatisticsCustomerApi.getCustomerSummaryByDate(props.queryParams)
const contractSummary = await StatisticsCustomerApi.getContractSummary(props.queryParams)
// 2.1 Echarts

View File

@ -12,11 +12,11 @@
<el-table v-loading="loading" :data="list">
<el-table-column label="序号" align="center" type="index" width="80" />
<el-table-column label="员工姓名" align="center" prop="ownerUserName" min-width="200" />
<el-table-column label="跟进次数" align="right" prop="followupRecordCount" min-width="200" />
<el-table-column label="跟进次数" align="right" prop="followUpRecordCount" min-width="200" />
<el-table-column
label="跟进客户数"
align="right"
prop="followupCustomerCount"
prop="followUpCustomerCount"
min-width="200"
/>
</el-table>
@ -25,8 +25,8 @@
<script setup lang="ts">
import {
StatisticsCustomerApi,
CrmStatisticsFollowupSummaryByDateRespVO,
CrmStatisticsFollowupSummaryByUserRespVO
CrmStatisticsFollowUpSummaryByDateRespVO,
CrmStatisticsFollowUpSummaryByUserRespVO
} from '@/api/crm/statistics/customer'
import { EChartsOption } from 'echarts'
@ -34,7 +34,7 @@ defineOptions({ name: 'CustomerFollowupSummary' })
const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) //
const list = ref<CrmStatisticsFollowupSummaryByUserRespVO[]>([]) //
const list = ref<CrmStatisticsFollowUpSummaryByUserRespVO[]>([]) //
/** 柱状图配置:纵向 */
const echartsOption = reactive<EChartsOption>({
@ -89,30 +89,30 @@ const echartsOption = reactive<EChartsOption>({
const loadData = async () => {
// 1.
loading.value = true
const followupSummaryByDate = await StatisticsCustomerApi.getFollowupSummaryByDate(
const followUpSummaryByDate = await StatisticsCustomerApi.getFollowUpSummaryByDate(
props.queryParams
)
const followupSummaryByUser = await StatisticsCustomerApi.getFollowupSummaryByUser(
const followUpSummaryByUser = await StatisticsCustomerApi.getFollowUpSummaryByUser(
props.queryParams
)
// 2.1 Echarts
if (echartsOption.xAxis && echartsOption.xAxis['data']) {
echartsOption.xAxis['data'] = followupSummaryByDate.map(
(s: CrmStatisticsFollowupSummaryByDateRespVO) => s.time
echartsOption.xAxis['data'] = followUpSummaryByDate.map(
(s: CrmStatisticsFollowUpSummaryByDateRespVO) => s.time
)
}
if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
echartsOption.series[0]['data'] = followupSummaryByDate.map(
(s: CrmStatisticsFollowupSummaryByDateRespVO) => s.followupCustomerCount
echartsOption.series[0]['data'] = followUpSummaryByDate.map(
(s: CrmStatisticsFollowUpSummaryByDateRespVO) => s.followUpCustomerCount
)
}
if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
echartsOption.series[1]['data'] = followupSummaryByDate.map(
(s: CrmStatisticsFollowupSummaryByDateRespVO) => s.followupRecordCount
echartsOption.series[1]['data'] = followUpSummaryByDate.map(
(s: CrmStatisticsFollowUpSummaryByDateRespVO) => s.followUpRecordCount
)
}
// 2.2
list.value = followupSummaryByUser
list.value = followUpSummaryByUser
loading.value = false
}
defineExpose({ loadData })

View File

@ -11,8 +11,12 @@
<el-card shadow="never" class="mt-16px">
<el-table v-loading="loading" :data="list">
<el-table-column label="序号" align="center" type="index" width="80" />
<el-table-column label="跟进方式" align="center" prop="followupType" min-width="200" />
<el-table-column label="个数" align="center" prop="followupRecordCount" min-width="200" />
<el-table-column label="跟进方式" align="center" prop="followUpType" min-width="200">
<template #default="scope">
<dict-tag :type="DICT_TYPE.CRM_FOLLOW_UP_TYPE" :value="scope.row.followUpType" />
</template>
</el-table-column>
<el-table-column label="个数" align="center" prop="followUpRecordCount" min-width="200" />
<el-table-column label="占比(%)" align="center" prop="portion" min-width="200" />
</el-table>
</el-card>
@ -20,16 +24,17 @@
<script setup lang="ts">
import {
StatisticsCustomerApi,
CrmStatisticsFollowupSummaryByTypeRespVO
CrmStatisticsFollowUpSummaryByTypeRespVO
} from '@/api/crm/statistics/customer'
import { EChartsOption } from 'echarts'
import { round, sumBy } from 'lodash-es'
import { DICT_TYPE, getDictLabel } from '@/utils/dict'
defineOptions({ name: 'CustomerFollowupType' })
const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) //
const list = ref<CrmStatisticsFollowupSummaryByTypeRespVO[]>([]) //
const list = ref<CrmStatisticsFollowUpSummaryByTypeRespVO[]>([]) //
/** 饼图配置 */
const echartsOption = reactive<EChartsOption>({
@ -71,27 +76,26 @@ const echartsOption = reactive<EChartsOption>({
const loadData = async () => {
// 1.
loading.value = true
const followupSummaryByType = await StatisticsCustomerApi.getFollowupSummaryByType(
const followUpSummaryByType = await StatisticsCustomerApi.getFollowUpSummaryByType(
props.queryParams
)
// 2.1 Echarts
if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
echartsOption.series[0]['data'] = followupSummaryByType.map(
(r: CrmStatisticsFollowupSummaryByTypeRespVO) => {
echartsOption.series[0]['data'] = followUpSummaryByType.map(
(row: CrmStatisticsFollowUpSummaryByTypeRespVO) => {
return {
name: r.followupType,
value: r.followupRecordCount
name: getDictLabel(DICT_TYPE.CRM_FOLLOW_UP_TYPE, row.followUpType),
value: row.followUpRecordCount
}
}
)
}
// 2.2
const totalCount = sumBy(followupSummaryByType, 'followupRecordCount')
list.value = followupSummaryByType.map((r: CrmStatisticsFollowupSummaryByTypeRespVO) => {
const totalCount = sumBy(followUpSummaryByType, 'followUpRecordCount')
list.value = followUpSummaryByType.map((row: CrmStatisticsFollowUpSummaryByTypeRespVO) => {
return {
followupType: r.followupType,
followupRecordCount: r.followupRecordCount,
portion: round((r.followupRecordCount / totalCount) * 100, 2)
...row,
portion: round((row.followUpRecordCount / totalCount) * 100, 2)
}
})
loading.value = false

View File

@ -9,17 +9,7 @@
:inline="true"
label-width="68px"
>
<el-form-item label="间隔类型" prop="intervalType">
<el-select v-model="queryParams.intervalType" class="!w-240px" placeholder="间隔类型">
<el-option
v-for="(intervalType, index) in DATE_INTERVAL_OPTIONS"
:label="intervalType.name"
:value="intervalType.value"
:key="index"
/>
</el-select>
</el-form-item>
<el-form-item label="时间范围" prop="orderDate" v-show="queryParams.intervalType === CUSTOMER_INTERVAL">
<el-form-item label="时间范围" prop="orderDate">
<el-date-picker
v-model="queryParams.times"
:shortcuts="defaultShortcuts"
@ -31,6 +21,16 @@
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
/>
</el-form-item>
<el-form-item label="时间间隔" prop="interval">
<el-select v-model="queryParams.interval" class="!w-240px" placeholder="间隔类型">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.DATE_INTERVAL)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="归属部门" prop="deptId">
<el-tree-select
v-model="queryParams.deptId"
@ -68,12 +68,12 @@
<CustomerSummary :query-params="queryParams" ref="customerSummaryRef" />
</el-tab-pane>
<!-- 客户跟进次数分析 -->
<el-tab-pane label="客户跟进次数分析" name="followupSummary" lazy>
<CustomerFollowupSummary :query-params="queryParams" ref="followupSummaryRef" />
<el-tab-pane label="客户跟进次数分析" name="followUpSummary" lazy>
<CustomerFollowUpSummary :query-params="queryParams" ref="followUpSummaryRef" />
</el-tab-pane>
<!-- 客户跟进方式分析 -->
<el-tab-pane label="客户跟进方式分析" name="followupType" lazy>
<CustomerFollowupType :query-params="queryParams" ref="followupTypeRef" />
<el-tab-pane label="客户跟进方式分析" name="followUpType" lazy>
<CustomerFollowUpType :query-params="queryParams" ref="followUpTypeRef" />
</el-tab-pane>
<!-- 客户转化率分析 -->
<el-tab-pane label="客户转化率分析" name="conversionStat" lazy>
@ -94,16 +94,16 @@ import { useUserStore } from '@/store/modules/user'
import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
import { defaultProps, handleTree } from '@/utils/tree'
import CustomerSummary from './components/CustomerSummary.vue'
import CustomerFollowupSummary from './components/CustomerFollowupSummary.vue'
import CustomerFollowupType from './components/CustomerFollowupType.vue'
import CustomerFollowUpSummary from './components/CustomerFollowUpSummary.vue'
import CustomerFollowUpType from './components/CustomerFollowUpType.vue'
import CustomerConversionStat from './components/CustomerConversionStat.vue'
import CustomerDealCycle from './components/CustomerDealCycle.vue'
import { DATE_INTERVAL_OPTIONS, CUSTOMER_INTERVAL } from '@/api/crm/statistics/customer'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
defineOptions({ name: 'CrmStatisticsCustomer' })
const queryParams = reactive({
intervalType: CUSTOMER_INTERVAL,
interval: 1,
deptId: useUserStore().getUser.deptId,
userId: undefined,
times: [
@ -116,27 +116,23 @@ const queryParams = reactive({
const queryFormRef = ref() //
const deptList = ref<Tree[]>([]) //
const userList = ref<UserApi.UserVO[]>([]) //
//
/** 根据选择的部门筛选员工清单 */
const userListByDeptId = computed(() =>
queryParams.deptId
? userList.value.filter((u: UserApi.UserVO) => u.deptId === queryParams.deptId)
: []
)
//
const activeTab = ref('customerSummary')
// 1.
const customerSummaryRef = ref()
// 2.
const followupSummaryRef = ref()
// 3.
const followupTypeRef = ref()
// 4.
const conversionStatRef = ref()
// 5.
//
const activeTab = ref('customerSummary') //
const customerSummaryRef = ref() // 1.
const followUpSummaryRef = ref() // 2.
const followUpTypeRef = ref() // 3.
const conversionStatRef = ref() // 4.
// 5. TODO
// crm_owner_record
// 6.
const dealCycleRef = ref()
const dealCycleRef = ref() // 6.
/** 搜索按钮操作 */
const handleQuery = () => {
@ -144,11 +140,11 @@ const handleQuery = () => {
case 'customerSummary':
customerSummaryRef.value?.loadData?.()
break
case 'followupSummary':
followupSummaryRef.value?.loadData?.()
case 'followUpSummary':
followUpSummaryRef.value?.loadData?.()
break
case 'followupType':
followupTypeRef.value?.loadData?.()
case 'followUpType':
followUpTypeRef.value?.loadData?.()
break
case 'conversionStat':
conversionStatRef.value?.loadData?.()
@ -159,7 +155,7 @@ const handleQuery = () => {
}
}
// activeTab tab
/** 当 activeTab 改变时,刷新当前活动的 tab */
watch(activeTab, () => {
handleQuery()
})
@ -170,7 +166,7 @@ const resetQuery = () => {
handleQuery()
}
//
/** 初始化 */
onMounted(async () => {
deptList.value = handleTree(await DeptApi.getSimpleDeptList())
userList.value = handleTree(await UserApi.getSimpleUserList())