diff --git a/apps/web-antd/src/api/crm/statistics/customer.ts b/apps/web-antd/src/api/crm/statistics/customer.ts index e661ba81c..8bee0a383 100644 --- a/apps/web-antd/src/api/crm/statistics/customer.ts +++ b/apps/web-antd/src/api/crm/statistics/customer.ts @@ -1,5 +1,3 @@ -import type { PageParam } from '@vben/request'; - import { requestClient } from '#/api/request'; export namespace CrmStatisticsCustomerApi { @@ -93,10 +91,19 @@ export namespace CrmStatisticsCustomerApi { customerDealCycle: number; customerDealCount: number; } + + export interface CustomerSummaryParams { + times: string[]; + interval: number; + deptId: number; + userId: number; + } } /** 客户总量分析(按日期) */ -export function getCustomerSummaryByDate(params: PageParam) { +export function getCustomerSummaryByDate( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-customer-summary-by-date', { params }, @@ -104,7 +111,9 @@ export function getCustomerSummaryByDate(params: PageParam) { } /** 客户总量分析(按用户) */ -export function getCustomerSummaryByUser(params: PageParam) { +export function getCustomerSummaryByUser( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-customer-summary-by-user', { params }, @@ -112,7 +121,9 @@ export function getCustomerSummaryByUser(params: PageParam) { } /** 客户跟进次数分析(按日期) */ -export function getFollowUpSummaryByDate(params: PageParam) { +export function getFollowUpSummaryByDate( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-follow-up-summary-by-date', { params }, @@ -120,7 +131,9 @@ export function getFollowUpSummaryByDate(params: PageParam) { } /** 客户跟进次数分析(按用户) */ -export function getFollowUpSummaryByUser(params: PageParam) { +export function getFollowUpSummaryByUser( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-follow-up-summary-by-user', { params }, @@ -128,7 +141,9 @@ export function getFollowUpSummaryByUser(params: PageParam) { } /** 获取客户跟进方式统计数 */ -export function getFollowUpSummaryByType(params: PageParam) { +export function getFollowUpSummaryByType( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-follow-up-summary-by-type', { params }, @@ -136,7 +151,9 @@ export function getFollowUpSummaryByType(params: PageParam) { } /** 合同摘要信息(客户转化率页面) */ -export function getContractSummary(params: PageParam) { +export function getContractSummary( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-contract-summary', { params }, @@ -144,7 +161,9 @@ export function getContractSummary(params: PageParam) { } /** 获取客户公海分析(按日期) */ -export function getPoolSummaryByDate(params: PageParam) { +export function getPoolSummaryByDate( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-pool-summary-by-date', { params }, @@ -152,7 +171,9 @@ export function getPoolSummaryByDate(params: PageParam) { } /** 获取客户公海分析(按用户) */ -export function getPoolSummaryByUser(params: PageParam) { +export function getPoolSummaryByUser( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-pool-summary-by-user', { params }, @@ -160,7 +181,9 @@ export function getPoolSummaryByUser(params: PageParam) { } /** 获取客户成交周期(按日期) */ -export function getCustomerDealCycleByDate(params: PageParam) { +export function getCustomerDealCycleByDate( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-customer-deal-cycle-by-date', { params }, @@ -168,7 +191,9 @@ export function getCustomerDealCycleByDate(params: PageParam) { } /** 获取客户成交周期(按用户) */ -export function getCustomerDealCycleByUser(params: PageParam) { +export function getCustomerDealCycleByUser( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-customer-deal-cycle-by-user', { params }, @@ -176,7 +201,9 @@ export function getCustomerDealCycleByUser(params: PageParam) { } /** 获取客户成交周期(按地区) */ -export function getCustomerDealCycleByArea(params: PageParam) { +export function getCustomerDealCycleByArea( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get( '/crm/statistics-customer/get-customer-deal-cycle-by-area', { params }, @@ -184,7 +211,9 @@ export function getCustomerDealCycleByArea(params: PageParam) { } /** 获取客户成交周期(按产品) */ -export function getCustomerDealCycleByProduct(params: PageParam) { +export function getCustomerDealCycleByProduct( + params: CrmStatisticsCustomerApi.CustomerSummaryParams, +) { return requestClient.get< CrmStatisticsCustomerApi.CustomerDealCycleByProduct[] >('/crm/statistics-customer/get-customer-deal-cycle-by-product', { params }); diff --git a/apps/web-antd/src/views/crm/statistics/customer/data.ts b/apps/web-antd/src/views/crm/statistics/customer/data.ts new file mode 100644 index 000000000..447cf54d8 --- /dev/null +++ b/apps/web-antd/src/views/crm/statistics/customer/data.ts @@ -0,0 +1,135 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { VxeTableGridOptions } from '#/adapter/vxe-table'; + +import { useUserStore } from '@vben/stores'; +import { + beginOfDay, + endOfDay, + erpCalculatePercentage, + formatDateTime, + handleTree, +} from '@vben/utils'; + +import { getSimpleDeptList } from '#/api/system/dept'; +import { getSimpleUserList } from '#/api/system/user'; +import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils'; + +const userStore = useUserStore(); + +/** 列表的搜索表单 */ +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'times', + label: '时间范围', + component: 'RangePicker', + componentProps: { + ...getRangePickerDefaultProps(), + }, + defaultValue: [ + formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))), + formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))), + ] as [Date, Date], + }, + { + fieldName: 'interval', + label: '时间间隔', + component: 'Select', + componentProps: { + allowClear: true, + options: getDictOptions(DICT_TYPE.DATE_INTERVAL, 'number'), + }, + defaultValue: 2, + }, + { + fieldName: 'deptId', + label: '归属部门', + component: 'ApiTreeSelect', + componentProps: { + api: async () => { + const data = await getSimpleDeptList(); + return handleTree(data); + }, + labelField: 'name', + valueField: 'id', + childrenField: 'children', + treeDefaultExpandAll: true, + }, + defaultValue: userStore.userInfo?.deptId, + }, + { + fieldName: 'userId', + label: '员工', + component: 'ApiSelect', + componentProps: { + api: getSimpleUserList, + allowClear: true, + labelField: 'nickname', + valueField: 'id', + }, + }, + ]; +} + +/** 列表的字段 */ +export function useSummaryGridColumns(): VxeTableGridOptions['columns'] { + return [ + { + type: 'seq', + title: '序号', + }, + { + field: 'ownerUserName', + title: '员工姓名', + minWidth: 100, + }, + { + field: 'customerCreateCount', + title: '新增客户数', + minWidth: 200, + }, + { + field: 'customerDealCount', + title: '成交客户数', + minWidth: 200, + }, + { + field: 'customerDealRate', + title: '客户成交率(%)', + minWidth: 200, + formatter: ({ row }) => { + return erpCalculatePercentage( + row.customerDealCount, + row.customerCreateCount, + ); + }, + }, + { + field: 'contractPrice', + title: '合同总金额', + minWidth: 200, + formatter: 'formatAmount2', + }, + { + field: 'receivablePrice', + title: '回款金额', + minWidth: 200, + formatter: 'formatAmount2', + }, + { + field: 'creceivablePrice', + title: '未回款金额', + minWidth: 200, + formatter: ({ row }) => { + return erpCalculatePercentage(row.receivablePrice, row.contractPrice); + }, + }, + { + field: 'ccreceivablePrice', + title: '回款完成率(%)', + formatter: ({ row }) => { + return erpCalculatePercentage(row.receivablePrice, row.contractPrice); + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/crm/statistics/customer/index.vue b/apps/web-antd/src/views/crm/statistics/customer/index.vue index f86e725c7..69b674150 100644 --- a/apps/web-antd/src/views/crm/statistics/customer/index.vue +++ b/apps/web-antd/src/views/crm/statistics/customer/index.vue @@ -1,28 +1,151 @@