orderChannel.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="chart-box">
  3. <div class="title-top">
  4. <span>toC 订单渠道</span>
  5. <el-select v-model="dateValue" size="mini" class="select" placeholder="请选择" @change="dateChange">
  6. <el-option v-for="item in options" :key="item.value" :label="item.label"
  7. :value="item.value"></el-option>
  8. </el-select>
  9. </div>
  10. <div class="chart" :id="id"></div>
  11. </div>
  12. </template>
  13. <script lang="ts">
  14. import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
  15. import * as echarts from 'echarts';
  16. type EChartsOption = echarts.EChartsOption;
  17. @Component
  18. export default class Pie02 extends Vue {
  19. id = this.randomString();
  20. dateValue = new Date().getMonth() + 1
  21. options: Array<any> = [{
  22. label: '1月',
  23. value: 1
  24. }, {
  25. label: '2月',
  26. value: 2
  27. }, {
  28. label: '3月',
  29. value: 3
  30. }, {
  31. label: '4月',
  32. value: 4
  33. }, {
  34. label: '5月',
  35. value: 5
  36. }, {
  37. label: '6月',
  38. value: 6
  39. }, {
  40. label: '7月',
  41. value: 7
  42. }, {
  43. label: '8月',
  44. value: 8
  45. }, {
  46. label: '9月',
  47. value: 9
  48. }, {
  49. label: '10月',
  50. value: 10
  51. }, {
  52. label: '11月',
  53. value: 11
  54. }, {
  55. label: '12月',
  56. value: 12
  57. }]
  58. mounted() {
  59. this.getData()
  60. }
  61. randomString() {
  62. const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  63. let result = '';
  64. for (let i = 10; i > 0; --i)
  65. result += str[Math.floor(Math.random() * str.length)];
  66. return result;
  67. }
  68. dateChange() {
  69. this.getData()
  70. }
  71. getData() {
  72. (this as any).$request({
  73. url: '/omsOrder/orderReport/orderChannel',
  74. method: 'GET',
  75. params: {
  76. month: this.dateValue
  77. }
  78. }).then((res: any) => {
  79. if (res.data) {
  80. this.initChart(res.data)
  81. }
  82. }).catch(() => { })
  83. }
  84. initChart(data: Array<any>) {
  85. let chartDom: any = document.getElementById(this.id);
  86. let myChart = echarts.init(chartDom);
  87. let option: EChartsOption;
  88. let _data: Array<any> = []
  89. for (const item of data) {
  90. _data.push({
  91. name: item.shopSite,
  92. value: item.total
  93. })
  94. }
  95. option = {
  96. tooltip: {
  97. trigger: 'item'
  98. },
  99. legend: {
  100. show: true,
  101. bottom: 0,
  102. type: 'scroll',
  103. orient: 'horizontal',
  104. },
  105. series: [
  106. {
  107. type: 'pie',
  108. radius: ['40%', '70%'],
  109. avoidLabelOverlap: false,
  110. itemStyle: {
  111. borderRadius: 10,
  112. borderColor: '#fff',
  113. borderWidth: 2
  114. },
  115. label: {
  116. formatter: '{b}:\n {d}' + '%',
  117. position: 'inside'
  118. },
  119. emphasis: {
  120. label: {
  121. show: true,
  122. fontSize: 20,
  123. fontWeight: 'bold'
  124. }
  125. },
  126. labelLine: {
  127. show: false
  128. },
  129. data: _data
  130. }
  131. ]
  132. };
  133. option && myChart.setOption(option);
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .chart-box {
  139. height: 100%;
  140. width: 100%;
  141. .title-top {
  142. height: 40px;
  143. display: flex;
  144. justify-content: center;
  145. align-items: center;
  146. position: relative;
  147. width: 100%;
  148. >span {
  149. font-size: 16px;
  150. font-weight: 700;
  151. }
  152. .select {
  153. width: 100px;
  154. position: absolute;
  155. top: 6px;
  156. right: 0;
  157. }
  158. }
  159. }
  160. .chart {
  161. height: calc(100% - 40px);
  162. width: 100%;
  163. }
  164. </style>>