FollowupCount.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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="日期" align="center" prop="category" min-width="200" />
  14. <el-table-column label="跟进客户数" align="center" prop="distinctRecordCount" min-width="200" />
  15. <el-table-column label="跟进次数" align="center" prop="recordCount" min-width="200" />
  16. </el-table>
  17. </el-card>
  18. </template>
  19. <script setup lang="ts">
  20. import { StatisticsCustomerApi, StatisticsCustomerRespVO } from '@/api/crm/statistics/customer'
  21. import { EChartsOption } from 'echarts'
  22. defineOptions({ name: 'FollowupCount' })
  23. const props = defineProps<{ queryParams: any }>() // 搜索参数
  24. const loading = ref(false) // 加载中
  25. const list = ref<StatisticsCustomerRespVO[]>([]) // 列表的数据
  26. /** 柱状图配置:纵向 */
  27. const echartsOption = reactive<EChartsOption>({
  28. grid: {
  29. left: 20,
  30. right: 20,
  31. bottom: 20,
  32. containLabel: true
  33. },
  34. legend: { },
  35. series: [
  36. {
  37. name: '跟进客户数',
  38. type: 'bar',
  39. data: []
  40. },
  41. {
  42. name: '跟进次数',
  43. type: 'bar',
  44. data: []
  45. },
  46. ],
  47. toolbox: {
  48. feature: {
  49. dataZoom: {
  50. xAxisIndex: false // 数据区域缩放:Y 轴不缩放
  51. },
  52. brush: {
  53. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  54. },
  55. saveAsImage: { show: true, name: '客户跟进次数分析' } // 保存为图片
  56. }
  57. },
  58. tooltip: {
  59. trigger: 'axis',
  60. axisPointer: {
  61. type: 'shadow'
  62. }
  63. },
  64. yAxis: {
  65. type: 'value',
  66. name: '数量(个)'
  67. },
  68. xAxis: {
  69. type: 'category',
  70. name: '日期',
  71. data: []
  72. }
  73. }) as EChartsOption
  74. /** 获取统计数据 */
  75. const loadData = async () => {
  76. // 1. 加载统计数据
  77. loading.value = true
  78. const recordCount = await StatisticsCustomerApi.getRecordCount(props.queryParams)
  79. const distinctRecordCount = await StatisticsCustomerApi.getDistinctRecordCount(props.queryParams)
  80. // 2.1 更新 Echarts 数据
  81. if (echartsOption.xAxis && echartsOption.xAxis['data']) {
  82. echartsOption.xAxis['data'] = recordCount.map((s: StatisticsCustomerRespVO) => s.category)
  83. }
  84. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  85. echartsOption.series[0]['data'] = distinctRecordCount.map((s: StatisticsCustomerRespVO) => s.count)
  86. }
  87. if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
  88. echartsOption.series[1]['data'] = recordCount.map((s: StatisticsCustomerRespVO) => s.count)
  89. }
  90. // 2.2 更新列表数据
  91. const tableData = recordCount.map((item: StatisticsCustomerRespVO, index: number) => {
  92. return {
  93. category: item.category,
  94. recordCount: item.count,
  95. distinctRecordCount: distinctRecordCount[index].count,
  96. }
  97. })
  98. list.value = tableData
  99. loading.value = false
  100. }
  101. defineExpose({ loadData })
  102. /** 初始化 */
  103. onMounted(() => {
  104. loadData()
  105. })
  106. </script>