CustomerSummary.vue 4.5 KB

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