CustomerLevel.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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="客户来源" min-width="200" prop="levelName" />
  23. <el-table-column align="center" label="客户个数" min-width="200" prop="customerCount" />
  24. <el-table-column align="center" label="成交个数" min-width="200" prop="dealCount" />
  25. <el-table-column align="center" label="级别占比(%)" min-width="200" prop="levelPortion" />
  26. <el-table-column align="center" label="成交占比(%)" min-width="200" prop="dealPortion" />
  27. </el-table>
  28. </el-card>
  29. </template>
  30. <script lang="ts" setup>
  31. import {
  32. CrmStatisticCustomerLevelRespVO,
  33. StatisticsCustomerApi
  34. } from '@/api/crm/statistics/customer'
  35. import { EChartsOption } from 'echarts'
  36. defineOptions({ name: 'CustomerSource' })
  37. const props = defineProps<{ queryParams: any }>() // 搜索参数
  38. const loading = ref(false) // 加载中
  39. const list = ref<CrmStatisticCustomerLevelRespVO[]>([]) // 列表的数据
  40. /** 饼图配置 */
  41. const echartsOption = reactive<EChartsOption>({
  42. title: {
  43. text: '全部客户',
  44. left: 'center'
  45. },
  46. tooltip: {
  47. trigger: 'item'
  48. },
  49. legend: {
  50. orient: 'vertical',
  51. left: 'left'
  52. },
  53. toolbox: {
  54. feature: {
  55. saveAsImage: { show: true, name: '全部客户' } // 保存为图片
  56. }
  57. },
  58. series: [
  59. {
  60. name: '全部客户',
  61. type: 'pie',
  62. radius: ['40%', '70%'],
  63. avoidLabelOverlap: false,
  64. itemStyle: {
  65. borderRadius: 10,
  66. borderColor: '#fff',
  67. borderWidth: 2
  68. },
  69. label: {
  70. show: false,
  71. position: 'center'
  72. },
  73. emphasis: {
  74. label: {
  75. show: true,
  76. fontSize: 40,
  77. fontWeight: 'bold'
  78. }
  79. },
  80. labelLine: {
  81. show: false
  82. },
  83. data: []
  84. }
  85. ]
  86. }) as EChartsOption
  87. /** 饼图配置 */
  88. const echartsOption2 = reactive<EChartsOption>({
  89. title: {
  90. text: '成交客户',
  91. left: 'center'
  92. },
  93. tooltip: {
  94. trigger: 'item'
  95. },
  96. legend: {
  97. orient: 'vertical',
  98. left: 'left'
  99. },
  100. toolbox: {
  101. feature: {
  102. saveAsImage: { show: true, name: '成交客户' } // 保存为图片
  103. }
  104. },
  105. series: [
  106. {
  107. name: '成交客户',
  108. type: 'pie',
  109. radius: ['40%', '70%'],
  110. avoidLabelOverlap: false,
  111. itemStyle: {
  112. borderRadius: 10,
  113. borderColor: '#fff',
  114. borderWidth: 2
  115. },
  116. label: {
  117. show: false,
  118. position: 'center'
  119. },
  120. emphasis: {
  121. label: {
  122. show: true,
  123. fontSize: 40,
  124. fontWeight: 'bold'
  125. }
  126. },
  127. labelLine: {
  128. show: false
  129. },
  130. data: []
  131. }
  132. ]
  133. }) as EChartsOption
  134. /** 获取统计数据 */
  135. const loadData = async () => {
  136. // 1. 加载统计数据
  137. loading.value = true
  138. const levelList = await StatisticsCustomerApi.getCustomerLevel(props.queryParams)
  139. // 2.1 更新 Echarts 数据
  140. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  141. echartsOption.series[0]['data'] = levelList.map((r: CrmStatisticCustomerLevelRespVO) => {
  142. return {
  143. name: r.levelName,
  144. value: r.customerCount
  145. }
  146. })
  147. }
  148. // 2.2 更新 Echarts2 数据
  149. if (echartsOption2.series && echartsOption2.series[0] && echartsOption2.series[0]['data']) {
  150. echartsOption2.series[0]['data'] = levelList.map((r: CrmStatisticCustomerLevelRespVO) => {
  151. return {
  152. name: r.levelName,
  153. value: r.dealCount
  154. }
  155. })
  156. }
  157. list.value = levelList
  158. loading.value = false
  159. }
  160. defineExpose({ loadData })
  161. /** 初始化 */
  162. onMounted(() => {
  163. loadData()
  164. })
  165. </script>