Newer
Older
smartKitchenFront / src / views / dashboard / components / opportunityStatistics.vue
<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内容 -->
      <MixChart
        :seriesData="seriesData"
        :legend="legend"
        :xAxisData="xAxisData"
        :yAxisData="yAxisData"
        :style="{ 'height': parseInt(height) - 40 + 'px'}"
      />
    </div>
  </div>
</template>
    
    <script>
import MixChart from "@/components/echart/barChart/MixChart.vue";
import { getOpportunityStatistics } from "@/api/cockpit/cockpit";
export default {
  name: "commonSelectChart",
  components: {
    MixChart,
  },
  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:'bar',
    //       name:'商机个数',
    //       data:[19,22,24,29,14,36,35]
    //     },
    //     {
    //       type:'bar',
    //       name:'商机转订单个数',
    //       data:[11,32,29,29,44,31,15]
    //     }
    //   ]
    //   this.xAxisData = ['一月','二月','三月','四月','五月','六月','七月']
    //   this.legend = ['商机个数','商机转订单个数']
    //   this.yAxisData = [
    //   {
    //           type: "value",
    //           show: true,
    //           axisLabel: {
    //             formatter: "{value}",
    //             fontSize: 12,
    //             color: "#000",
    //           },
    //           axisLine: {
    //             show: false,
    //           },
    //           splitLine: {
    //             //多条横线
    //             show: true,
    //           },
    //           interval: 20,
    //         },
    //   ]
    // }, 2000);
  },
  methods: {
    fetchData() {
      getOpportunityStatistics(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 = [
          {
            type: "bar",
            name: "商机个数",
            data: seriesData[1].data,
          },
          {
            type: "bar",
            name: "商机转订单个数",
            data: seriesData[2].data,
          },
        ];
        this.xAxisData = seriesData[0].data;
        // this.yAxisData = [
        //   {
        //     type: "value",
        //     show: true,
        //     axisLabel: {
        //       formatter: "{value}",
        //       fontSize: 12,
        //       color: "#000",
        //     },
        //     axisLine: {
        //       show: false,
        //     },
        //     splitLine: {
        //       //多条横线
        //       show: true,
        //     },
        //     interval: 20,
        //   },
        // ];
        this.legend = ['商机个数','商机转订单个数']
      });
    },
  },
  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;
    display:flex;
    justify-content: space-between;
  }
}
</style>