OrderRate.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div :class="className" id="echart-customer2" style="width: 100%; height: 260px;" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import { debounce } from '@/utils'
  8. import { getStorePaymentData } from "@/api/index";
  9. const animationDuration = 6000
  10. export default {
  11. props: {
  12. className: {
  13. type: String,
  14. default: 'chart2'
  15. },
  16. width: {
  17. type: String,
  18. default: '100%'
  19. },
  20. height: {
  21. type: String,
  22. default: '260px'
  23. }
  24. },
  25. data() {
  26. return {
  27. chart: null,
  28. dates:[],
  29. orderCount:[],
  30. payMoney:[]
  31. }
  32. },
  33. mounted() {
  34. this.getStorePaymentData()
  35. this.__resizeHandler = debounce(() => {
  36. if (this.chart) {
  37. this.chart.resize()
  38. }
  39. }, 100)
  40. window.addEventListener('resize', this.__resizeHandler)
  41. },
  42. beforeDestroy() {
  43. if (!this.chart) {
  44. return
  45. }
  46. window.removeEventListener('resize', this.__resizeHandler)
  47. this.chart.dispose()
  48. this.chart = null
  49. },
  50. methods: {
  51. getStorePaymentData(){
  52. var that=this;
  53. getStorePaymentData().then((response) => {
  54. this.dates=response.dates;
  55. this.orderCount=response.orderCount;
  56. this.payMoney=response.payMoney;
  57. setTimeout(() => {
  58. that.initEchart();
  59. }, 500);
  60. });
  61. },
  62. initEchart(){
  63. var option = {
  64. series: [{
  65. type: 'gauge',
  66. axisLine: {
  67. lineStyle: {
  68. width: 10,
  69. color: [
  70. [0.2, '#1c4587'],
  71. [0.8, '#980000'],
  72. [1, '#009100']
  73. ]
  74. }
  75. },
  76. pointer: {
  77. itemStyle: {
  78. color: 'auto'
  79. }
  80. },
  81. axisTick: {
  82. distance: -30,
  83. length: 8,
  84. lineStyle: {
  85. color: '#fff',
  86. width: 2
  87. }
  88. },
  89. splitLine: {
  90. distance: -30,
  91. length: 30,
  92. lineStyle: {
  93. color: '#fff',
  94. width: 4
  95. }
  96. },
  97. axisLabel: {
  98. color: 'auto',
  99. distance: 0,
  100. fontSize: 14
  101. },
  102. detail: {
  103. fontSize: 18,
  104. valueAnimation: true,
  105. formatter: '{value} %',
  106. color: 'auto'
  107. },
  108. data: [{
  109. value: 1
  110. }]
  111. }]
  112. };
  113. this.chart=echarts.init(document.getElementById("echart-customer2"));
  114. this.chart.setOption(option,true);
  115. },
  116. }
  117. }
  118. </script>