<template>
  <div id="card-1">
    <el-row>
      <el-col :span="24" class="main">
        <div id="card_one" style="width: 37vw; height: 17vw"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts';
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'index',
  props: { list: { type: Array } },
  components: {},
  data: function () {
    return {
      xAxisList: [],
      seriesList: [],
    };
  },
  computed: {
    ...mapState(['user']),
  },
  mounted() {},
  created() {},
  methods: {
    getEchartData(data) {
      var chartDom = document.getElementById('card_one');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: '本周下单数',
        },
        color: '#FFD700',
        tooltip: {
          trigger: 'axis',
        },
        xAxis: {
          type: 'category',
          data: this.xAxisList,
          // 设置x轴线的属性
          //使x轴文字显示全
          axisLabel: {
            show: true,
            rotate: 50,
          },
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            data: this.seriesList,
            type: 'line',
          },
        ],
      };
      myChart.setOption(option);
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    list: {
      deep: true,
      handler(val) {
        let xAxisList = [];
        let seriesList = [];
        for (const p1 of val) {
          xAxisList.push(p1.date);
          seriesList.push(p1.num);
        }
        this.$set(this, 'xAxisList', xAxisList);
        this.$set(this, 'seriesList', seriesList);
        this.getEchartData();
      },
    },
  },
};
</script>

<style lang="less" scoped></style>
