FunnelBusiness.vue 4.3 KB

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