<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">
          <span v-if="display">
            <el-col :span="24" class="list" v-for="(item, index) in planList" :key="index" @click.native="toClass(item.id)">
              <p>计划年份：{{ item.year }}</p>
              <p>计划标题：{{ item.title }}</p>
            </el-col>
          </span>
          <span v-else>
            <el-col :span="24" class="list" v-for="(item, index) in classList" :key="index" @click.native="classBtn(item.id)">
              <p>班级时间：{{ item.startdate }}~{{ item.enddate }}</p>
              <p>第{{ item.term }}期-第{{ item.batch }}批</p>
              <p>
                班级名称：{{ item.name }}<span style="margin-left:20px;">班级人数：{{ item.number }}</span>
              </p>
            </el-col>
          </span>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: lesson } = createNamespacedHelpers('lesson');
const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
const { mapActions: classes } = createNamespacedHelpers('classes');
export default {
  name: 'index',
  props: {},
  components: {
    NavBar,
  },
  data: function() {
    return {
      title: '',
      isleftarrow: '',
      navShow: true,
      display: true,
      // 计划列表
      planList: [],
      // 计划id
      planId: '',
      classList: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...lesson({ lessionInfo: 'fetch', lessionlist: 'query' }),
    ...trainplan(['query']),
    ...classes({ classQuery: 'query' }),
    async search() {
      const planList = await this.query();
      this.$set(this, `planList`, planList.data);
    },
    async toClass(planid) {
      // index:计划id
      this.display = false;
      this.$set(this, `planId`, planid);
      const classList = await this.classQuery({ planid: planid, headteacherid: this.user.userid });
      this.$set(this, `classList`, classList.data);
    },
    classBtn(index) {
      // index:班级id
      sessionStorage.setItem('classid', index);
      this.$router.push({ path: '/home/index', query: { id: index } });
    },
  },
  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;
    },
  },
};
</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;
}
.list {
  background: #fff;
  margin: 10px;
  width: 94%;
  padding: 10px;
  border-radius: 20px;
}
</style>
