123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <template>
- <div class="chart-box">
- <div class="title-top">
- <span>toC 订单渠道</span>
- <el-select v-model="dateValue" size="mini" class="select" placeholder="请选择" @change="dateChange">
- <el-option v-for="item in options" :key="item.value" :label="item.label"
- :value="item.value"></el-option>
- </el-select>
- </div>
- <div class="chart" :id="id"></div>
- </div>
- </template>
- <script lang="ts">
- import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
- import * as echarts from 'echarts';
- type EChartsOption = echarts.EChartsOption;
- @Component
- export default class Pie02 extends Vue {
- id = this.randomString();
- dateValue = new Date().getMonth() + 1
- options: Array<any> = [{
- label: '1月',
- value: 1
- }, {
- label: '2月',
- value: 2
- }, {
- label: '3月',
- value: 3
- }, {
- label: '4月',
- value: 4
- }, {
- label: '5月',
- value: 5
- }, {
- label: '6月',
- value: 6
- }, {
- label: '7月',
- value: 7
- }, {
- label: '8月',
- value: 8
- }, {
- label: '9月',
- value: 9
- }, {
- label: '10月',
- value: 10
- }, {
- label: '11月',
- value: 11
- }, {
- label: '12月',
- value: 12
- }]
- mounted() {
- this.getData()
- }
- randomString() {
- const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- let result = '';
- for (let i = 10; i > 0; --i)
- result += str[Math.floor(Math.random() * str.length)];
- return result;
- }
- dateChange() {
- this.getData()
- }
- getData() {
- (this as any).$request({
- url: '/omsOrder/orderReport/orderChannel',
- method: 'GET',
- params: {
- month: this.dateValue
- }
- }).then((res: any) => {
- if (res.data) {
- this.initChart(res.data)
- }
- }).catch(() => { })
- }
- initChart(data: Array<any>) {
- let chartDom: any = document.getElementById(this.id);
- let myChart = echarts.init(chartDom);
- let option: EChartsOption;
- let _data: Array<any> = []
- for (const item of data) {
- if (item.shopSite === undefined) continue;
- _data.push({
- name: item.shopSite,
- value: item.total
- })
- }
- option = {
- tooltip: {
- trigger: 'item'
- },
- legend: {
- show: true,
- bottom: 0,
- type: 'scroll',
- orient: 'horizontal',
- },
- series: [
- {
- type: 'pie',
- radius: ['40%', '70%'],
- avoidLabelOverlap: false,
- itemStyle: {
- borderRadius: 10,
- borderColor: '#fff',
- borderWidth: 2
- },
- label: {
- formatter: '{b}:\n {d}' + '%',
- position: 'inside'
- },
- emphasis: {
- label: {
- show: true,
- fontSize: 20,
- fontWeight: 'bold'
- }
- },
- labelLine: {
- show: false
- },
- data: _data
- }
- ]
- };
- option && myChart.setOption(option);
- }
- }
- </script>
- <style lang="scss" scoped>
- .chart-box {
- height: 100%;
- width: 100%;
- .title-top {
- height: 40px;
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
- width: 100%;
- >span {
- font-size: 16px;
- font-weight: 700;
- }
- .select {
- width: 100px;
- position: absolute;
- top: 6px;
- right: 0;
- }
- }
- }
- .chart {
- height: calc(100% - 40px);
- width: 100%;
- }
- </style>>
|