index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="style">
  5. <el-col :span="24" class="top">
  6. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  7. </el-col>
  8. <el-col :span="24" class="main">
  9. <el-tabs v-model="activeName" @tab-click="tabchange">
  10. <el-tab-pane label="班级名单" name="first">
  11. <el-col :span="24">
  12. <name-list :data="studentList" @updateStu="toUpdateStu"></name-list>
  13. </el-col>
  14. </el-tab-pane>
  15. <el-tab-pane label="班级分组" name="second">
  16. <classGroup
  17. :groupList="groupList"
  18. :stuIdAndGroupId="stuIdAndGroupId"
  19. :noGroupStu="noGroupStu"
  20. :groupForm="groupForm"
  21. @saveGroup="saveGroup"
  22. @joinGroup="joinGroup"
  23. @exitGroup="exitGroup"
  24. @affirm="affirm"
  25. @deleteGroup="deleteGroup"
  26. ></classGroup>
  27. </el-tab-pane>
  28. <el-tab-pane label="平时成绩" name="third">
  29. <daily :data="studentList" :scoreList="pscoreList" :classInfo="classInfo" :lesson="lesson" @save="dailyUpdate"></daily>
  30. </el-tab-pane>
  31. <el-tab-pane label="作业成绩" name="forth">
  32. <homework
  33. :homeworkList="homeworkList"
  34. :homeworkLessonList="homeworkLessonList"
  35. @onsist="onsist"
  36. :homeworkForm="homeworkForm"
  37. @homeworkBtn="homeworkBtn"
  38. @homeworkOnsubmit="homeworkOnsubmit"
  39. ></homework>
  40. </el-tab-pane>
  41. </el-tabs>
  42. </el-col>
  43. <el-col :span="24" class="foot">
  44. <footInfo></footInfo>
  45. </el-col>
  46. </el-col>
  47. </el-row>
  48. </div>
  49. </template>
  50. <script>
  51. import NavBar from '@/layout/common/topInfo.vue';
  52. import footInfo from '@/layout/common/footInfo.vue';
  53. // 班级分组
  54. import classGroup from './newClass/classGroup.vue';
  55. import nameList from './newClass/nameList.vue';
  56. import daily from './newClass/daily.vue';
  57. // 作业成绩
  58. import homework from './newClass/homework.vue';
  59. import { mapState, createNamespacedHelpers } from 'vuex';
  60. const { mapActions: group } = createNamespacedHelpers('group');
  61. const { mapActions: classes } = createNamespacedHelpers('classes');
  62. const { mapActions: util } = createNamespacedHelpers('util');
  63. const { mapActions: student } = createNamespacedHelpers('student');
  64. const { mapActions: pscore } = createNamespacedHelpers('personalscore');
  65. const { mapActions: uploadtask } = createNamespacedHelpers('uploadtask');
  66. export default {
  67. metaInfo: { title: '班级名单' },
  68. name: 'index',
  69. props: {},
  70. components: {
  71. NavBar, //头部导航
  72. footInfo, //底部导航
  73. // 班级分组
  74. classGroup,
  75. //班级名单
  76. nameList,
  77. // 日常分
  78. daily,
  79. // 作业成绩
  80. homework,
  81. },
  82. data: function() {
  83. return {
  84. title: '',
  85. isleftarrow: '',
  86. navShow: true,
  87. // 班级信息
  88. // 头部标签
  89. activeName: 'forth',
  90. // 小组列表
  91. groupList: [],
  92. // 登陆者所在组,id
  93. stuIdAndGroupId: {},
  94. // 未分组成员
  95. noGroupStu: [],
  96. // 创建小组form
  97. groupForm: {},
  98. //学生列表
  99. studentList: [],
  100. // 平时分列表
  101. pscoreList: [],
  102. // 作业成绩
  103. homeworkList: [],
  104. homeworkLessonList: [],
  105. homeworkForm: {},
  106. // 班级信息
  107. classInfo: {},
  108. // 课程信息
  109. lesson: [],
  110. };
  111. },
  112. async created() {
  113. await this.getClass();
  114. await this.toGetStudentList();
  115. // 查看班级小组
  116. await this.findGroup();
  117. // 查询学生作业成绩
  118. await this.searchHomework();
  119. },
  120. methods: {
  121. ...util({ modelFetch: 'fetch' }),
  122. ...classes({ getClassInfo: 'fetch' }),
  123. ...pscore({ getPScoreList: 'query', pscoreOpera: 'opera' }),
  124. ...group({ groupQuery: 'query', groupDelete: 'delete', groupCreate: 'create', groupUpdate: 'update', groupInsert: 'insert', groupExit: 'exit' }),
  125. ...student({ getStudentList: 'query', updateStudent: 'update' }),
  126. ...uploadtask({ uploadtasklist: 'query', uploadtaskUpdate: 'update' }),
  127. async getClass() {
  128. const res = await this.getClassInfo(this.user.classid);
  129. if (this.$checkRes(res)) this.$set(this, `classInfo`, res.data);
  130. const lres = await this.modelFetch({ model: 'lesson', classid: this.user.classid });
  131. if (this.$checkRes(lres)) {
  132. let { lessons } = lres.data;
  133. if (lessons) {
  134. lessons = _.uniqBy(
  135. lessons.filter(f => f.subid),
  136. 'subid'
  137. );
  138. console.log(lessons);
  139. this.$set(this, `lesson`, lessons);
  140. }
  141. }
  142. },
  143. // first 查学生
  144. async toGetStudentList() {
  145. const res = await this.getStudentList({ classid: this.user.classid });
  146. if (res) this.$set(this, `studentList`, res.data);
  147. },
  148. // first 修改学生职位
  149. async toUpdateStu(data) {
  150. const res = await this.updateStudent(data);
  151. if (this.$checkRes(res, '修改成功', res.errmsg || '修改失败')) this.toGetStudentList();
  152. },
  153. // second 查询小组
  154. async findGroup() {
  155. let stuid = this.user.userid;
  156. let classid = this.user.classid;
  157. const res = await this.groupQuery({ classid });
  158. if (res.errcode === 0) {
  159. this.$set(this, 'groupList', res.data);
  160. // 登陆者所在组
  161. // 组id
  162. let groupId = '';
  163. // 所有有组学生id
  164. let studentIds = [];
  165. var i = this.groupList.findIndex(value => {
  166. var v = value.students.findIndex(value => {
  167. studentIds.push(value.stuid);
  168. return stuid === value.stuid;
  169. });
  170. return v != -1;
  171. });
  172. if (i != -1) {
  173. groupId = this.groupList[i].id;
  174. }
  175. // 登录者id+組id
  176. let stuIdAndGroupId = {
  177. // 登陆者id
  178. stuid: stuid,
  179. // 登陆者属于哪个组id
  180. groupId: groupId,
  181. };
  182. this.$set(this, 'stuIdAndGroupId', stuIdAndGroupId);
  183. // 未分组成员
  184. var is = this.groupList.map(value => {
  185. var v = value.students.map(value => {
  186. studentIds.push(value.stuid);
  187. });
  188. return studentIds;
  189. });
  190. let havegroupstuid = is[0];
  191. var data = this.studentList.map(item => item.id);
  192. let stuidlist = _.xorWith(data, havegroupstuid, _.isEqual);
  193. let arr = [];
  194. let stus = [];
  195. for (const stuid of stuidlist) {
  196. arr = this.studentList.filter(item => item.id === stuid);
  197. stus = [...arr, ...stus];
  198. }
  199. this.$set(this, 'noGroupStu', stus);
  200. }
  201. },
  202. // second 创建小组
  203. async saveGroup({ data }) {
  204. data.termid = this.user.termid;
  205. data.batchid = this.user.batchid;
  206. data.classid = this.user.classid;
  207. const result = await this.groupCreate(data);
  208. if (result.errcode == 0) {
  209. this.findGroup();
  210. }
  211. },
  212. // second 确定小组
  213. async affirm() {
  214. for (const val of this.groupList) {
  215. val.status = '1';
  216. const res = await this.groupUpdate(val);
  217. }
  218. },
  219. // second 加入小组
  220. async joinGroup({ groupId }) {
  221. let data = {
  222. groupid: groupId,
  223. stuid: this.user.userid,
  224. stuname: this.user.name,
  225. };
  226. const result = await this.groupInsert(data);
  227. if (result.errcode == 0) {
  228. this.findGroup();
  229. }
  230. },
  231. //second 退出小组
  232. async exitGroup({ groupId }) {
  233. let data = {
  234. groupid: groupId,
  235. stuid: this.user.userid,
  236. };
  237. const result = await this.groupExit(data);
  238. if (result.errcode == 0) {
  239. this.findGroup();
  240. }
  241. },
  242. // second 删除小组
  243. async deleteGroup({ groupId }) {
  244. const result = await this.groupDelete(groupId);
  245. if (result.errcode == 0) {
  246. this.findGroup();
  247. }
  248. },
  249. //third 获取该班平时分
  250. async toGetPScoreList() {
  251. const res = await this.getPScoreList({ classid: this.user.classid });
  252. if (this.$checkRes(res)) this.$set(this, `pscoreList`, res.data);
  253. },
  254. // third 平时分保存(添加/修改)
  255. async dailyUpdate(data) {
  256. const res = await this.pscoreOpera(data);
  257. if (this.$checkRes(res, '修改成功', res.errmsg || '修改失败')) this.toGetPScoreList();
  258. },
  259. tabchange(tab) {
  260. const { name } = tab;
  261. if (name === 'third') this.toGetPScoreList();
  262. },
  263. // forth作业成绩
  264. async searchHomework() {
  265. if (this.user.job == '学委') {
  266. this.$set(this, `homeworkList`, this.studentList);
  267. } else {
  268. let classid = this.user.classid;
  269. const res = await this.uploadtasklist({ classid });
  270. for (const val of res.data) {
  271. var arr = this.studentList.filter(item => item.id === val.studentid);
  272. this.$set(this, `homeworkList`, arr);
  273. }
  274. }
  275. },
  276. // 当前学生上传科目成绩
  277. async onsist({ id }) {
  278. const res = await this.uploadtasklist({ studentid: id });
  279. if (res.errcode === 0) {
  280. this.$set(this, `homeworkLessonList`, res.data);
  281. }
  282. },
  283. // 打开上成绩
  284. homeworkBtn({ data }) {
  285. console.log(data);
  286. this.$set(this, `homeworkForm`, data);
  287. },
  288. // 提交上成绩
  289. async homeworkOnsubmit({ data }) {
  290. let res = await this.uploadtaskUpdate(data);
  291. this.searchHomework();
  292. },
  293. },
  294. computed: {
  295. ...mapState(['user']),
  296. },
  297. mounted() {
  298. this.title = this.$route.meta.title;
  299. this.isleftarrow = this.$route.meta.isleftarrow;
  300. },
  301. watch: {
  302. $route(to, from) {
  303. this.title = to.meta.title;
  304. this.isleftarrow = to.meta.isleftarrow;
  305. },
  306. },
  307. };
  308. </script>
  309. <style lang="less" scoped>
  310. .style {
  311. width: 100%;
  312. min-height: 667px;
  313. position: relative;
  314. background-color: #f9fafc;
  315. }
  316. .top {
  317. height: 46px;
  318. overflow: hidden;
  319. }
  320. .main {
  321. min-height: 570px;
  322. }
  323. /deep/.el-tabs__header {
  324. margin: 0;
  325. }
  326. /deep/.el-tabs__nav {
  327. width: 100%;
  328. }
  329. /deep/.el-tabs__item {
  330. padding: 0;
  331. width: 25%;
  332. text-align: center;
  333. }
  334. .foot {
  335. height: 90px;
  336. overflow: hidden;
  337. }
  338. </style>