guhongwei 4 tahun lalu
induk
melakukan
f058993da8
2 mengubah file dengan 197 tambahan dan 13 penghapusan
  1. 2 0
      src/store/index.js
  2. 195 13
      src/views/user/league.vue

+ 2 - 0
src/store/index.js

@@ -31,6 +31,7 @@ import answerchat from '@frame/store/answerchat';
 import classtype from '@frame/store/classtype';
 import personalscore from '@frame/store/personalscore';
 import liveroom from '@frame/store/liveroom';
+import groupscore from '@frame/store/groupscore';
 import * as ustate from '@frame/store/user/state';
 import * as umutations from '@frame/store/user/mutations';
 Vue.use(Vuex);
@@ -72,5 +73,6 @@ export default new Vuex.Store({
     personalscore,
     classtype,
     liveroom,
+    groupscore,
   },
 });

+ 195 - 13
src/views/user/league.vue

@@ -1,34 +1,216 @@
 <template>
   <div id="league">
     <el-row>
-      <el-col :span="24">
-        <p>积分榜</p>
+      <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="list" v-for="(item, index) in leagueList" :key="index">
+            <el-collapse accordion>
+              <el-collapse-item>
+                <template slot="title">
+                  <el-col :span="8" class="titleOne"> 组名:{{ item.groupname }} </el-col>
+                  <el-col :span="8" class="titleTwo"> 姓名:{{ item.stuname }} </el-col>
+                  <el-col :span="8" class="titleThree"> 总分:{{ calcTotal(item) }}分 </el-col>
+                </template>
+                <el-col :span="24" class="lessonList" v-for="(tag, index) in item.lessonList" :key="index">
+                  <el-col :span="24" class="subname"> 课程:{{ tag.subname }} </el-col>
+                  <el-col :span="24" class="info">
+                    <el-col :span="8" class="one">团队:{{ getGroupscore(item.groupid, tag.subid) || '暂无' }} </el-col>
+                    <el-col :span="8" class="one">个人:{{ getpscore(item.stuid, tag._id) || '暂无' }} </el-col>
+                    <el-col :span="8" class="one">作业: {{ gethomework(item.stuid, tag._id) || '暂无' }} </el-col>
+                  </el-col>
+                </el-col>
+              </el-collapse-item>
+            </el-collapse>
+          </el-col>
+        </el-col>
       </el-col>
     </el-row>
   </div>
 </template>
 
 <script>
+import NavBar from '@/layout/common/topTitle.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: group } = createNamespacedHelpers('group');
+const { mapActions: lesson } = createNamespacedHelpers('lesson');
+const { mapActions: uploadtask } = createNamespacedHelpers('uploadtask');
+const { mapActions: pscore } = createNamespacedHelpers('personalscore');
+const { mapActions: groupscore } = createNamespacedHelpers('groupscore');
+const { mapActions: util } = createNamespacedHelpers('util');
+
 export default {
   name: 'league',
   props: {},
-  components: {},
+  components: {
+    NavBar,
+  },
   data: function() {
-    return {};
+    return {
+      title: '',
+      isleftarrow: '',
+      transitionName: 'fade',
+      navShow: true,
+      // 积分榜
+      leagueList: [],
+      // 课程列表
+      lessonList: [],
+      // 平时分
+      getPScore: [],
+      // 作业分
+      homeworkList: [],
+      // 团队分
+      groupscoreList: [],
+      // 团队列表
+      groupList: [],
+    };
+  },
+  created() {
+    this.searchOther();
+    this.search();
   },
-  created() {},
-  methods: {},
-  computed: {
-    ...mapState(['user']),
-    pageTitle() {
-      return `${this.$route.meta.title}`;
+  methods: {
+    ...group({ groupQuery: 'query', groupFetch: 'fetch' }),
+    ...groupscore({ groupscoreQuery: 'query', groupscoreFetch: 'fetch' }),
+    ...uploadtask({ uploadtaskQuery: 'query' }),
+    ...pscore({ getPScoreList: 'query', pscoreOpera: 'opera' }),
+    ...util({ modelFetch: 'fetch' }),
+    // 查询班级信息 课表,团队分,个人分,作业分
+    async searchOther() {
+      let classid = this.user.classid;
+      // 课表
+      let res = await this.modelFetch({ model: 'lesson', classid });
+      let r = res.data.lessons.filter(f => f.subid);
+      r = r.map(r => {
+        let time = r.time.split('-');
+        r.start = `${r.date} ${time[0]}`;
+        return r;
+      });
+      r = Object.values(_.groupBy(r, 'subid'));
+      r = r.map(a => {
+        let na = _.orderBy(a, ['start'], ['asc']);
+        return _.head(na);
+      });
+      this.$set(this, `lessonList`, r);
+      res = await this.groupQuery({ classid });
+      this.$set(this, `groupList`, res.data);
+      // 团队分
+      res = await this.groupscoreQuery({ classid });
+      this.$set(this, `groupscoreList`, res.data);
+      // 个人分
+      res = await this.getPScoreList({ classid: classid });
+      this.$set(this, `getPScore`, res.data);
+      // 作业分
+      res = await this.uploadtaskQuery({ classid });
+      this.$set(this, `homeworkList`, res.data);
+    },
+    // 查询班级组
+    async search() {
+      let classid = this.user.classid;
+      // 组列表
+      let groupQuery = await this.groupQuery({ classid });
+      // 组分放入数组中去
+      for (const val of groupQuery.data) {
+        for (const student of val.students) {
+          student.groupname = val.name;
+          student.groupid = val.id;
+        }
+      }
+      let arr = groupQuery.data.map(item => item.students);
+      arr = _.flattenDeep(arr);
+      for (const group of arr) {
+        console.log(group);
+        group.lessonList = this.lessonList;
+      }
+      this.$set(this, `leagueList`, arr);
+    },
+    // 团队
+    getGroupscore(groupid, prop) {
+      let res = this.groupscoreList.find(f => f.subid == prop && f.groupid == groupid);
+      if (res) return res.score;
+    },
+    // 平时
+    getpscore(stuid, prop) {
+      let lesson = this.lessonList.find(f => f._id == prop);
+      let res = this.getPScore.find(f => f.date == lesson.date && f.studentid == stuid);
+      if (res) return res.score;
+    },
+    // 作业
+    gethomework(stuid, prop) {
+      let res = this.homeworkList.find(f => f.lessonid == prop && f.studentid == stuid);
+      if (res) return res.score;
+    },
+    // 计算总分
+    calcTotal(data) {
+      // 个人
+      let getPScore = this.getPScore.filter(f => f.studentid == data.stuid);
+      let psSum = getPScore.reduce((p, n) => p + (n['score'] * 1 || 0), 0);
+      // 作业
+      let homework = this.homeworkList.filter(f => f.studentid == data.stuid);
+      let hwSum = homework.reduce((p, n) => p + (n['score'] * 1 || 0), 0);
+      // // 团队
+      let groupscore = this.groupscoreList.filter(f => f.groupid == data.groupid);
+      let groupLength = this.groupList.find(f => f.id == data.groupid);
+      let grSum = groupscore.reduce((p, n) => p + ((n['score'] * 1) / groupLength.students.length || 0), 0);
+      return hwSum + psSum + grSum;
     },
   },
-  metaInfo() {
-    return { title: this.$route.meta.title };
+  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>
+<style lang="less" scoped>
+.style {
+  width: 100%;
+  min-height: 667px;
+  position: relative;
+  background-color: #f9fafc;
+}
+.top {
+  height: 46px;
+  overflow: hidden;
+}
+.main {
+  min-height: 620px;
+  padding: 5px;
+  .titleOne {
+    text-align: center;
+    font-size: 16px;
+  }
+  .titleTwo {
+    text-align: center;
+    font-size: 16px;
+  }
+  .titleThree {
+    text-align: center;
+    font-size: 16px;
+  }
+  .lessonList {
+    .subname {
+      text-align: center;
+      font-size: 16px;
+      color: #2c69fe;
+      font-weight: bold;
+      padding: 5px 0;
+    }
+    .info {
+      .one {
+        text-align: center;
+        border: 1px dashed #cccccc5f;
+      }
+    }
+  }
+}
+</style>