<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>
            <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 {
  metaInfo: { title: '问卷调查' },
  name: 'index',
  props: {},
  components: {
    NavBar, //头部导航
    footInfo, //底部导航
    questionnaireInfo, //问卷调查
    // teaClass, //班主任班级名单
  },
  data: () => ({
    questionnaireList: [],
    classList: [],
    title: '',
    isleftarrow: '',
    navShow: true,
  }),
  created() {
    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.getQuestList({ type: 0 });
      let termid = this.user.termid;
      let ress = await this.query({ termid });
      let ids = _.flattenDeep(ress.data.map(i => i.questionnaireid));
      console.log(ids);
      let quest = await this.getQuestMerge({ method: 'fetch', data: ids });
      console.log(quest);
      let news = [];
      news = [...res.data, ...quest];
      console.log(news);
      this.$set(this, `questionnaireList`, news);
    },

    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>
