diff --git a/src/utils/index.ts b/src/utils/index.ts index d2111430..412a8b62 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -329,10 +329,11 @@ const ERP_PRICE_DIGIT = 2 * 例如说:库存数量 * * @param num 数量 + * @package digit 保留的小数位数 * @return 格式化后的数量 */ export const erpNumberFormatter = (num: number | string | undefined, digit: number) => { - if (num === null) { + if (num == null) { return '' } if (typeof num === 'string') { @@ -404,3 +405,16 @@ export const erpPriceMultiply = (price: number, count: number) => { } return parseFloat((price * count).toFixed(ERP_PRICE_DIGIT)) } + +/** + * 【ERP】百分比计算,四舍五入保留两位小数 + * + * 如果 total 为 0,则返回 0 + * + * @param value 当前值 + * @param total 总值 + */ +export const erpCalculatePercentage = (value: number, total: number) => { + if (total === 0) return 0 + return ((value / total) * 100).toFixed(2) +} diff --git a/src/views/crm/statistics/customer/components/CustomerFollowUpType.vue b/src/views/crm/statistics/customer/components/CustomerFollowUpType.vue index f9c045cb..8384da74 100644 --- a/src/views/crm/statistics/customer/components/CustomerFollowUpType.vue +++ b/src/views/crm/statistics/customer/components/CustomerFollowUpType.vue @@ -27,8 +27,9 @@ import { CrmStatisticsFollowUpSummaryByTypeRespVO } from '@/api/crm/statistics/customer' import { EChartsOption } from 'echarts' -import { round, sumBy } from 'lodash-es' +import { sumBy } from 'lodash-es' import { DICT_TYPE, getDictLabel } from '@/utils/dict' +import { erpCalculatePercentage } from '@/utils' defineOptions({ name: 'CustomerFollowupType' }) const props = defineProps<{ queryParams: any }>() // 搜索参数 @@ -95,7 +96,7 @@ const loadData = async () => { list.value = followUpSummaryByType.map((row: CrmStatisticsFollowUpSummaryByTypeRespVO) => { return { ...row, - portion: round((row.followUpRecordCount / totalCount) * 100, 2) + portion: erpCalculatePercentage(row.followUpRecordCount, totalCount) } }) loading.value = false diff --git a/src/views/crm/statistics/customer/components/CustomerSummary.vue b/src/views/crm/statistics/customer/components/CustomerSummary.vue index 14f0b9b8..37e4d166 100644 --- a/src/views/crm/statistics/customer/components/CustomerSummary.vue +++ b/src/views/crm/statistics/customer/components/CustomerSummary.vue @@ -10,8 +10,8 @@ - - + + - - + + - - + @@ -55,7 +58,7 @@ import { CrmStatisticsCustomerSummaryByUserRespVO } from '@/api/crm/statistics/customer' import { EChartsOption } from 'echarts' -import { round } from 'lodash-es' +import { erpCalculatePercentage, erpPriceTableColumnFormatter } from '@/utils' defineOptions({ name: 'CustomerSummary' }) const props = defineProps<{ queryParams: any }>() // 搜索参数 diff --git a/src/views/crm/statistics/customer/index.vue b/src/views/crm/statistics/customer/index.vue index a667a964..c9d7268c 100644 --- a/src/views/crm/statistics/customer/index.vue +++ b/src/views/crm/statistics/customer/index.vue @@ -124,32 +124,31 @@ const userListByDeptId = computed(() => : [] ) -// 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 表 +// 缺 crm_owner_record 表 TODO @dhb52:可以先做界面 + 接口,接口数据直接写死返回,相当于 mock 出来 const dealCycleRef = ref() // 6. 成交周期分析 /** 搜索按钮操作 */ const handleQuery = () => { switch (activeTab.value) { - case 'customerSummary': + case 'customerSummary': // 客户总量分析 customerSummaryRef.value?.loadData?.() break - case 'followUpSummary': + case 'followUpSummary': // 客户跟进次数分析 followUpSummaryRef.value?.loadData?.() break - case 'followUpType': + case 'followUpType': // 客户跟进方式分析 followUpTypeRef.value?.loadData?.() break - case 'conversionStat': + case 'conversionStat': // 客户转化率分析 conversionStatRef.value?.loadData?.() break - case 'dealCycle': + case 'dealCycle': // 成交周期分析 dealCycleRef.value?.loadData?.() break }