ContractPricePerformance.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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="tableData">
  12. <el-table-column v-for="item in columnsData" :key="item.prop" :label="item.label" :prop="item.prop" align="center">
  13. <template #default="scope">
  14. {{scope.row[item.prop]}}
  15. </template>
  16. </el-table-column>
  17. </el-table>
  18. </el-card>
  19. </template>
  20. <script setup lang="ts">
  21. import { EChartsOption } from 'echarts'
  22. import {
  23. StatisticsPerformanceApi,
  24. StatisticsPerformanceRespVO
  25. } from "@/api/crm/statistics/performance"
  26. defineOptions({ name: 'ContractPricePerformance' })
  27. const props = defineProps<{ queryParams: any }>() // 搜索参数
  28. const loading = ref(false) // 加载中
  29. const list = ref<StatisticsPerformanceRespVO[]>([]) // 列表的数据
  30. /** 柱状图配置:纵向 */
  31. const echartsOption = reactive<EChartsOption>({
  32. grid: {
  33. left: 20,
  34. right: 20,
  35. bottom: 20,
  36. containLabel: true
  37. },
  38. legend: {},
  39. series: [
  40. {
  41. name: '当月合同金额(元)',
  42. type: 'line',
  43. data: []
  44. },
  45. {
  46. name: '上月合同金额(元)',
  47. type: 'line',
  48. data: []
  49. },
  50. {
  51. name: '去年同月合同金额(元)',
  52. type: 'line',
  53. data: []
  54. },
  55. {
  56. name: '同比增长率(%)',
  57. type: 'line',
  58. yAxisIndex: 1,
  59. data: []
  60. },
  61. {
  62. name: '环比增长率(%)',
  63. type: 'line',
  64. yAxisIndex: 1,
  65. data: []
  66. }
  67. ],
  68. toolbox: {
  69. feature: {
  70. dataZoom: {
  71. xAxisIndex: false // 数据区域缩放:Y 轴不缩放
  72. },
  73. brush: {
  74. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  75. },
  76. saveAsImage: { show: true, name: '客户总量分析' } // 保存为图片
  77. }
  78. },
  79. tooltip: {
  80. trigger: 'axis',
  81. axisPointer: {
  82. type: 'shadow'
  83. }
  84. },
  85. yAxis: [{
  86. type: 'value',
  87. name: '金额(元)',
  88. axisTick: {
  89. show: false
  90. },
  91. axisLabel: {
  92. color: '#BDBDBD',
  93. formatter: '{value}'
  94. },
  95. /** 坐标轴轴线相关设置 */
  96. axisLine: {
  97. lineStyle: {
  98. color: '#BDBDBD'
  99. }
  100. },
  101. splitLine: {
  102. show: true,
  103. lineStyle: {
  104. color: '#e6e6e6'
  105. }
  106. }
  107. },
  108. {
  109. type: 'value',
  110. name: '',
  111. axisTick: {
  112. alignWithLabel: true,
  113. lineStyle: {
  114. width: 0
  115. }
  116. },
  117. axisLabel: {
  118. color: '#BDBDBD',
  119. formatter: '{value}%'
  120. },
  121. /** 坐标轴轴线相关设置 */
  122. axisLine: {
  123. lineStyle: {
  124. color: '#BDBDBD'
  125. }
  126. },
  127. splitLine: {
  128. show: true,
  129. lineStyle: {
  130. color: '#e6e6e6'
  131. }
  132. }
  133. }],
  134. xAxis: {
  135. type: 'category',
  136. name: '日期',
  137. data: []
  138. }
  139. }) as EChartsOption
  140. /** 获取统计数据 */
  141. const loadData = async () => {
  142. // 1. 加载统计数据
  143. loading.value = true
  144. const performanceList = await StatisticsPerformanceApi.getContractPricePerformance(
  145. props.queryParams
  146. )
  147. // 2.1 更新 Echarts 数据
  148. if (echartsOption.xAxis && echartsOption.xAxis['data']) {
  149. echartsOption.xAxis['data'] = performanceList.map(
  150. (s: StatisticsPerformanceRespVO) => s.time
  151. )
  152. }
  153. if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
  154. echartsOption.series[0]['data'] = performanceList.map(
  155. (s: StatisticsPerformanceRespVO) => s.currentMonthCount
  156. )
  157. }
  158. if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
  159. echartsOption.series[1]['data'] = performanceList.map(
  160. (s: StatisticsPerformanceRespVO) => s.lastMonthCount
  161. )
  162. echartsOption.series[3]['data'] = performanceList.map(
  163. (s: StatisticsPerformanceRespVO) => s.lastMonthCount !== 0 ? (s.currentMonthCount / s.lastMonthCount*100).toFixed(2) : 'NULL'
  164. )
  165. }
  166. if (echartsOption.series && echartsOption.series[2] && echartsOption.series[2]['data']) {
  167. echartsOption.series[2]['data'] = performanceList.map(
  168. (s: StatisticsPerformanceRespVO) => s.lastYearCount
  169. )
  170. echartsOption.series[4]['data'] = performanceList.map(
  171. (s: StatisticsPerformanceRespVO) => s.lastYearCount !== 0 ? (s.currentMonthCount / s.lastYearCount*100).toFixed(2) : 'NULL'
  172. )
  173. }
  174. // 2.2 更新列表数据
  175. list.value = performanceList
  176. loading.value = false
  177. }
  178. // 初始化数据
  179. const columnsData = reactive([]);
  180. const tableData = reactive([{title: '当月合同金额统计(元)'}, {title: '上月合同金额统计(元)'}, {title: '去年当月合同金额统计(元)'},
  181. {title: '同比增长率(%)'}, {title: '环比增长率(%)'}])
  182. // 定义 init 方法
  183. const init = () => {
  184. const columnObj = {label: '日期', prop: 'title'}
  185. columnsData.push(columnObj)
  186. list.value.forEach((item, index) => {
  187. const columnObj = {label: item.time, prop: 'prop' + index}
  188. columnsData.push(columnObj)
  189. tableData[0]['prop' + index] = item.currentMonthCount
  190. tableData[1]['prop' + index] = item.lastMonthCount
  191. tableData[2]['prop' + index] = item.lastYearCount
  192. tableData[3]['prop' + index] = item.lastYearCount !== 0 ? (item.currentMonthCount / item.lastYearCount).toFixed(2) : 'NULL'
  193. tableData[4]['prop' + index] = item.lastMonthCount !== 0 ? (item.currentMonthCount / item.lastMonthCount).toFixed(2) : 'NULL'
  194. })
  195. }
  196. defineExpose({ loadData })
  197. /** 初始化 */
  198. onMounted(async () => {
  199. await loadData()
  200. init()
  201. })
  202. </script>