CustomerSource.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <!-- 客户来源分析 -->
  2. <template>
  3. <!-- Echarts图 -->
  4. <el-card shadow="never">
  5. <el-row :gutter="20">
  6. <el-col :span="12">
  7. <el-skeleton :loading="loading" animated>
  8. <Echart :height="500" :options="echartsOption" />
  9. </el-skeleton>
  10. </el-col>
  11. <el-col :span="12">
  12. <el-skeleton :loading="loading" animated>
  13. <Echart :height="500" :options="echartsOption2" />
  14. </el-skeleton>
  15. </el-col>
  16. </el-row>
  17. </el-card>
  18. <!-- 统计列表 -->
  19. <el-card class="mt-16px" shadow="never">
  20. <el-table v-loading="loading" :data="list">
  21. <el-table-column align="center" label="序号" type="index" width="80" />
  22. <el-table-column align="center" label="客户来源" prop="source" width="100">
  23. <template #default="scope">
  24. <dict-tag :type="DICT_TYPE.CRM_CUSTOMER_SOURCE" :value="scope.row.source" />
  25. </template>
  26. </el-table-column>
  27. <el-table-column align="center" label="客户个数" min-width="200" prop="customerCount" />
  28. <el-table-column align="center" label="成交个数" min-width="200" prop="dealCount" />
  29. <el-table-column align="center" label="来源占比(%)" min-width="200" prop="sourcePortion" />
  30. <el-table-column align="center" label="成交占比(%)" min-width="200" prop="dealPortion" />
  31. </el-table>
  32. </el-card>
  33. </template>
  34. <script lang="ts" setup>
  35. import {
  36. CrmStatisticCustomerSourceRespVO,
  37. StatisticsPortraitApi
  38. } from '@/api/crm/statistics/portrait'
  39. import { EChartsOption } from 'echarts'
  40. import { DICT_TYPE, getDictLabel } from '@/utils/dict'
  41. import { isEmpty } from '@/utils/is'
  42. import { getSumValue } from '@/utils'
  43. defineOptions({ name: 'CustomerSource' })
  44. const props = defineProps<{ queryParams: any }>() // 搜索参数
  45. const loading = ref(false) // 加载中
  46. const list = ref<CrmStatisticCustomerSourceRespVO[]>([]) // 列表的数据
  47. /** 饼图配置(全部客户) */
  48. const echartsOption = reactive<EChartsOption>({
  49. title: {
  50. text: '全部客户',
  51. left: 'center'
  52. },
  53. tooltip: {
  54. trigger: 'item'
  55. },
  56. legend: {
  57. orient: 'vertical',
  58. left: 'left'
  59. },
  60. toolbox: {
  61. feature: {
  62. saveAsImage: { show: true, name: '全部客户' } // 保存为图片
  63. }
  64. },
  65. series: [
  66. {
  67. name: '全部客户',
  68. type: 'pie',
  69. radius: ['40%', '70%'],
  70. avoidLabelOverlap: false,
  71. itemStyle: {
  72. borderRadius: 10,
  73. borderColor: '#fff',
  74. borderWidth: 2
  75. },
  76. label: {
  77. show: false,
  78. position: 'center'
  79. },
  80. emphasis: {
  81. label: {
  82. show: true,
  83. fontSize: 40,
  84. fontWeight: 'bold'
  85. }
  86. },
  87. labelLine: {
  88. show: false
  89. },
  90. data: []
  91. }
  92. ]
  93. }) as EChartsOption
  94. /** 饼图配置(成交客户) */
  95. const echartsOption2 = reactive<EChartsOption>({
  96. title: {
  97. text: '成交客户',
  98. left: 'center'
  99. },
  100. tooltip: {
  101. trigger: 'item'
  102. },
  103. legend: {
  104. orient: 'vertical',
  105. left: 'left'
  106. },
  107. toolbox: {
  108. feature: {
  109. saveAsImage: { show: true, name: '成交客户' } // 保存为图片
  110. }
  111. },
  112. series: [
  113. {
  114. name: '成交客户',
  115. type: 'pie',
  116. radius: ['40%', '70%'],
  117. avoidLabelOverlap: false,
  118. itemStyle: {
  119. borderRadius: 10,
  120. borderColor: '#fff',
  121. borderWidth: 2
  122. },
  123. label: {
  124. show: false,
  125. position: 'center'
  126. },
  127. emphasis: {
  128. label: {
  129. show: true,
  130. fontSize: 40,
  131. fontWeight: 'bold'
  132. }
  133. },
  134. labelLine: {
  135. show: false
  136. },
  137. data: []
  138. }
  139. ]
  140. }) as EChartsOption
  141. /** 获取统计数据 */
  142. const loadData = async () => {
  143. // 1. 加载统计数据
  144. loading.value = true
  145. const sourceList = await StatisticsPortraitApi.getCustomerSource(props.queryParams)
  146. // 2.1 更新 Echarts 数据
  147. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  148. echartsOption.series[0]['data'] = sourceList.map((r: CrmStatisticCustomerSourceRespVO) => {
  149. return {
  150. name: getDictLabel(DICT_TYPE.CRM_CUSTOMER_SOURCE, r.source),
  151. value: r.customerCount
  152. }
  153. })
  154. }
  155. // 2.2 更新 Echarts2 数据
  156. if (echartsOption2.series && echartsOption2.series[0] && echartsOption2.series[0]['data']) {
  157. echartsOption2.series[0]['data'] = sourceList.map((r: CrmStatisticCustomerSourceRespVO) => {
  158. return {
  159. name: getDictLabel(DICT_TYPE.CRM_CUSTOMER_SOURCE, r.source),
  160. value: r.dealCount
  161. }
  162. })
  163. }
  164. // 3. 计算比例
  165. calculateProportion(sourceList)
  166. list.value = sourceList
  167. loading.value = false
  168. }
  169. defineExpose({ loadData })
  170. /** 计算比例 */
  171. const calculateProportion = (sourceList: CrmStatisticCustomerSourceRespVO[]) => {
  172. if (isEmpty(sourceList)) {
  173. return
  174. }
  175. // 这里类型丢失了所以重新搞个变量
  176. const list = sourceList as unknown as CrmStatisticCustomerSourceRespVO[]
  177. const sumCustomerCount = getSumValue(list.map((item) => item.customerCount))
  178. const sumDealCount = getSumValue(list.map((item) => item.dealCount))
  179. list.forEach((item) => {
  180. item.sourcePortion =
  181. item.customerCount === 0 ? 0 : ((item.customerCount / sumCustomerCount) * 100).toFixed(2)
  182. item.dealPortion = item.dealCount === 0 ? 0 : ((item.dealCount / sumDealCount) * 100).toFixed(2)
  183. })
  184. }
  185. /** 初始化 */
  186. onMounted(() => {
  187. loadData()
  188. })
  189. </script>