orderChannel.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. if (item.shopSite === undefined) continue;
  91. _data.push({
  92. name: item.shopSite,
  93. value: item.total
  94. })
  95. }
  96. option = {
  97. tooltip: {
  98. trigger: 'item'
  99. },
  100. legend: {
  101. show: true,
  102. bottom: 0,
  103. type: 'scroll',
  104. orient: 'horizontal',
  105. },
  106. series: [
  107. {
  108. type: 'pie',
  109. radius: ['40%', '70%'],
  110. avoidLabelOverlap: false,
  111. itemStyle: {
  112. borderRadius: 10,
  113. borderColor: '#fff',
  114. borderWidth: 2
  115. },
  116. label: {
  117. formatter: '{b}:\n {d}' + '%',
  118. position: 'inside'
  119. },
  120. emphasis: {
  121. label: {
  122. show: true,
  123. fontSize: 20,
  124. fontWeight: 'bold'
  125. }
  126. },
  127. labelLine: {
  128. show: false
  129. },
  130. data: _data
  131. }
  132. ]
  133. };
  134. option && myChart.setOption(option);
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .chart-box {
  140. height: 100%;
  141. width: 100%;
  142. .title-top {
  143. height: 40px;
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. position: relative;
  148. width: 100%;
  149. >span {
  150. font-size: 16px;
  151. font-weight: 700;
  152. }
  153. .select {
  154. width: 100px;
  155. position: absolute;
  156. top: 6px;
  157. right: 0;
  158. }
  159. }
  160. }
  161. .chart {
  162. height: calc(100% - 40px);
  163. width: 100%;
  164. }
  165. </style>>