<template>
  <div id="leave">
    <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">
          <el-col :span="24" class="leaveBtn" v-if="this.user.job == '班长'">
            <van-button round type="info" icon="smile" @click="onClickRight()">添加分数</van-button>
          </el-col>
          <el-col :span="24" class="leaveList">
            <pingfenList :groupList="groupList" :leaveList="leaveList" :stuList="groupList" @clickShow="clickShow"></pingfenList>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topTitle.vue';
import pingfenList from '@/layout/user/pingfenList.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapStudent } = createNamespacedHelpers('student');
const { mapActions: group } = createNamespacedHelpers('group');
const { mapActions: mapclass } = createNamespacedHelpers('classes');

export default {
  metaInfo: { title: '评分列表' },
  name: 'leave',
  props: {},
  components: {
    NavBar, //头部导航
    pingfenList, //请假列表
  },
  data: () => ({
    groupList: [],
    leaveList: [],
    stuList: [],
    title: '',
    isleftarrow: '',
    transitionName: 'fade',
    navShow: true,
  }),
  created() {
    this.searchInfo();
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  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: {
    ...mapStudent(['fetch', 'query']),
    ...group({ groupinfo: 'query', groupfetch: 'fetch' }),
    ...mapclass({ mapclass: 'query', classfetch: 'fetch' }),
    async searchInfo() {
      let classid = this.id;
      const acc = await this.query({ classid });
      console.log(res);
      var res = acc.data.filter(item => item.classid === classid);
      let selfscore = res.map(i => i.selfscore);
      let nes = selfscore.filter(d => d);
      console.log(nes);
      let num = eval(nes.join('+'));
      console.log(num);
      this.leaveList.num = num;
      this.$set(this, `leaveList`, this.leaveList);
      const resq = await this.groupinfo({ classid });
      for (const val of resq.data) {
        for (const acc of val.students) {
          var ref = res.filter(item => item.id === acc.stuid);
          for (const aaa of ref) {
            acc.stores = aaa.selfscore;
          }
          let asd = val.students.map(i => i.stores);
          let nes = asd.filter(d => d);
          let snewcore = eval(nes.join('+'));
          val.score = snewcore;
        }
      }
      this.$set(this, `groupList`, resq.data);
    },
    async clickShow(acc) {},
    // 跳转到请假
    onClickRight() {
      this.$router.push({ path: '/user/socre', query: { classid: this.id } });
    },
  },
};
</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;
}
</style>
