CustomerDealCycleByProduct.vue 4.0 KB

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