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