<template> <div class="chart-container"> <div class="chart-header"> <!--标题 --> <span class="title">供应商状态统计</span> </div> <div class="chart-content" :style="{ height: height, width: width }"> <!-- echarts内容 --> <doughnutChart :seriesData="seriesData" :title="title"/> </div> </div> </template> <script> import doughnutChart from "../../../components/echart/pieChart/doughnutChart.vue"; import { getSupplierStatus } from "@/api/cockpit/cockpit"; export default { name: "supplierStatus", components: { doughnutChart, }, props: { name: { type: String, default: "", }, width: { type: String, default: "500px", }, height: { type: String, default: "300px", }, }, data() { return { seriesData: [], indicator: [], title:'' }; }, mounted() { this.fetchData(); //真实获取数据,后期接口完成直接使用 // setTimeout(() => { // // 模拟数据后期注释掉 // let data = [ // { // status: "1", // statusName: "审核通过", // supplierCount: 70, // }, // { // status: "2", // statusName: "审核中", // supplierCount: 30, // }, // { // status: "3", // statusName: "审核不通过", // supplierCount: 20, // }, // ]; // this.seriesData = data.map((item) => { // return { // value: item.supplierCount, // name: item.statusName, // }; // }); // this.indicator = data.map((item) => { // return { // name: item.statusName, // max: item.supplierCount + 10, // }; // }); // this.title = `总\n\n50` // }, 2000); }, methods: { fetchData() { getSupplierStatus().then((res) => { this.seriesData = res.data.map((item) => { return { value: item.supplierCount, name: item.statusName, }; }); this.indicator = res.data.map((item) => { return { name: item.statusName, max: item.supplierCount + 10, }; }); let arr =[] res.data.forEach(element => { arr.push(element.supplierCount) }); this.title = `总\n\n${arr.reduce((pre,cur) => pre + cur)}` }); }, }, }; </script> <style lang="scss" scoped> .chart-container { .chart-header { width: 600px; align-items: center; display: flex; justify-content: space-between; } .chart-content { // width: 600px; // height: 400px; } } </style>