<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <nav-bar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </nav-bar>
        </el-col>
        <el-col :span="24" class="main">
          <span v-if="this.user.type === '1'">
            <teaClass :classList="classList" @turnto="turnto" title="班级问卷进度"></teaClass>
          </span>
          <span v-else>
            <questionnaire-info :questionnaireList="questionnaireList"></questionnaire-info>
          </span>
        </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 teaClass from '@/layout/question/teaClass.vue';
import questionnaireInfo from '@question/src/views/index.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: termquest } = createNamespacedHelpers('termquest');
const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
const { mapActions: mapClass } = createNamespacedHelpers('classes');
const { mapActions: mapStudent } = createNamespacedHelpers('student');
export default {
  name: 'index',
  props: {},
  components: {
    NavBar, //头部导航
    footInfo, //底部导航
    questionnaireInfo, //问卷调查
    teaClass, //班主任班级名单
  },
  data: () => ({
    questionnaireList: [],
    classList: [],
    title: '',
    isleftarrow: '',
    navShow: true,
  }),
  created() {
    this.searchInfo();
    this.search();
  },
  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: {
    ...termquest(['query']),
    ...questionnaire({ getQuestList: 'query', getQuestMerge: 'mergeRequest' }),
    ...mapClass({ classinfo: 'query' }),
    ...mapStudent({ stuQuery: 'query', stuFetch: 'fetch' }),
    // 查询问卷调查列表
    async search() {
      let res = await this.query({ termid: this.user.termid });
      if (this.$checkRes(res)) {
        let ids = _.flattenDeep(res.data.map(i => i.questionnaireid));
        let quest = await this.getQuestMerge({ method: 'fetch', data: ids });
        this.$set(this, `questionnaireList`, quest);
      }
    },
    // 班主任查询管理班级列表
    async searchInfo({ ...info } = {}) {
      const res = await this.classinfo({ headteacherid: this.user.userid });
      this.$set(this, `classList`, res.data);
    },
    turnto(data) {
      this.$router.push({ path: '/question/teaProgress', query: { classid: data.id } });
    },
  },
};
</script>
<style lang="less" scoped>
.style {
  width: 100%;
  min-height: 667px;
  position: relative;
  background-color: #f9fafc;
}
.top {
  height: 46px;
  overflow: hidden;
  position: relative;
  z-index: 999;
}
.main {
  min-height: 570px;
  margin: 0 0 50px 0;
}
</style>
