Newer
Older
smartKitchenFront / src / views / dashboard / components / supplierAssessment.vue
<template>
  <div class="chart-container" :style="{ height: height, width: width }">
    <div class="chart-header">
      <!--标题  -->
      <span class="title">供应商年度考核统计</span>
    </div>
    <div class="chart-content"  :style="{ 'height': parseInt(height) - 40 + 'px'}">
      <!-- echarts内容 -->
      <lineChart
        :seriesData="seriesData"
        :xAxisData="xAxisData"
        :yAxisData="yAxisData"
        :legend="legend"
      />
    </div>
  </div>
</template>
    
    <script>
import lineChart from "../../../components/echart/lineChart/lineChart.vue";
import { getAnnualAssess } from "@/api/cockpit/cockpit";
export default {
  name: "supplierAss",
  components: {
    lineChart,
  },
  props: {
    name: {
      type: String,
      default: "",
    },
    width: {
      type: String,
      default: "500px",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      xAxisData: [],
      yAxisData: [],
      seriesData: [],
      legend: [],
    };
  },
  mounted() {
    this.fetchData();
    // setTimeout(() => {
    //   this.seriesData = [
    //     {
    //       name: "a",
    //       type: "line",
    //       data: [13, 15, 19, 33],
    //     },
    //     {
    //       name: "b",
    //       type: "line",
    //       data: [19, 17, 13, 23],
    //     },
    //     {
    //       name: "c",
    //       type: "line",
    //       data: [33, 46, 39, 43],
    //     },
    //     {
    //       name: "d",
    //       type: "line",
    //       data: [23, 55, 41, 37],
    //     },
    //   ];
    //   this.xAxisData = ["2019", "2020", "2021", "2022"];
    //   this.yAxisData = [
    //     {
    //       type: "value",
    //       show: true,
    //       axisLabel: {
    //         formatter: "{value}",
    //         fontSize: 12,
    //         color: "#000",
    //       },
    //       axisLine: {
    //         show: false,
    //       },
    //       splitLine: {
    //         //多条横线
    //         show: true,
    //       },
    //       interval: 20,
    //     },
    //   ];
    //   console.log(this.xAxisData, "this.xAxisData");
    // }, 2000);
  },
  methods: {
    fetchData() {
      getAnnualAssess().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.slice(0,seriesData.length-1).map(item => {
          return {
            ...item,
            type:'line'
          }
        })
        this.xAxisData = seriesData[seriesData.length-1].data
        this.yAxisData = [
        {
          type: "value",
          show: true,
          axisLabel: {
            formatter: "{value}",
            fontSize: 12,
            color: "#000",
          },
          axisLine: {
            show: false,
          },
          splitLine: {
            //多条横线
            show: true,
          },
          interval: 20,
        },
      ];
      this.legend = legend.slice(0,legend.length-1)
      });
    },
  },
  watch: {
    value(newVal) {
      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;
  }
}
</style>