Skip to content

Commit 1b7d604

Browse files
committed
CRM:code review【客户统计】的代码实现
1 parent b51397f commit 1b7d604

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

src/utils/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ const ERP_PRICE_DIGIT = 2
329329
* 例如说:库存数量
330330
*
331331
* @param num 数量
332+
* @package digit 保留的小数位数
332333
* @return 格式化后的数量
333334
*/
334335
export const erpNumberFormatter = (num: number | string | undefined, digit: number) => {
335-
if (num === null) {
336+
if (num == null) {
336337
return ''
337338
}
338339
if (typeof num === 'string') {
@@ -404,3 +405,16 @@ export const erpPriceMultiply = (price: number, count: number) => {
404405
}
405406
return parseFloat((price * count).toFixed(ERP_PRICE_DIGIT))
406407
}
408+
409+
/**
410+
* 【ERP】百分比计算,四舍五入保留两位小数
411+
*
412+
* 如果 total 为 0,则返回 0
413+
*
414+
* @param value 当前值
415+
* @param total 总值
416+
*/
417+
export const erpCalculatePercentage = (value: number, total: number) => {
418+
if (total === 0) return 0
419+
return ((value / total) * 100).toFixed(2)
420+
}

src/views/crm/statistics/customer/components/CustomerFollowUpType.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import {
2727
CrmStatisticsFollowUpSummaryByTypeRespVO
2828
} from '@/api/crm/statistics/customer'
2929
import { EChartsOption } from 'echarts'
30-
import { round, sumBy } from 'lodash-es'
30+
import { sumBy } from 'lodash-es'
3131
import { DICT_TYPE, getDictLabel } from '@/utils/dict'
32+
import { erpCalculatePercentage } from '@/utils'
3233
3334
defineOptions({ name: 'CustomerFollowupType' })
3435
const props = defineProps<{ queryParams: any }>() // 搜索参数
@@ -95,7 +96,7 @@ const loadData = async () => {
9596
list.value = followUpSummaryByType.map((row: CrmStatisticsFollowUpSummaryByTypeRespVO) => {
9697
return {
9798
...row,
98-
portion: round((row.followUpRecordCount / totalCount) * 100, 2)
99+
portion: erpCalculatePercentage(row.followUpRecordCount, totalCount)
99100
}
100101
})
101102
loading.value = false

src/views/crm/statistics/customer/components/CustomerSummary.vue

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<!-- 统计列表 -->
1111
<el-card shadow="never" class="mt-16px">
1212
<el-table v-loading="loading" :data="list">
13-
<el-table-column label="序号" align="center" type="index" width="80" />
14-
<el-table-column label="员工姓名" prop="ownerUserName" min-width="100" />
13+
<el-table-column label="序号" align="center" type="index" width="80" fixed="left" />
14+
<el-table-column label="员工姓名" prop="ownerUserName" min-width="100" fixed="left" />
1515
<el-table-column
1616
label="新增客户数"
1717
align="right"
@@ -21,28 +21,31 @@
2121
<el-table-column label="成交客户数" align="right" prop="customerDealCount" min-width="200" />
2222
<el-table-column label="客户成交率(%)" align="right" min-width="200">
2323
<template #default="scope">
24-
{{
25-
scope.row.customerCreateCount !== 0
26-
? round((scope.row.customerDealCount / scope.row.customerCreateCount) * 100, 2)
27-
: 0
28-
}}
24+
{{ erpCalculatePercentage(scope.row.customerDealCount, scope.row.customerCreateCount) }}
2925
</template>
3026
</el-table-column>
31-
<el-table-column label="合同总金额" align="right" prop="contractPrice" min-width="200" />
32-
<el-table-column label="回款金额" align="right" prop="receivablePrice" min-width="200" />
27+
<el-table-column
28+
label="合同总金额"
29+
align="right"
30+
prop="contractPrice"
31+
min-width="200"
32+
:formatter="erpPriceTableColumnFormatter"
33+
/>
34+
<el-table-column
35+
label="回款金额"
36+
align="right"
37+
prop="receivablePrice"
38+
min-width="200"
39+
:formatter="erpPriceTableColumnFormatter"
40+
/>
3341
<el-table-column label="未回款金额" align="right" min-width="200">
34-
<!-- TODO @dhb52:参考 util/index.ts 的 // ========== ERP 专属方法 ========== 部分,搞个两个方法,一个格式化百分比,一个计算百分比 -->
3542
<template #default="scope">
36-
{{ round(scope.row.contractPrice - scope.row.receivablePrice, 2) }}
43+
{{ erpCalculatePercentage(scope.row.receivablePrice, scope.row.contractPrice) }}
3744
</template>
3845
</el-table-column>
39-
<el-table-column label="回款完成率(%)" align="right" min-width="200">
46+
<el-table-column label="回款完成率(%)" align="right" min-width="200" fixed="right">
4047
<template #default="scope">
41-
{{
42-
scope.row.contractPrice !== 0
43-
? round((scope.row.receivablePrice / scope.row.contractPrice) * 100, 2)
44-
: 0
45-
}}
48+
{{ erpCalculatePercentage(scope.row.receivablePrice, scope.row.contractPrice) }}
4649
</template>
4750
</el-table-column>
4851
</el-table>
@@ -55,7 +58,7 @@ import {
5558
CrmStatisticsCustomerSummaryByUserRespVO
5659
} from '@/api/crm/statistics/customer'
5760
import { EChartsOption } from 'echarts'
58-
import { round } from 'lodash-es'
61+
import { erpCalculatePercentage, erpPriceTableColumnFormatter } from '@/utils'
5962
6063
defineOptions({ name: 'CustomerSummary' })
6164
const props = defineProps<{ queryParams: any }>() // 搜索参数

src/views/crm/statistics/customer/index.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,31 @@ const userListByDeptId = computed(() =>
124124
: []
125125
)
126126
127-
//
128127
const activeTab = ref('customerSummary') // 活跃标签
129128
const customerSummaryRef = ref() // 1. 客户总量分析
130129
const followUpSummaryRef = ref() // 2. 客户跟进次数分析
131130
const followUpTypeRef = ref() // 3. 客户跟进方式分析
132131
const conversionStatRef = ref() // 4. 客户转化率分析
133132
// 5. TODO 公海客户分析
134-
// 缺 crm_owner_record 表
133+
// 缺 crm_owner_record 表 TODO @dhb52:可以先做界面 + 接口,接口数据直接写死返回,相当于 mock 出来
135134
const dealCycleRef = ref() // 6. 成交周期分析
136135
137136
/** 搜索按钮操作 */
138137
const handleQuery = () => {
139138
switch (activeTab.value) {
140-
case 'customerSummary':
139+
case 'customerSummary': // 客户总量分析
141140
customerSummaryRef.value?.loadData?.()
142141
break
143-
case 'followUpSummary':
142+
case 'followUpSummary': // 客户跟进次数分析
144143
followUpSummaryRef.value?.loadData?.()
145144
break
146-
case 'followUpType':
145+
case 'followUpType': // 客户跟进方式分析
147146
followUpTypeRef.value?.loadData?.()
148147
break
149-
case 'conversionStat':
148+
case 'conversionStat': // 客户转化率分析
150149
conversionStatRef.value?.loadData?.()
151150
break
152-
case 'dealCycle':
151+
case 'dealCycle': // 成交周期分析
153152
dealCycleRef.value?.loadData?.()
154153
break
155154
}

0 commit comments

Comments
 (0)