<template>
  <div class="app-container">
    <span v-for="(value, index) in dateList">
      <el-link @click="handleReport(value)">{{value}}</el-link><br/>
    </span>
  </div>
</template>

<script>
  import axios from 'axios';
  import { treeselect } from "@/api/system/dept";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import { yearMonth } from "@/api/production/quality";


  export default {
    name: "history.vue",
    data(){
      return {
        dateList: [],
        sampleDate: [],
      }
    },
    created() {
      yearMonth().then(response => {
        this.dateList = response.data;
      });
    },
    methods: {
      handleReport(value) {
        let array = value.split('-');
        var date = new Date();
        date.setFullYear(array[0]);
        date.setMonth(array[1])
        var firstDay = new Date(date.getFullYear(), date.getMonth() - 1, 1);
        var lastDay = new Date(date.getFullYear(), date.getMonth(), 0);
        let sampleDate = [
          firstDay.getFullYear() + '-' + Number(firstDay.getMonth() + 1) + '-' + firstDay.getDate(),
          lastDay.getFullYear() + '-' + Number(lastDay.getMonth() + 1) + '-' + lastDay.getDate()
        ];
        this.$router.push({
          name: "report",
          params: sampleDate
        });
      }
    }
  }
</script>
