<template> <div class="chart-container" :style="{ 'height': height, 'width': width }"> <div class="chart-header"> <!--标题 --> <span class="title">订单统计</span> <el-select v-model="value" placeholder="请选择" size="mini"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" > </el-option> </el-select> </div> <div class="chart-content" :style="{ 'height': parseInt(height) - 40 + 'px'}"> <!-- echarts内容 --> <lineChart :seriesData="seriesData" :xAxisData="xAxisData" :legend="legend"/> </div> </div> </template> <script> import lineChart from "../../../components/echart/lineChart/lineChart.vue"; import { getUserCountStatistic } from "@/api/cockpit/cockpit"; export default { name: "layoutChartSelect", components: { lineChart, }, props: { name: { type: String, default: "", }, width: { type: String, default: "500px", }, height: { type: String, default: "300px", }, }, data() { return { value: "year", options: [ { value: "year", label: "近一年", }, { value: "month", label: "近一月", }, ], xAxisData: [], yAxisData: [], seriesData: [], legend: [], }; }, mounted() { this.fetchData(); // setTimeout(() => { // this.seriesData = [ // { // type:'line', // name:'经销商订单数', // data:[19,22,24,29,14,36,35] // }, // { // type:'line', // name:'分公司订单数', // data:[11,32,29,29,44,31,15] // } // ] // this.xAxisData = ['一月','二月','三月','四月','五月','六月','七月'] // this.legend = ['经销商订单数','分公司订单数'] // }, 2000); }, methods: { fetchData() { getUserCountStatistic(this.value).then((res) => { // 图表数据 let seriesData = []; let legend = [] if (res.data.length > 0) { for (var user in res.data[0]) { legend.push(user); seriesData.push({ name: user, data: [], }); } } for (var i = 0; i < res.data.length; i++) { seriesData.forEach((item) => { if (item.name in res.data[i]) { item.data.push(res.data[i][item.name]); } }); } this.seriesData = [{...seriesData[0],name:'分公司订单数'},{...seriesData[2],name:'经销商订单数'}] this.xAxisData = seriesData[1].data; this.legend = ['分公司订单数','经销商订单数'] }); }, }, watch:{ value(){ this.fetchData() } } }; </script> <style lang="scss" scoped> .chart-container { background: #edf5f8; border-radius: 8px; margin:10px; padding: 10px; .chart-header { font-size: 14px; color: #2076A1; font-weight: 700; display:flex; justify-content: space-between; } } </style>