coupon.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. let couponChart = null;
  2. let couponChartOption = {
  3. tooltip: {
  4. trigger: 'axis'
  5. },
  6. grid: {
  7. right: 15,
  8. bottom: 25
  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 mixin = {
  31. mounted() {
  32. couponChart = echarts.init(this.$refs['couponChart']);
  33. couponChart.setOption(couponChartOption);
  34. this.getCouponOverallData();
  35. this.getCouponStatisticsData();
  36. this.getCouponRankData();
  37. },
  38. data() {
  39. return {
  40. overall: {
  41. givenCoupon: 0,
  42. usedCoupon: 0,
  43. expiredCoupon: 0,
  44. receiveCoupon: 0
  45. },
  46. couponStatistics: {
  47. dataTime: null,
  48. data: []
  49. },
  50. couponRank: {
  51. pagination: {
  52. pages: 1,
  53. limit: 10,
  54. total: 50
  55. },
  56. data: []
  57. }
  58. }
  59. },
  60. methods: {
  61. getCouponOverallData() {
  62. this.fetchData(GetCouponOverallDataUrl).then(res => {
  63. this.overall = res.cumulative_data;
  64. });
  65. },
  66. getCouponStatisticsData() {
  67. couponChart.showLoading();
  68. this.fetchData(GetCouponStatisticsDataUrl, {
  69. time: this.couponStatistics.dataTime ? this.couponStatistics.dataTime / 1000 : null
  70. }).then(data => {
  71. let legendData = [];
  72. let xAxisData = null;
  73. let series = [];
  74. let statisticsData = [];
  75. for (const key in data) {
  76. if (Object.hasOwnProperty.call(data, key)) {
  77. const dataItem = data[key];
  78. legendData.push(dataItem['name']);
  79. if (xAxisData === null) {
  80. xAxisData = dataItem['x_axis'];
  81. }
  82. statisticsData.push({
  83. title: dataItem.name,
  84. tip: dataItem.tips,
  85. count: dataItem.value,
  86. key,
  87. decimals:this.getDecimals(dataItem.value)
  88. })
  89. series.push({
  90. name: dataItem.name,
  91. data: dataItem.series,
  92. type: "line",
  93. })
  94. }
  95. }
  96. this.couponStatistics.data = statisticsData;
  97. couponChart.setOption({
  98. legend: {
  99. data: legendData
  100. },
  101. xAxis: {
  102. data: xAxisData
  103. },
  104. series
  105. });
  106. couponChart.hideLoading();
  107. });
  108. },
  109. getCouponRankData(page = this.couponRank.pagination.pages) {
  110. let loading = this.$loading({
  111. target: "#couponRankPanel"
  112. })
  113. this.couponRank.pagination.pages = page;
  114. this.fetchData(GetCouponRankDataUrl, {
  115. page
  116. }).then(({
  117. data, per_page, total
  118. }) => {
  119. this.couponRank.pagination.limit = per_page;
  120. this.couponRank.pagination.total = total;
  121. for (let index = 0; index < data.length; index++) {
  122. data[index]['rank'] = (this.couponRank.pagination.pages - 1) * this.couponRank.pagination.limit + index + 1;
  123. }
  124. this.couponRank.data = data;
  125. loading.close();
  126. }).catch(() => {
  127. loading.close();
  128. })
  129. }
  130. }
  131. }