<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
        </el-col>
        <el-col :span="24" class="main">
          <mainData :lessons="lessons" :week="week"></mainData>
        </el-col>
        <el-col :span="24" class="foot">
          <footInfo></footInfo>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import footInfo from '@/layout/common/footInfo.vue';
import mainData from '@/layout/index/mainData.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: lesson } = createNamespacedHelpers('lesson');
const { mapActions: classes } = createNamespacedHelpers('classes');

export default {
  name: 'index',
  props: {},
  components: {
    NavBar, //头部导航
    footInfo, //底部导航
    mainData, //课程安排主体
  },
  data: () => ({
    lessons: [],
    dates: '',
    week: '',
    title: '日程安排',
    isleftarrow: '',
    navShow: true,
  }),
  created() {
    this.getDate();
    this.searchInfo();
  },
  computed: {
    ...mapState(['user']),
  },
  mounted() {
    this.title = this.$route.meta.title;
    this.isleftarrow = this.$route.meta.isleftarrow;
  },
  watch: {
    $route(to, from) {
      this.title = to.meta.title;
      this.isleftarrow = to.meta.isleftarrow;
    },
  },
  methods: {
    ...lesson({ lessionInfo: 'fetch', lessionlist: 'query' }),
    ...classes({ classesInfo: 'fetch', classeslist: 'query' }),
    // 查询课程详情
    async searchInfo() {
      const res = await this.classesInfo(this.user.classid);
      console.log(res.data);
      const result = await this.lessionInfo(res.data.lessonid);
      console.log(result.data);
      var ahh = result.data.lessons.map((i, index) => {
        let word = '';
        if (index == 1) word = '拓展交流';
        if (index == 2) word = '课程作业小组展示';
        if (index == 3) word = '课程作业';
        if (index == 4) word = '礼仪课小组面试';
        if (index == 5) word = '结业仪式';
        i.lastLesson = word;
        return i;
      });
      var aee = result.data.lessons.filter(item => item.date === '2020-01-02');
      this.$set(this, `lessons`, aee);
    },
    // 获取时间
    getDate() {
      var adate = new Date();
      this.value = adate.getFullYear() + '-' + (adate.getMonth() + 1) + '-' + adate.getDate();
      this.$set(this, `dates`, this.value);
      var str = '星期' + '日一二三四五六'.charAt(new Date().getDay());
      this.$set(this, `week`, str);
    },
  },
};
</script>

<style lang="less" scoped>
.style {
  width: 100%;
  min-height: 667px;
  position: relative;
  background-color: #f9fafc;
}
.top {
  height: 46px;
  overflow: hidden;
}
.main {
  min-height: 570px;
}
.foot {
  height: 50px;
  overflow: hidden;
}
</style>
