leagueData.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div id="leagueData">
  3. <el-row>
  4. <el-col :span="24">
  5. <el-table :data="list" border :span-method="objectSpanMethod">
  6. <el-table-column label="小组" prop="groupname" align="center"> </el-table-column>
  7. <el-table-column label="姓名" prop="stuname" align="center"> </el-table-column>
  8. <el-table-column v-for="(i, index) in lessonList" :key="index" :label="i.date" :prop="i._id" align="center">
  9. <el-table-column label="团队" align="center" prop="team">
  10. <template v-slot="{ row }">
  11. {{ getGroupscore(row, i.date) }}
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="个人" align="center">
  15. <template v-slot="{ row }">
  16. {{ getpscore(row, i.date, i.subid) }}
  17. </template>
  18. </el-table-column>
  19. <el-table-column label="作业" align="center">
  20. <template v-slot="{ row }">
  21. {{ getHomework(row, i._id) }}
  22. </template>
  23. </el-table-column>
  24. </el-table-column>
  25. <el-table-column label="总分" prop="totalScore" align="center">
  26. <template v-slot="{ row }">{{ calcTotal(row) }}</template>
  27. </el-table-column>
  28. </el-table>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </template>
  33. <script>
  34. import _ from 'lodash';
  35. import { mapState, createNamespacedHelpers } from 'vuex';
  36. export default {
  37. name: 'leagueData',
  38. props: {
  39. lessonList: { type: Array, default: () => [] },
  40. groupList: { type: Array, default: () => [] },
  41. list: { type: Array, default: () => [] },
  42. getPScore: { type: Array, default: () => [] },
  43. homeworkList: { type: Array, default: () => [] },
  44. groupscoreList: { type: Array, default: () => [] },
  45. },
  46. components: {},
  47. data: function() {
  48. return {};
  49. },
  50. created() {},
  51. computed: { ...mapState(['user', 'defaultOption']) },
  52. methods: {
  53. // 合并
  54. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  55. let prop = _.get(column, 'property');
  56. if (prop == 'groupname' || prop == 'team') {
  57. let data = _.flatten(_.toPairs(_.groupBy(this.list, 'groupid'))).filter(_.isArray);
  58. let num = data.find(i => i.every(e => e.groupid === row.groupid));
  59. let head = _.head(num);
  60. if (_.isEqual(head, row)) {
  61. return {
  62. rowspan: num.length,
  63. colspan: 1,
  64. };
  65. } else {
  66. return {
  67. rowspan: 0,
  68. colspan: 0,
  69. };
  70. }
  71. }
  72. },
  73. // 团队
  74. getGroupscore(data, date) {
  75. let res = this.groupscoreList.find(f => f.date == date && f.groupid == data.groupid);
  76. return _.get(res, 'score', '--');
  77. },
  78. // 平时
  79. getpscore(data, date, subid) {
  80. let res = this.getPScore.find(f => f.date == date && f.studentid == data.stuid && f.subid === subid);
  81. return _.get(res, 'score', '--');
  82. },
  83. // 作业
  84. getHomework(data, lessonid) {
  85. let res = this.homeworkList.find(f => f.lessonid == lessonid && f.studentid == data.stuid);
  86. return _.get(res, 'score', '--');
  87. },
  88. // 计算总分
  89. calcTotal(data) {
  90. // 个人
  91. let getPScore = this.getPScore.filter(f => f.studentid == data.stuid);
  92. let psSum = getPScore.reduce((p, n) => p + (n['score'] * 1 || 0), 0);
  93. // 作业
  94. let homework = this.homeworkList.filter(f => f.studentid == data.stuid);
  95. let hwSum = homework.reduce((p, n) => p + (n['score'] * 1 || 0), 0);
  96. // // 团队
  97. const groupscoreList = this.cleanSame(this.groupscoreList, 'groupid');
  98. let groupscore = groupscoreList.filter(f => f.groupid == data.groupid).reduce((p, n) => p + n['score'] * 1, 0);
  99. let groupLength = _.get(
  100. this.groupList.find(f => f.id == data.groupid),
  101. 'students.length',
  102. 0
  103. );
  104. let grSum = 0;
  105. if (groupLength > 0) grSum = groupscore / groupLength;
  106. // let grSum = groupscore.reduce((p, n) => p + ((n['score'] * 1) / groupLength.students.length || 0), 0);
  107. // if (this.getPScore.length > 0 && this.homeworkList.length > 0 && this.groupscoreList.length > 0 && data.stuname === '谷彦庆') {
  108. // console.group(data.stuname);
  109. // console.log(`个人:${psSum}`);
  110. // console.log(`作业:${hwSum}`);
  111. // let t = this.groupscoreList.filter(f => f.groupid == data.groupid);
  112. // console.log(t);
  113. // console.log(`团队:${grSum}`);
  114. // console.groupEnd(data.stuname);
  115. // }
  116. return _.round(hwSum + psSum + grSum, 2);
  117. },
  118. cleanSame(list, key) {
  119. console.log(list);
  120. return _.uniqBy(list, key);
  121. },
  122. },
  123. };
  124. </script>
  125. <style lang="less" scoped></style>