pie01.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="chart-box">
  3. <div class="title-top">
  4. <span>区域销量</span>
  5. <el-select v-model="areatValue" size="mini" class="select" placeholder="请选择" @change="areaChange">
  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 Pie01 extends Vue {
  18. id=this.randomString();
  19. areatValue=1
  20. options:Array<any>=[{
  21. label:'省级',
  22. value:1
  23. },{
  24. label:'市级',
  25. value: 2
  26. }]
  27. mounted(){
  28. this.getData()
  29. }
  30. randomString(){
  31. const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  32. let result = '';
  33. for (let i = 10; i > 0; --i)
  34. result += str[Math.floor(Math.random() * str.length)];
  35. return result;
  36. }
  37. areaChange() {
  38. this.getData()
  39. }
  40. initChart(data:Array<any>){
  41. let chartDom:any = document.getElementById(this.id);
  42. let myChart = echarts.init(chartDom);
  43. let option: EChartsOption;
  44. let _data=[]
  45. for(const item of data) {
  46. _data.push({
  47. name: item.area,
  48. value:item.total
  49. })
  50. }
  51. option = {
  52. tooltip: {
  53. trigger: 'item'
  54. },
  55. legend: {
  56. // orient: 'vertical',
  57. show:true,
  58. bottom:0
  59. },
  60. series: [
  61. {
  62. type: 'pie',
  63. radius: '50%',
  64. data:_data,
  65. emphasis: {
  66. itemStyle: {
  67. shadowBlur: 10,
  68. shadowOffsetX: 0,
  69. shadowColor: 'rgba(0, 0, 0, 0.5)'
  70. }
  71. },
  72. label:{
  73. formatter: '{b}: {d}' + '%'
  74. }
  75. }
  76. ]
  77. };
  78. option && myChart.setOption(option);
  79. }
  80. getData() {
  81. (this as any).$request({
  82. url:'/omsOrder/report/areaSalesTop',
  83. method: 'GET',
  84. params:{
  85. level:this.areatValue
  86. }
  87. }).then((res:any) => {
  88. if(res.data) {
  89. this.initChart(res.data)
  90. }
  91. }).catch(() =>{})
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .chart-box{
  97. height: 100%;
  98. width: 100%;
  99. .title-top{
  100. height: 40px;
  101. display: flex;
  102. justify-content: center;
  103. align-items: center;
  104. position: relative;
  105. width: 100%;
  106. >span{
  107. font-size: 16px;
  108. font-weight: 700;
  109. }
  110. .select{
  111. width: 100px;
  112. position: absolute;
  113. top: 6px;
  114. right: 0;
  115. }
  116. }
  117. }
  118. .chart{
  119. height: calc(100% - 40px);
  120. width: 100%;
  121. }
  122. </style>