ReceivablePricePerformance.vue 6.1 KB

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