<template>
  <div id="homework">
    <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">
          <el-col :span="24" class="leaveBtn"> </el-col>
          <el-col :span="24" class="leaveList">
            <workList :workLists="workLists" :display="display"></workList>
          </el-col>
          <el-col :span="24" class="foot">
            <footInfo></footInfo>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import footInfo from '@/layout/common/footInfo.vue';
import workList from '@/layout/user/workList.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapClass } = createNamespacedHelpers('classes');
const { mapActions: mapLesson } = createNamespacedHelpers('lesson');
const { mapActions: mapTask } = createNamespacedHelpers('task');
const { mapActions: mapSubject } = createNamespacedHelpers('subject');

export default {
  name: 'homework',
  props: {},
  components: {
    NavBar, //头部导航
    workList,
    footInfo,
  },
  data: () => ({
    workLists: [],
    display: '',
    navShow: true,
    title: '',
    isleftarrow: '',
  }),
  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;
    },
  },
  created() {
    this.search();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...mapTask({ list: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
    ...mapClass({ classinfo: 'fetch', classquery: 'query' }),
    ...mapLesson({ lessonList: 'query', lessonadd: 'create', lessonfet: 'fetch', lessonupdates: 'update' }),

    ...mapSubject({ subjectList: 'query', subjectListadd: 'create', subjectListfet: 'fetch', subjectListpdates: 'update' }),

    async search() {
      let classid = this.user.classid;
      const ress = await this.classinfo(classid);
      console.log(ress.data.lessonid);
      let lessonid = ress.data.lessonid;
      const res = await this.subjectList({ lessonid });
      console.log(res);

      const resout = await this.list();
      for (const val of resout.data) {
        // console.log(result.data.lessons);
        // var crr = result.data.lessons.filter(item => item.subid);
        this.$set(this, `workLists`, res.data);
        var arr = res.data.filter(item => item.name === val.name);
        console.log(arr);
        for (const att of arr) {
          att.display = 'second';
        }
      }
    },
  },
};
</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;
}
.main .leaveBtn {
  text-align: center;
  padding: 15px 0;
}
.leaveList {
  position: relative;
  background-color: #f9fafc;
}
</style>
