<template>
  <div class="app-container">
    <div>
      <!-- 学年/学期 -->
      <!-- 这里的@selecrYear是接收timeSelect提交的事件 -->
      <time-select
        style="margin-top: 30px"
        ref="timeSelect"
        @selectYear="load"
        @selectSemester="load"
      ></time-select>
      <!-- 课程表 -->
      <tb-course
        ref="tbCourse"
        table-label="我的课表"
        label="我的课表"
        :custom="true"
      ></tb-course>
    </div>
  </div>
</template>

<script>
import tbCourse from "@/views/components/tbCourse";
import timeSelect from "@/views/components/timeSelect";
import tableApi from "@/api/labbooking/table.js";

export default {
  name: "myCourse1",
  components: {
    tbCourse,
    timeSelect,
  },
  data() {
    return {
      tableData: [],
    };
  },

  mounted() {
    this.load();
  },

  methods: {
    load() {
      // console.log(this.$refs.timeSelect.year, this.$refs.timeSelect.semester)
      //重置课表，不要问我为什么这样重置，问就是师兄nmd有问题
      this.init();
      //向后端传year和term两个参数,封装成对象
      tableApi
        .list({
          year: this.$refs.timeSelect.year,
          term: this.$refs.timeSelect.semester,
        })
        .then((res) => {
          this.tableData = res.data;
          // console.log(this.tableData);
          if (this.tableData != null) {
            for (let i = 0; i < this.tableData.length; i++) {
              let time = this.tableData[i].time;
              if (this.tableData[i].day == 1)
                this.$refs.tbCourse.tableData[time - 1].Monday =
                  this.tableData[i];
              if (this.tableData[i].day == 2)
                this.$refs.tbCourse.tableData[time - 1].Tuesday =
                  this.tableData[i];
              if (this.tableData[i].day == 3)
                this.$refs.tbCourse.tableData[time - 1].Wednesday =
                  this.tableData[i];
              if (this.tableData[i].day == 4)
                this.$refs.tbCourse.tableData[time - 1].Thursday =
                  this.tableData[i];
              if (this.tableData[i].day == 5)
                this.$refs.tbCourse.tableData[time - 1].Friday =
                  this.tableData[i];
              if (this.tableData[i].day == 6)
                this.$refs.tbCourse.tableData[time - 1].Saturday =
                  this.tableData[i];
              if (this.tableData[i].day == 7)
                this.$refs.tbCourse.tableData[time - 1].Sunday =
                  this.tableData[i];
            }
          }
        });
    },

    // async load(){
    //     this.tableData = await get('lb/labrecord/getUserScheduleBySelf',{
    //         year: this.$refs.timeSelect.year,
    //         semester: this.$refs.timeSelect.semester
    //     })           //发送地址，请求该实验室地址的所有课程
    //     for (let i = 0; i < this.tableData.length; i++) {
    //         this.$refs.tbCourse.tableData[i].Monday = item2html(this.tableData[i][0])
    //         this.$refs.tbCourse.tableData[i].Tuesday =  item2html(this.tableData[i][1])
    //         this.$refs.tbCourse.tableData[i].Wednesday =  item2html(this.tableData[i][2])
    //         this.$refs.tbCourse.tableData[i].Thursday =  item2html(this.tableData[i][3])
    //         this.$refs.tbCourse.tableData[i].Friday =  item2html(this.tableData[i][4])
    //         this.$refs.tbCourse.tableData[i].Saturday =  item2html(this.tableData[i][5])
    //         this.$refs.tbCourse.tableData[i].Sunday =  item2html(this.tableData[i][6])
    //     }
    // },

    //初始化课表
    init() {
      this.$refs.tbCourse.tableData = [
        {
          index: 1,
          day: "上午",
          time: "第一节",
          Monday: "",
          Tuesday: "",
          Wednesday: "",
          Thursday: "",
          Friday: "",
          Saturday: "",
          Sunday: "",
        },
        {
          index: 2,
          day: "上午",
          time: "第二节",
          Monday: "",
          Tuesday: "",
          Wednesday: "",
          Thursday: "",
          Friday: "",
          Saturday: "",
          Sunday: "",
        },
        {
          index: 3,
          day: "下午",
          time: "第三节",
          Monday: "",
          Tuesday: "",
          Wednesday: "",
          Thursday: "",
          Friday: "",
          Saturday: "",
          Sunday: "",
        },
        {
          index: 4,
          day: "下午",
          time: "第四节",
          Monday: "",
          Tuesday: "",
          Wednesday: "",
          Thursday: "",
          Friday: "",
          Saturday: "",
          Sunday: "",
        },
        {
          index: 5,
          day: "晚上",
          time: "第五节",
          Monday: "",
          Tuesday: "",
          Wednesday: "",
          Thursday: "",
          Friday: "",
          Saturday: "",
          Sunday: "",
        },
      ];
    },

    cellClick() {},
    tableStyle() {},
  },
};
</script>

<style scoped>
</style>