index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. <span v-if="this.user.type === '1'">
  10. <headClassList :headClassList="headClassList" @clickStu="clickStu"></headClassList>
  11. </span>
  12. <span v-else>
  13. <classList
  14. :stuNameList="stuNameList"
  15. :groupList="groupList"
  16. @createGroup="createGroup"
  17. :createGroupDialog="createGroupDialog"
  18. :groupForm="groupForm"
  19. @saveGroup="saveGroup"
  20. @deleteGroup="deleteGroup"
  21. @exitGroup="exitGroup"
  22. @joinGroup="joinGroup"
  23. :stuIdAndGroupId="stuIdAndGroupId"
  24. :noGroupStudentNames="noGroupStudentNames"
  25. ></classList>
  26. <!-- :groupList="groupList"
  27. @saveGroup="saveGroup"
  28. @exitGroup="exitGroup"
  29. @deleteGroup="deleteGroup"
  30. @joinGroup="joinGroup"
  31. :stuIdAndGroupId="stuIdAndGroupId"
  32. :noGroupStudentNames="noGroupStudentNames" -->
  33. </span>
  34. </el-col>
  35. <el-col :span="24" class="foot">
  36. <footInfo></footInfo>
  37. </el-col>
  38. </el-col>
  39. </el-row>
  40. </div>
  41. </template>
  42. <script>
  43. import NavBar from '@/layout/common/topInfo.vue';
  44. import footInfo from '@/layout/common/footInfo.vue';
  45. import headClassList from '@/layout/class/headClassList.vue';
  46. import classList from '@/layout/class/classList.vue';
  47. import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
  48. const { mapActions: mapGroup } = createNamespacedHelpers('group');
  49. const { mapActions: mapStudent } = createNamespacedHelpers('student');
  50. const { mapActions: mapclasses } = createNamespacedHelpers('classes');
  51. export default {
  52. name: 'index',
  53. props: {},
  54. components: {
  55. NavBar, //头部导航
  56. headClassList, //班主任中管理的学生列表
  57. classList, //班级名单
  58. footInfo, //底部导航
  59. },
  60. data: () => ({
  61. // 班主任看班级名单
  62. headClassList: [],
  63. // 学生看学生名单
  64. stuNameList: [],
  65. // 班级分组
  66. groupList: [],
  67. createGroupDialog: false,
  68. groupForm: {},
  69. stuIdAndGroupId: {},
  70. noGroupStudentNames: [],
  71. title: '',
  72. isleftarrow: '',
  73. navShow: true,
  74. }),
  75. created() {
  76. this.searchInfo();
  77. this.searchstu();
  78. this.findGroup();
  79. },
  80. computed: {
  81. ...mapState(['user']),
  82. },
  83. mounted() {
  84. this.title = this.$route.meta.title;
  85. this.isleftarrow = this.$route.meta.isleftarrow;
  86. },
  87. watch: {
  88. $route(to, from) {
  89. this.title = to.meta.title;
  90. this.isleftarrow = to.meta.isleftarrow;
  91. },
  92. },
  93. methods: {
  94. ...mapclasses({ classList: 'query', classFetch: 'fetch' }),
  95. ...mapStudent({ stuQery: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
  96. ...mapGroup(['query', 'create', 'delete', 'insert', 'exit']),
  97. // 班主任查询管理班级列表
  98. async searchInfo() {
  99. const res = await this.classList(this.user.userid);
  100. if (this.$checkRes(res)) {
  101. this.$set(this, `headClassList`, res.data);
  102. }
  103. },
  104. // 班主任跳转到班级信息
  105. clickStu(id) {
  106. this.$router.push({ path: '/class/classStuList', query: { id: id } });
  107. },
  108. //学生
  109. async searchstu() {
  110. let classid = this.user.classid;
  111. const res = await this.stuQery({ classid });
  112. this.$set(this, `stuNameList`, res.data);
  113. },
  114. // 查询组
  115. async findGroup() {
  116. let stuid = this.user.userid;
  117. const result = await this.query();
  118. const groupList = result.data;
  119. this.$set(this, 'groupList', groupList);
  120. // 找出登陆者在哪个组
  121. // 找出组id
  122. let groupId = '';
  123. // 所有有组学生id
  124. let studentIds = [];
  125. var i = groupList.findIndex(value => {
  126. var v = value.students.findIndex(value => {
  127. studentIds.push(value.stuid);
  128. return stuid === value.stuid;
  129. });
  130. return v != -1;
  131. });
  132. if (i != -1) {
  133. groupId = groupList[i].id;
  134. }
  135. // 學生id+組id
  136. let stuIdAndGroupId = {};
  137. // 登陆者id
  138. stuIdAndGroupId.stuid = stuid;
  139. // 登陆者属于哪个组id
  140. stuIdAndGroupId.groupId = groupId;
  141. // 登陆者身份是否为班长
  142. // let job = this.user.job;
  143. // console.log(stuIdAndGroupId.job);
  144. // stuIdAndGroupId.job = job;
  145. this.$set(this, 'stuIdAndGroupId', stuIdAndGroupId);
  146. let studentList = this.stuNameList;
  147. // 没有组的学生名字
  148. let noGroupStudentNames = [];
  149. // 循环所有学生id
  150. for (let i = 0; i < studentList.length; i++) {
  151. // 循环有组学生id
  152. for (let j = 0; j < studentIds.length; j++) {
  153. if (studentList[i].id != studentIds[j]) {
  154. noGroupStudentNames.push(studentList[i].name);
  155. }
  156. }
  157. }
  158. // 未分组学生id(studentIds(有组学生id))(studentList所有学生)(noGroupStudentNames没有组的学生名字)
  159. this.$set(this, 'noGroupStudentNames', noGroupStudentNames);
  160. },
  161. // 创建分组-打開dialog
  162. createGroup() {
  163. this.createGroupDialog = true;
  164. },
  165. // 提交创建分组-班长职责
  166. async saveGroup({ data }) {
  167. const result = await this.create(data);
  168. if (result.errcode == 0) {
  169. this.createGroupDialog = false;
  170. this.findGroup();
  171. }
  172. },
  173. // 删除分组-班长职责
  174. async deleteGroup({ groupId }) {
  175. const result = await this.delete(groupId);
  176. if (result.errcode == 0) {
  177. this.findGroup();
  178. }
  179. },
  180. // 退出小组
  181. async exitGroup({ groupId }) {
  182. let data = {};
  183. data.groupid = groupId;
  184. data.stuid = this.user.userid;
  185. const result = await this.exit(data);
  186. if (result.errcode == 0) {
  187. this.findGroup();
  188. }
  189. },
  190. // 加入小组
  191. async joinGroup({ groupId }) {
  192. let data = {};
  193. data.groupid = groupId;
  194. data.stuid = this.user.userid;
  195. data.stuname = this.user.name;
  196. const result = await this.insert(data);
  197. if (result.errcode == 0) {
  198. this.findGroup();
  199. }
  200. },
  201. },
  202. };
  203. </script>
  204. <style lang="less" scoped>
  205. .style {
  206. width: 100%;
  207. min-height: 667px;
  208. position: relative;
  209. background-color: #f9fafc;
  210. }
  211. .top {
  212. height: 46px;
  213. overflow: hidden;
  214. }
  215. .main {
  216. min-height: 570px;
  217. }
  218. .foot {
  219. height: 50px;
  220. overflow: hidden;
  221. }
  222. </style>