FunnelBusiness.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!-- 销售漏斗分析 -->
  2. <template>
  3. <!-- Echarts图 -->
  4. <el-card shadow="never">
  5. <el-row>
  6. <el-col :span="24">
  7. <el-skeleton :loading="loading" animated>
  8. <Echart :height="500" :options="echartsOption" />
  9. </el-skeleton>
  10. </el-col>
  11. </el-row>
  12. </el-card>
  13. <!-- 统计列表 -->
  14. <el-card class="mt-16px" shadow="never">
  15. <el-table v-loading="loading" :data="list">
  16. <el-table-column align="center" label="序号" type="index" width="80" />
  17. <el-table-column align="center" label="阶段" prop="endStatus" width="200">
  18. <template #default="scope">
  19. <dict-tag :type="DICT_TYPE.CRM_BUSINESS_END_STATUS_TYPE" :value="scope.row.endStatus" />
  20. </template>
  21. </el-table-column>
  22. <el-table-column align="center" label="商机数" min-width="200" prop="businessCount" />
  23. <el-table-column align="center" label="商机总金额(元)" min-width="200" prop="totalPrice" />
  24. </el-table>
  25. </el-card>
  26. </template>
  27. <script lang="ts" setup>
  28. import { CrmStatisticFunnelRespVO, StatisticFunnelApi } from '@/api/crm/statistics/funnel'
  29. import { EChartsOption } from 'echarts'
  30. import { DICT_TYPE } from '@/utils/dict'
  31. import echarts from '@/plugins/echarts'
  32. import { FunnelChart } from 'echarts/charts'
  33. echarts?.use([FunnelChart])
  34. defineOptions({ name: 'FunnelBusiness' })
  35. const props = defineProps<{ queryParams: any }>() // 搜索参数
  36. const loading = ref(false) // 加载中
  37. const list = ref<CrmStatisticFunnelRespVO[]>([]) // 列表的数据
  38. /** 销售漏斗 */
  39. const echartsOption = reactive<EChartsOption>({
  40. title: {
  41. text: '销售漏斗'
  42. },
  43. tooltip: {
  44. trigger: 'item',
  45. formatter: '{a} <br/>{b}'
  46. },
  47. toolbox: {
  48. feature: {
  49. dataView: { readOnly: false },
  50. restore: {},
  51. saveAsImage: {}
  52. }
  53. },
  54. legend: {
  55. data: ['客户', '商机', '赢单']
  56. },
  57. series: [
  58. {
  59. name: '销售漏斗',
  60. type: 'funnel',
  61. left: '10%',
  62. top: 60,
  63. bottom: 60,
  64. width: '80%',
  65. min: 0,
  66. max: 100,
  67. minSize: '0%',
  68. maxSize: '100%',
  69. sort: 'descending',
  70. gap: 2,
  71. label: {
  72. show: true,
  73. position: 'inside'
  74. },
  75. labelLine: {
  76. length: 10,
  77. lineStyle: {
  78. width: 1,
  79. type: 'solid'
  80. }
  81. },
  82. itemStyle: {
  83. borderColor: '#fff',
  84. borderWidth: 1
  85. },
  86. emphasis: {
  87. label: {
  88. fontSize: 20
  89. }
  90. },
  91. data: [
  92. { value: 60, name: '客户-0个' },
  93. { value: 40, name: '商机-0个' },
  94. { value: 20, name: '赢单-0个' }
  95. ]
  96. }
  97. ]
  98. }) as EChartsOption
  99. /** 获取统计数据 */
  100. const loadData = async () => {
  101. loading.value = true
  102. // 1. 加载漏斗数据
  103. const data = (await StatisticFunnelApi.getFunnelSummary(
  104. props.queryParams
  105. )) as CrmStatisticFunnelRespVO
  106. // 2.1 更新 Echarts 数据
  107. if (
  108. !!data &&
  109. echartsOption.series &&
  110. echartsOption.series[0] &&
  111. echartsOption.series[0]['data']
  112. ) {
  113. // tips:写死 value 值是为了保持漏斗顺序不变
  114. const list: { value: number; name: string }[] = []
  115. list.push({ value: 60, name: `客户-${data.customerCount || 0}个` })
  116. list.push({ value: 40, name: `商机-${data.businessCount || 0}个` })
  117. list.push({ value: 20, name: `赢单-${data.winCount || 0}个` })
  118. echartsOption.series[0]['data'] = list
  119. }
  120. // 2.2 获取商机结束状态统计
  121. list.value = await StatisticFunnelApi.getBusinessEndStatusSummary(props.queryParams)
  122. loading.value = false
  123. }
  124. defineExpose({ loadData })
  125. /** 初始化 */
  126. onMounted(() => {
  127. loadData()
  128. })
  129. </script>