PoolSummary.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 label="进入公海客户数" align="right" prop="customerPutCount" min-width="200" />
  15. <el-table-column label="公海领取客户数" align="right" prop="customerTakeCount" min-width="200" />
  16. </el-table>
  17. </el-card>
  18. </template>
  19. <script setup lang="ts">
  20. import {
  21. StatisticsCustomerApi,
  22. CrmStatisticsPoolSummaryByDateRespVO,
  23. CrmStatisticsPoolSummaryByUserRespVO
  24. } from '@/api/crm/statistics/customer'
  25. import { EChartsOption } from 'echarts'
  26. defineOptions({ name: 'CustomerSummary' })
  27. const props = defineProps<{ queryParams: any }>() // 搜索参数
  28. const loading = ref(false) // 加载中
  29. const list = ref<CrmStatisticsPoolSummaryByUserRespVO[]>([]) // 列表的数据
  30. /** 柱状图配置:纵向 */
  31. const echartsOption = reactive<EChartsOption>({
  32. grid: {
  33. left: 20,
  34. right: 40, // 让X轴右侧显示完整
  35. bottom: 20,
  36. containLabel: true
  37. },
  38. legend: {},
  39. series: [
  40. {
  41. name: '进入公海客户数',
  42. type: 'bar',
  43. yAxisIndex: 0,
  44. data: []
  45. },
  46. {
  47. name: '公海领取客户数',
  48. type: 'bar',
  49. yAxisIndex: 1,
  50. data: []
  51. }
  52. ],
  53. toolbox: {
  54. feature: {
  55. dataZoom: {
  56. xAxisIndex: false // 数据区域缩放:Y 轴不缩放
  57. },
  58. brush: {
  59. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  60. },
  61. saveAsImage: { show: true, name: '公海客户分析' } // 保存为图片
  62. }
  63. },
  64. tooltip: {
  65. trigger: 'axis',
  66. axisPointer: {
  67. type: 'shadow'
  68. }
  69. },
  70. yAxis: [
  71. {
  72. type: 'value',
  73. name: '进入公海客户数',
  74. min: 0,
  75. minInterval: 1, // 显示整数刻度
  76. },
  77. {
  78. type: 'value',
  79. name: '公海领取客户数',
  80. min: 0,
  81. minInterval: 1, // 显示整数刻度
  82. splitLine: {
  83. lineStyle: {
  84. type: 'dotted', // 右侧网格线虚化, 减少混乱
  85. opacity: 0.7,
  86. }
  87. }
  88. }
  89. ],
  90. xAxis: {
  91. type: 'category',
  92. name: '日期',
  93. data: [],
  94. }
  95. }) as EChartsOption
  96. /** 获取数据并填充图表 */
  97. const fetchAndFill = async () => {
  98. // 1. 加载统计数据
  99. const poolSummaryByDate = await StatisticsCustomerApi.getPoolSummaryByDate(
  100. props.queryParams
  101. )
  102. const poolSummaryByUser = await StatisticsCustomerApi.getPoolSummaryByUser(
  103. props.queryParams
  104. )
  105. // 2.1 更新 Echarts 数据
  106. if (echartsOption.xAxis && echartsOption.xAxis['data']) {
  107. echartsOption.xAxis['data'] = poolSummaryByDate.map(
  108. (s: CrmStatisticsPoolSummaryByDateRespVO) => s.time
  109. )
  110. }
  111. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  112. echartsOption.series[0]['data'] = poolSummaryByDate.map(
  113. (s: CrmStatisticsPoolSummaryByDateRespVO) => s.customerPutCount
  114. )
  115. }
  116. if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
  117. echartsOption.series[1]['data'] = poolSummaryByDate.map(
  118. (s: CrmStatisticsPoolSummaryByDateRespVO) => s.customerTakeCount
  119. )
  120. }
  121. // 2.2 更新列表数据
  122. list.value = poolSummaryByUser
  123. }
  124. /** 获取统计数据 */
  125. const loadData = async () => {
  126. loading.value = true
  127. try {
  128. fetchAndFill()
  129. } finally {
  130. loading.value = false
  131. }
  132. }
  133. defineExpose({ loadData })
  134. /** 初始化 */
  135. onMounted(() => {
  136. loadData()
  137. })
  138. </script>