CustomerDealCycle.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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: 'CustomerDealCycle' })
  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: 20,
  40. bottom: 20,
  41. containLabel: true
  42. },
  43. legend: {},
  44. series: [
  45. {
  46. name: '成交周期(天)',
  47. type: 'bar',
  48. data: []
  49. },
  50. {
  51. name: '成交客户数',
  52. type: 'bar',
  53. data: []
  54. }
  55. ],
  56. toolbox: {
  57. feature: {
  58. dataZoom: {
  59. xAxisIndex: false // 数据区域缩放:Y 轴不缩放
  60. },
  61. brush: {
  62. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  63. },
  64. saveAsImage: { show: true, name: '成交周期分析' } // 保存为图片
  65. }
  66. },
  67. tooltip: {
  68. trigger: 'axis',
  69. axisPointer: {
  70. type: 'shadow'
  71. }
  72. },
  73. yAxis: {
  74. type: 'value',
  75. name: '数量(个)'
  76. },
  77. xAxis: {
  78. type: 'category',
  79. name: '日期',
  80. data: []
  81. }
  82. }) as EChartsOption
  83. /** 获取统计数据 */
  84. const loadData = async () => {
  85. // 1. 加载统计数据
  86. loading.value = true
  87. const customerDealCycleByDate = await StatisticsCustomerApi.getCustomerDealCycleByDate(
  88. props.queryParams
  89. )
  90. const customerSummaryByDate = await StatisticsCustomerApi.getCustomerSummaryByDate(
  91. props.queryParams
  92. )
  93. const customerDealCycleByUser = await StatisticsCustomerApi.getCustomerDealCycleByUser(
  94. props.queryParams
  95. )
  96. // 2.1 更新 Echarts 数据
  97. if (echartsOption.xAxis && echartsOption.xAxis['data']) {
  98. echartsOption.xAxis['data'] = customerDealCycleByDate.map(
  99. (s: CrmStatisticsCustomerDealCycleByDateRespVO) => s.time
  100. )
  101. }
  102. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  103. echartsOption.series[0]['data'] = customerDealCycleByDate.map(
  104. (s: CrmStatisticsCustomerDealCycleByDateRespVO) => s.customerDealCycle
  105. )
  106. }
  107. if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
  108. echartsOption.series[1]['data'] = customerSummaryByDate.map(
  109. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerDealCount
  110. )
  111. }
  112. // 2.2 更新列表数据
  113. list.value = customerDealCycleByUser
  114. loading.value = false
  115. }
  116. defineExpose({ loadData })
  117. /** 初始化 */
  118. onMounted(() => {
  119. loadData()
  120. })
  121. </script>