<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <!-- <topInfo></topInfo> -->
          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
        </el-col>
        <el-col :span="24" class="main">
          <mainData :lessionclassInfo="lessionclassInfo" :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';
const { mapActions: lesson } = createNamespacedHelpers('lesson');
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapStudent } = createNamespacedHelpers('student');
export default {
  name: 'index',
  props: {},
  components: {
    NavBar, //头部导航
    footInfo, //底部导航
    mainData, //课程安排主体
  },
  data: () => ({
    lessionclassInfo: { lessons: [] },
    dates: '',
    week: '',
    title: '日程安排',
    isleftarrow: '',
    transitionName: 'fade',
    navShow: true,
  }),
  created() {
    this.getDate();
    this.searchInfo();
    this.searchSite();
  },
  computed: {},
  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' }),
    ...mapStudent(['fetch']),
    async searchSite() {
      const res = await this.fetch('5e4f3d096a90e861b0f30871');
      sessionStorage.setItem('site', JSON.stringify(res.data));
    },
    async searchInfo({ ...info } = {}) {
      const res = await this.lessionlist({ ...info });
      for (const val of res.data) {
        var arr = res.data.filter(item => item.class === '5e4df0c93ffa245d6065f526');
        var aff = res.data[0].lessons;
        console.log(aff);
        var ahh = aff.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;
        });
        for (const aqq of aff) {
          var aee = aff.filter(item => item.date === '2020-01-04');
          this.$set(this.lessionclassInfo, `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>
