CustomerSummary.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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" fixed="left" />
  13. <el-table-column label="员工姓名" prop="ownerUserName" min-width="100" fixed="left" />
  14. <el-table-column
  15. label="新增客户数"
  16. align="right"
  17. prop="customerCreateCount"
  18. min-width="200"
  19. />
  20. <el-table-column label="成交客户数" align="right" prop="customerDealCount" min-width="200" />
  21. <el-table-column label="客户成交率(%)" align="right" min-width="200">
  22. <template #default="scope">
  23. {{ erpCalculatePercentage(scope.row.customerDealCount, scope.row.customerCreateCount) }}
  24. </template>
  25. </el-table-column>
  26. <el-table-column
  27. label="合同总金额"
  28. align="right"
  29. prop="contractPrice"
  30. min-width="200"
  31. :formatter="erpPriceTableColumnFormatter"
  32. />
  33. <el-table-column
  34. label="回款金额"
  35. align="right"
  36. prop="receivablePrice"
  37. min-width="200"
  38. :formatter="erpPriceTableColumnFormatter"
  39. />
  40. <el-table-column label="未回款金额" align="right" min-width="200">
  41. <template #default="scope">
  42. {{ erpCalculatePercentage(scope.row.receivablePrice, scope.row.contractPrice) }}
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="回款完成率(%)" align="right" min-width="200" fixed="right">
  46. <template #default="scope">
  47. {{ erpCalculatePercentage(scope.row.receivablePrice, scope.row.contractPrice) }}
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. </el-card>
  52. </template>
  53. <script setup lang="ts">
  54. import {
  55. StatisticsCustomerApi,
  56. CrmStatisticsCustomerSummaryByDateRespVO,
  57. CrmStatisticsCustomerSummaryByUserRespVO
  58. } from '@/api/crm/statistics/customer'
  59. import { EChartsOption } from 'echarts'
  60. import { erpCalculatePercentage, erpPriceTableColumnFormatter } from '@/utils'
  61. defineOptions({ name: 'CustomerSummary' })
  62. const props = defineProps<{ queryParams: any }>() // 搜索参数
  63. const loading = ref(false) // 加载中
  64. const list = ref<CrmStatisticsCustomerSummaryByUserRespVO[]>([]) // 列表的数据
  65. /** 柱状图配置:纵向 */
  66. const echartsOption = reactive<EChartsOption>({
  67. grid: {
  68. left: 20,
  69. right: 30, // 让 X 轴右侧显示完整
  70. bottom: 20,
  71. containLabel: true
  72. },
  73. legend: {},
  74. series: [
  75. {
  76. name: '新增客户数',
  77. type: 'bar',
  78. yAxisIndex: 0,
  79. data: []
  80. },
  81. {
  82. name: '成交客户数',
  83. type: 'bar',
  84. yAxisIndex: 1,
  85. data: []
  86. }
  87. ],
  88. toolbox: {
  89. feature: {
  90. dataZoom: {
  91. xAxisIndex: false // 数据区域缩放:Y 轴不缩放
  92. },
  93. brush: {
  94. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  95. },
  96. saveAsImage: { show: true, name: '客户总量分析' } // 保存为图片
  97. }
  98. },
  99. tooltip: {
  100. trigger: 'axis',
  101. axisPointer: {
  102. type: 'shadow'
  103. }
  104. },
  105. yAxis: [
  106. {
  107. type: 'value',
  108. name: '新增客户数',
  109. min: 0,
  110. minInterval: 1 // 显示整数刻度
  111. },
  112. {
  113. type: 'value',
  114. name: '成交客户数',
  115. min: 0,
  116. minInterval: 1, // 显示整数刻度
  117. splitLine: {
  118. lineStyle: {
  119. type: 'dotted', // 右侧网格线虚化, 减少混乱
  120. opacity: 0.7
  121. }
  122. }
  123. }
  124. ],
  125. xAxis: {
  126. type: 'category',
  127. name: '日期',
  128. data: []
  129. }
  130. }) as EChartsOption
  131. /** 获取数据并填充图表 */
  132. const fetchAndFill = async () => {
  133. // 1. 加载统计数据
  134. const customerSummaryByDate = await StatisticsCustomerApi.getCustomerSummaryByDate(
  135. props.queryParams
  136. )
  137. const customerSummaryByUser = await StatisticsCustomerApi.getCustomerSummaryByUser(
  138. props.queryParams
  139. )
  140. // 2.1 更新 Echarts 数据
  141. if (echartsOption.xAxis && echartsOption.xAxis['data']) {
  142. echartsOption.xAxis['data'] = customerSummaryByDate.map(
  143. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.time
  144. )
  145. }
  146. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  147. echartsOption.series[0]['data'] = customerSummaryByDate.map(
  148. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerCreateCount
  149. )
  150. }
  151. if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
  152. echartsOption.series[1]['data'] = customerSummaryByDate.map(
  153. (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerDealCount
  154. )
  155. }
  156. // 2.2 更新列表数据
  157. list.value = customerSummaryByUser
  158. }
  159. /** 获取统计数据 */
  160. const loadData = async () => {
  161. loading.value = true
  162. try {
  163. await fetchAndFill()
  164. } finally {
  165. loading.value = false
  166. }
  167. }
  168. defineExpose({ loadData })
  169. /** 初始化 */
  170. onMounted(() => {
  171. loadData()
  172. })
  173. </script>