CustomerSummary.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!-- 客户统计 -->
  2. <template>
  3. <!-- Echarts图 -->
  4. <el-card shadow="never">
  5. <el-skeleton :loading="loading" animated>
  6. <Echart :height="500" :options="echartsOption" />
  7. </el-skeleton>
  8. </el-card>
  9. <!-- 统计列表 -->
  10. <el-card shadow="never" class="mt-16px">
  11. <el-table v-loading="loading" :data="list">
  12. <el-table-column label="序号" align="center" type="index" width="80" />
  13. <el-table-column label="员工姓名" prop="ownerUserName" min-width="100" />
  14. <el-table-column
  15. label="新增客户数"
  16. align="right"
  17. prop="customerCreateCount"
  18. min-width="200"
  19. />
  20. <el-table-column label="成交客户数" align="right" prop="customerDealCount" min-width="200" />
  21. <el-table-column label="客户成交率(%)" align="right" min-width="200">
  22. <template #default="scope">
  23. {{
  24. scope.row.customerCreateCount !== 0
  25. ? round((scope.row.customerDealCount / scope.row.customerCreateCount) * 100, 2)
  26. : 0
  27. }}
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="合同总金额" align="right" prop="contractPrice" min-width="200" />
  31. <el-table-column label="回款金额" align="right" prop="receivablePrice" min-width="200" />
  32. <el-table-column label="未回款金额" align="right" min-width="200">
  33. <template #default="scope">
  34. {{ round(scope.row.contractPrice - scope.row.receivablePrice, 2) }}
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="回款完成率(%)" align="right" min-width="200">
  38. <template #default="scope">
  39. {{
  40. scope.row.contractPrice !== 0
  41. ? round((scope.row.receivablePrice / scope.row.contractPrice) * 100, 2)
  42. : 0
  43. }}
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. </el-card>
  48. </template>
  49. <script setup lang="ts">
  50. import {
  51. StatisticsCustomerApi,
  52. CrmStatisticsCustomerSummaryByDateRespVO,
  53. CrmStatisticsCustomerSummaryByUserRespVO
  54. } from '@/api/crm/statistics/customer'
  55. import { EChartsOption } from 'echarts'
  56. import { round } from 'lodash-es'
  57. defineOptions({ name: 'CustomerSummary' })
  58. const props = defineProps<{ queryParams: any }>() // 搜索参数
  59. const loading = ref(false) // 加载中
  60. const list = ref<CrmStatisticsCustomerSummaryByUserRespVO[]>([]) // 列表的数据
  61. /** 柱状图配置:纵向 */
  62. const echartsOption = reactive<EChartsOption>({
  63. grid: {
  64. left: 20,
  65. right: 20,
  66. bottom: 20,
  67. containLabel: true
  68. },
  69. legend: {},
  70. series: [
  71. {
  72. name: '新增客户数',
  73. type: 'bar',
  74. data: []
  75. },
  76. {
  77. name: '成交客户数',
  78. type: 'bar',
  79. data: []
  80. }
  81. ],
  82. toolbox: {
  83. feature: {
  84. dataZoom: {
  85. xAxisIndex: false // 数据区域缩放:Y 轴不缩放
  86. },
  87. brush: {
  88. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  89. },
  90. saveAsImage: { show: true, name: '客户总量分析' } // 保存为图片
  91. }
  92. },
  93. tooltip: {
  94. trigger: 'axis',
  95. axisPointer: {
  96. type: 'shadow'
  97. }
  98. },
  99. yAxis: {
  100. type: 'value',
  101. name: '数量(个)'
  102. },
  103. xAxis: {
  104. type: 'category',
  105. name: '日期',
  106. data: []
  107. }
  108. }) as EChartsOption
  109. /** 获取统计数据 */
  110. const loadData = async () => {
  111. // 1. 加载统计数据
  112. loading.value = true
  113. const customerSummaryByDate = await StatisticsCustomerApi.getCustomerSummaryByDate(
  114. props.queryParams
  115. )
  116. const customerSummaryByUser = await StatisticsCustomerApi.getCustomerSummaryByUser(
  117. props.queryParams
  118. )
  119. // 2.1 更新 Echarts 数据
  120. if (echartsOption.xAxis && echartsOption.xAxis['data']) {
  121. echartsOption.xAxis['data'] = customerSummaryByDate.map(
  122. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.time
  123. )
  124. }
  125. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  126. echartsOption.series[0]['data'] = customerSummaryByDate.map(
  127. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerCreateCount
  128. )
  129. }
  130. if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
  131. echartsOption.series[1]['data'] = customerSummaryByDate.map(
  132. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerDealCount
  133. )
  134. }
  135. // 2.2 更新列表数据
  136. list.value = customerSummaryByUser
  137. loading.value = false
  138. }
  139. defineExpose({ loadData })
  140. /** 初始化 */
  141. onMounted(() => {
  142. loadData()
  143. })
  144. </script>