pie02.vue 2.9 KB

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