goods.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. let goodsChart = null;
  2. let goodsChartOption = {
  3. toolbox: {
  4. show: true,
  5. },
  6. tooltip: {
  7. trigger: 'axis',
  8. },
  9. xAxis: {
  10. type: 'category',
  11. data: []
  12. },
  13. grid:{
  14. right:15,
  15. bottom:35
  16. },
  17. yAxis: {
  18. type: 'value',
  19. splitLine: {
  20. show: true,
  21. lineStyle: {
  22. type: 'dashed',
  23. color: "#f0f3f6",
  24. opacity: 1
  25. }
  26. }
  27. },
  28. series: []
  29. }
  30. const mixin = {
  31. mounted() {
  32. this.getGoodsOverallData();
  33. goodsChart = echarts.init(this.$refs['goodsChart']);
  34. goodsChart.setOption(goodsChartOption);
  35. this.getGoodsStatisticsData();
  36. },
  37. data() {
  38. return {
  39. overall: {
  40. goods_count: 0,
  41. pay_goods_count: 0,
  42. order_goods_count: 0
  43. },
  44. goodsSaleRank: [],
  45. categorySaleRank: [],
  46. goodsSaleAmountRank: [],
  47. goodsStatistics: [],
  48. goodsSearch: {
  49. timeRangeType: "key",
  50. timeRange: null
  51. }
  52. }
  53. },
  54. methods: {
  55. getGoodsOverallData() {
  56. let loading = this.$loading({
  57. target: "#goodsRankList"
  58. });
  59. this.fetchData(GetGoodsOverallData).then(res => {
  60. this.overall = res.cumulative_data;
  61. this.goodsSaleRank = res.goods_sales.data;
  62. this.categorySaleRank = res.category_goods_sales.data;
  63. this.goodsSaleAmountRank = res.goods_sales_amount.data;
  64. loading.close();
  65. }).catch(() => {
  66. loading.close();
  67. })
  68. },
  69. goodsTimeRangeChanged({ timeRange, timeRangeType }) {
  70. this.goodsSearch = {
  71. timeRange: timeRange ? timeRange / 1000 : null, timeRangeType
  72. }
  73. this.getGoodsStatisticsData();
  74. },
  75. getGoodsStatisticsData() {
  76. goodsChart.showLoading();
  77. this.fetchData(GetGoodsStatisticsDataUrl, {
  78. time_type: this.goodsSearch.timeRangeType,
  79. time: this.goodsSearch.timeRange
  80. }).then(res => {
  81. let goodsStatistics = [];
  82. let XAxisData = res[0]['x_axis'];
  83. let series = [];
  84. let legendData = [];
  85. res.forEach(item => {
  86. legendData.push(item.name);
  87. goodsStatistics.push({
  88. title: item.name,
  89. count: item.value,
  90. tip: item.tips
  91. });
  92. series.push({
  93. name: item.name,
  94. type: "line",
  95. data: item.series
  96. })
  97. });
  98. this.goodsStatistics = goodsStatistics;
  99. goodsChart.setOption({
  100. legend: {
  101. data: legendData
  102. },
  103. xAxis: {
  104. data: XAxisData
  105. },
  106. series
  107. });
  108. goodsChart.hideLoading();
  109. });
  110. }
  111. }
  112. }