CRM:code review【客户统计】的代码实现

This commit is contained in:
YunaiV 2024-03-30 11:02:29 +08:00
parent b51397fe19
commit 1b7d604858
4 changed files with 45 additions and 28 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -10,8 +10,8 @@
<!-- 统计列表 -->
<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="员工姓名" prop="ownerUserName" min-width="100" />
<el-table-column label="序号" align="center" type="index" width="80" fixed="left" />
<el-table-column label="员工姓名" prop="ownerUserName" min-width="100" fixed="left" />
<el-table-column
label="新增客户数"
align="right"
@ -21,28 +21,31 @@
<el-table-column label="成交客户数" align="right" prop="customerDealCount" min-width="200" />
<el-table-column label="客户成交率(%)" align="right" min-width="200">
<template #default="scope">
{{
scope.row.customerCreateCount !== 0
? round((scope.row.customerDealCount / scope.row.customerCreateCount) * 100, 2)
: 0
}}
{{ erpCalculatePercentage(scope.row.customerDealCount, scope.row.customerCreateCount) }}
</template>
</el-table-column>
<el-table-column label="合同总金额" align="right" prop="contractPrice" min-width="200" />
<el-table-column label="回款金额" align="right" prop="receivablePrice" min-width="200" />
<el-table-column
label="合同总金额"
align="right"
prop="contractPrice"
min-width="200"
:formatter="erpPriceTableColumnFormatter"
/>
<el-table-column
label="回款金额"
align="right"
prop="receivablePrice"
min-width="200"
:formatter="erpPriceTableColumnFormatter"
/>
<el-table-column label="未回款金额" align="right" min-width="200">
<!-- TODO @dhb52参考 util/index.ts // ========== ERP ========== -->
<template #default="scope">
{{ round(scope.row.contractPrice - scope.row.receivablePrice, 2) }}
{{ erpCalculatePercentage(scope.row.receivablePrice, scope.row.contractPrice) }}
</template>
</el-table-column>
<el-table-column label="回款完成率(%)" align="right" min-width="200">
<el-table-column label="回款完成率(%)" align="right" min-width="200" fixed="right">
<template #default="scope">
{{
scope.row.contractPrice !== 0
? round((scope.row.receivablePrice / scope.row.contractPrice) * 100, 2)
: 0
}}
{{ erpCalculatePercentage(scope.row.receivablePrice, scope.row.contractPrice) }}
</template>
</el-table-column>
</el-table>
@ -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 }>() //

View File

@ -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
}