index.vue 8.1 KB

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