achieve.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div id="achieve">
  3. <el-row>
  4. <el-col :span="24" class="style">
  5. <el-col :span="24" class="top">
  6. <!-- <topInfo></topInfo> -->
  7. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  8. </el-col>
  9. <el-col :span="24" class="main">
  10. <achieves
  11. @clickDialog="opensave"
  12. @submit="onsave"
  13. :peaceAchieveList="peaceAchieveList"
  14. :showPicker="showPicker"
  15. :peaceScore="peaceScore"
  16. @showBtn="showBtn"
  17. @onConfirm="onConfirm"
  18. :achieveList="achieveList"
  19. @submitss="onsist"
  20. :show="show"
  21. :form="form"
  22. :deptList="deptList"
  23. :lesson="lesson"
  24. :lesslist="lesslist"
  25. :names="names"
  26. :score="score"
  27. ></achieves>
  28. </el-col>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </template>
  33. <script>
  34. import NavBar from '@/layout/common/topInfo.vue';
  35. import achieves from '@/layout/class/achieve.vue';
  36. import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
  37. const { mapActions: mapStudent } = createNamespacedHelpers('student');
  38. const { mapActions: mapClass } = createNamespacedHelpers('classes');
  39. const { mapActions: mapLesson } = createNamespacedHelpers('lesson');
  40. const { mapActions: mapUploadtask } = createNamespacedHelpers('uploadtask');
  41. const { mapActions: mapSubject } = createNamespacedHelpers('subject');
  42. const { mapActions: group } = createNamespacedHelpers('group');
  43. export default {
  44. name: 'achieve',
  45. props: {},
  46. components: {
  47. NavBar, //头部导航
  48. achieves, //班级学生成绩列表
  49. },
  50. data: () => ({
  51. peaceAchieveList: [],
  52. showPicker: false,
  53. peaceScore: '',
  54. studid: '',
  55. lesson: [],
  56. lesslist: [],
  57. names: '',
  58. score: '',
  59. deptList: [],
  60. achieveList: [],
  61. show: false,
  62. form: {},
  63. title: '',
  64. isleftarrow: '',
  65. transitionName: 'fade',
  66. navShow: true,
  67. // 修改
  68. stuid: '',
  69. taskid: '',
  70. subname: '',
  71. task: [],
  72. groupsocre: '',
  73. }),
  74. created() {
  75. this.search();
  76. this.searchinfo();
  77. },
  78. computed: {
  79. ...mapState(['user']),
  80. classid() {
  81. return this.$route.query.classid;
  82. },
  83. },
  84. mounted() {
  85. this.title = this.$route.meta.title;
  86. this.isleftarrow = this.$route.meta.isleftarrow;
  87. },
  88. watch: {
  89. $route(to, from) {
  90. this.title = to.meta.title;
  91. this.isleftarrow = to.meta.isleftarrow;
  92. },
  93. },
  94. methods: {
  95. ...mapStudent({ list: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
  96. ...mapClass({ classinfo: 'fetch', classlist: 'query' }),
  97. ...mapLesson({ lessoninfo: 'fetch', lessonlist: 'query' }),
  98. ...mapUploadtask({ uploadtaskinfo: 'fetch', uploadtasklist: 'query', uploadtaskupdate: 'update' }),
  99. ...mapSubject({ subjectinfo: 'fetch', subjectlist: 'query' }),
  100. ...group({ groupinfo: 'query', groupfetch: 'fetch', findbystuid: 'findbystuid', groupupdate: 'update' }),
  101. // 平时成绩学生名单查询+作业成绩学生名单查询
  102. async search() {
  103. let classid;
  104. if (this.user.type === '1') classid = this.classid;
  105. else classid = this.user.classid;
  106. const res = await this.list({ classid });
  107. this.$set(this, `peaceAchieveList`, res.data);
  108. let classsid = this.user.classid;
  109. const result = await this.uploadtasklist({ classsid });
  110. for (const accc of res.data) {
  111. var arr = result.data.filter(item => item.studentid === accc.id);
  112. }
  113. // let lessons = [];
  114. let lessone = [];
  115. let stus = [];
  116. for (const val of result.data) {
  117. let newsid = val.lessonid;
  118. let classid = this.user.classid;
  119. //查询这个班的课程
  120. const lessonInfo = await this.lessonlist({ classid });
  121. for (const hic of lessonInfo.data) {
  122. //过滤出有作业的科目
  123. var fff = hic.lessons.filter(item => item.subid === newsid);
  124. for (const less of fff) {
  125. console.log(less.subname);
  126. this.$set(this, `subname`, less.subname);
  127. }
  128. }
  129. val.subName = this.subname;
  130. const stuInfo = await this.fet(val.studentid);
  131. if (stuInfo.data.name) {
  132. val.stuName = stuInfo.data.name;
  133. //创建学生名字相关数组
  134. let stu = [{ stuname: stuInfo.data.name, id: val.studentid, lesson: [] }];
  135. //合并数组
  136. stus = [...stu, ...stus];
  137. //去掉重复数组对象
  138. var appArray = _.uniqBy(stus, _.isEqual);
  139. //合并数组
  140. this.$set(this, `achieveList`, appArray);
  141. let lessonss = [{ name: this.subname, id: val.studentid, taskid: val.id, score: val.score }];
  142. lessone = [...lessonss, ...lessone];
  143. }
  144. for (const ss of appArray) {
  145. var vre = lessone.filter(item => item.id === ss.id);
  146. ss.lesson = vre;
  147. }
  148. // for (const eee of appArray) {
  149. // eee.less = lessone;
  150. // var qq = eee.less.filter(item => item.id === eee.id);
  151. // }
  152. }
  153. this.$set(this, `task`, appArray);
  154. },
  155. // 学委上作业分+存储学生id
  156. clickAchieve({ id }) {
  157. this.$set(this, `stuid`, id);
  158. this.show = true;
  159. },
  160. // 学委上作业分提交
  161. async submitAchieve(form) {
  162. this.form.id = this.stuid;
  163. let data = this.form;
  164. const res = await this.uploadtaskupdate(data);
  165. this.show = false;
  166. },
  167. // 平时成绩上分显示+学生id
  168. showBtn(id) {
  169. this.$set(this, `studid`, id);
  170. this.showPicker = true;
  171. },
  172. // 给学生上分
  173. async onConfirm(peaceScore) {
  174. let data = {};
  175. data.id = this.studid;
  176. const ress = await this.fet(this.studid);
  177. data.selfscore = Number(ress.data.selfscore) + Number(peaceScore);
  178. const res = await this.updates(data);
  179. this.$message({
  180. message: '平时成绩上分成功',
  181. type: 'success',
  182. });
  183. let classid = this.user.classid;
  184. const group = await this.findbystuid({ stuid: this.studid });
  185. for (const acc of group.data.students) {
  186. var ref = this.peaceAchieveList.filter(item => item.id === acc.stuid);
  187. for (const aaa of ref) {
  188. acc.stores = aaa.selfscore;
  189. }
  190. let asd = group.data.students.map(i => i.stores);
  191. console.log(asd);
  192. let nes = asd.filter(d => d);
  193. console.log(nes);
  194. let snewcore = eval(nes.join('+'));
  195. this.groupsocre = snewcore;
  196. }
  197. group.data.score = Number(data.selfscore) + Number(this.groupsocre);
  198. let groups = group.data;
  199. const groupup = await this.groupupdate(groups);
  200. this.search();
  201. this.showPicker = false;
  202. },
  203. // 作业成绩列表
  204. async searchinfo({ ...info } = {}) {
  205. // let classid = this.user.classid;
  206. // const result = await this.uploadtasklist({ classid });
  207. // const res = await this.list({ classid });
  208. // for (const accc of res.data) {
  209. // var arr = result.data.filter(item => item.studentid === accc.id);
  210. // }
  211. // // let lessons = [];
  212. // let lessone = [];
  213. // let stus = [];
  214. // for (const val of result.data) {
  215. // let newsid = val.lessonid;
  216. // let classid = this.user.classid;
  217. // //查询这个班的课程
  218. // const lessonInfo = await this.lessonlist({ classid });
  219. // for (const hic of lessonInfo.data) {
  220. // //过滤出有作业的科目
  221. // var fff = hic.lessons.filter(item => item._id === newsid);
  222. // for (const less of fff) {
  223. // this.$set(this, `subname`, less.subname);
  224. // }
  225. // }
  226. // val.subName = this.subname;
  227. // const stuInfo = await this.fet(val.studentid);
  228. // val.stuName = stuInfo.data.name;
  229. // //创建学生名字相关数组
  230. // let stu = [{ stuname: stuInfo.data.name, id: val.studentid }];
  231. // //合并数组
  232. // stus = [...stu, ...stus];
  233. // //去掉重复数组对象
  234. // var appArray = _.uniqWith(stus, _.isEqual);
  235. // //合并数组
  236. // this.$set(this, `achieveList`, appArray);
  237. // let lessonss = [{ name: this.subname, id: val.studentid, taskid: val.id, score: val.score, less: [] }];
  238. // lessone = [...lessonss, ...lessone];
  239. // var appArrayss = _.uniqWith(lessone, _.isEqual);
  240. // this.$set(this, `task`, lessone);
  241. // console.log(appArrayss);
  242. // }
  243. },
  244. //为了获取当前点击学生id和当前学生上传的作业
  245. async onsist({ id }) {
  246. var arr = this.task.filter(item => item.id === id);
  247. this.$set(this, `lesson`, arr);
  248. },
  249. async opensave({ id, name, score }) {
  250. this.show = true;
  251. this.$set(this, `names`, name);
  252. this.$set(this.form, `score`, score);
  253. this.$set(this, `taskid`, id);
  254. },
  255. async onsave(form) {
  256. this.form.id = this.taskid;
  257. let res = await this.uploadtaskupdate(this.form);
  258. this.show = false;
  259. },
  260. },
  261. };
  262. </script>
  263. <style lang="less" scoped>
  264. .style {
  265. width: 100%;
  266. min-height: 667px;
  267. position: relative;
  268. background-color: #eeeeee;
  269. }
  270. .top {
  271. height: 46px;
  272. overflow: hidden;
  273. }
  274. .main {
  275. min-height: 570px;
  276. }
  277. </style>