income.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. let incomeChart = null;
  2. let incomeChartOption = {
  3. tooltip: {
  4. trigger: 'axis',
  5. },
  6. grid: {
  7. bottom: 25,
  8. right:30
  9. },
  10. xAxis: {
  11. type: 'category',
  12. data: []
  13. },
  14. yAxis: {
  15. type: 'value',
  16. splitLine: {
  17. show: true,
  18. lineStyle: {
  19. type: 'dashed',
  20. color: "#f0f3f6",
  21. opacity: 1
  22. }
  23. }
  24. },
  25. series: [{
  26. data: [],
  27. type: 'line'
  28. }]
  29. }
  30. const incomeMixin = {
  31. data() {
  32. return {
  33. timeRanges: {
  34. time: null,
  35. type: null,
  36. },
  37. rank: {
  38. data: [],
  39. pagination: {
  40. pages: 1,
  41. total: 10,
  42. limit: 10
  43. }
  44. }
  45. }
  46. },
  47. mounted() {
  48. incomeChart = echarts.init(this.$refs['incomeChart']);
  49. incomeChart.setOption(incomeChartOption);
  50. this.getOverallData();
  51. this.getStatisticsData();
  52. this.getRankData();
  53. },
  54. methods: {
  55. incomeTimerangeChanged({ timeRange, timeRangeType }) {
  56. this.timeRanges = {
  57. time: timeRange ? typeof(timeRange) == 'number' ? timeRange / 1000 :{start:timeRange[0],end:timeRange[1]}: null,
  58. type: timeRangeType
  59. }
  60. this.getStatisticsData();
  61. },
  62. getOverallData() {
  63. this.fetchData(overallUrl).then(res => {
  64. let overallData = res.cumulative_data;
  65. for (const key in overallData) {
  66. if (this.statistics[key]) {
  67. this.statistics[key]['counts'] = overallData[key];
  68. }
  69. }
  70. });
  71. },
  72. getStatisticsData() {
  73. incomeChart.showLoading();
  74. this.fetchData(statisticsUrl, {
  75. time_type: this.timeRanges.type,
  76. time: this.timeRanges.time,
  77. }).then(data => {
  78. let legendData = [];
  79. let xAxisData = null;
  80. let series = [];
  81. let statisticsData = [];
  82. for (const key in data) {
  83. if (Object.hasOwnProperty.call(data, key)) {
  84. const dataItem = data[key];
  85. legendData.push(dataItem.name);
  86. if (xAxisData === null) {
  87. xAxisData = dataItem['x_axis'];
  88. }
  89. series.push({
  90. type: "line",
  91. name: dataItem.name,
  92. data: dataItem.series
  93. });
  94. statisticsData.push({
  95. title: dataItem.name,
  96. tip: dataItem.tips,
  97. counts: dataItem.value,
  98. key,
  99. decimals:this.getDecimals(dataItem.value)
  100. });
  101. }
  102. }
  103. this.chartStatistics = statisticsData;
  104. incomeChart.setOption({
  105. legend: {
  106. data: legendData,
  107. },
  108. xAxis: {
  109. data: xAxisData
  110. },
  111. series
  112. });
  113. incomeChart.hideLoading();
  114. });
  115. },
  116. getRankData(page = this.rank.pagination.pages) {
  117. this.rank.pagination.pages = page;
  118. let loading = this.$loading({
  119. target: "#rankPanel"
  120. })
  121. this.fetchData(rankDataUrl, {
  122. page
  123. }).then(({ total, per_page, data }) => {
  124. this.rank.pagination.limit = per_page;
  125. this.rank.pagination.total = total;
  126. for (let index = 0; index < data.length; index++) {
  127. data[index]['rank'] = (this.rank.pagination.pages - 1) * this.rank.pagination.limit + index + 1;
  128. }
  129. this.rank.data = data;
  130. loading.close();
  131. }).catch(() => {
  132. loading.close();
  133. })
  134. }
  135. }
  136. };