123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <div id="index">
- <el-row>
- <el-col :span="24" class="style">
- <el-col :span="24" class="top">
- <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
- </el-col>
- <el-col :span="24" class="main">
- <span v-if="this.user.type === '1'">
- <headClassList :headClassList="headClassList" @clickStu="clickStu"></headClassList>
- </span>
- <span v-else>
- <classList
- :stuNameList="stuNameList"
- :groupList="groupList"
- @createGroup="createGroup"
- :createGroupDialog="createGroupDialog"
- :groupForm="groupForm"
- @saveGroup="saveGroup"
- @deleteGroup="deleteGroup"
- @exitGroup="exitGroup"
- @joinGroup="joinGroup"
- :stuIdAndGroupId="stuIdAndGroupId"
- :noGroupStudentNames="noGroupStudentNames"
- ></classList>
- <!-- :groupList="groupList"
- @saveGroup="saveGroup"
- @exitGroup="exitGroup"
- @deleteGroup="deleteGroup"
- @joinGroup="joinGroup"
- :stuIdAndGroupId="stuIdAndGroupId"
- :noGroupStudentNames="noGroupStudentNames" -->
- </span>
- </el-col>
- <el-col :span="24" class="foot">
- <footInfo></footInfo>
- </el-col>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import NavBar from '@/layout/common/topInfo.vue';
- import footInfo from '@/layout/common/footInfo.vue';
- import headClassList from '@/layout/class/headClassList.vue';
- import classList from '@/layout/class/classList.vue';
- import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
- const { mapActions: mapGroup } = createNamespacedHelpers('group');
- const { mapActions: mapStudent } = createNamespacedHelpers('student');
- const { mapActions: mapclasses } = createNamespacedHelpers('classes');
- export default {
- name: 'index',
- props: {},
- components: {
- NavBar, //头部导航
- headClassList, //班主任中管理的学生列表
- classList, //班级名单
- footInfo, //底部导航
- },
- data: () => ({
- // 班主任看班级名单
- headClassList: [],
- // 学生看学生名单
- stuNameList: [],
- // 班级分组
- groupList: [],
- createGroupDialog: false,
- groupForm: {},
- stuIdAndGroupId: {},
- noGroupStudentNames: [],
- title: '',
- isleftarrow: '',
- navShow: true,
- }),
- created() {
- this.searchInfo();
- this.searchstu();
- this.findGroup();
- },
- computed: {
- ...mapState(['user']),
- },
- mounted() {
- this.title = this.$route.meta.title;
- this.isleftarrow = this.$route.meta.isleftarrow;
- },
- watch: {
- $route(to, from) {
- this.title = to.meta.title;
- this.isleftarrow = to.meta.isleftarrow;
- },
- },
- methods: {
- ...mapclasses({ classList: 'query', classFetch: 'fetch' }),
- ...mapStudent({ stuQery: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
- ...mapGroup(['query', 'create', 'delete', 'insert', 'exit']),
- // 班主任查询管理班级列表
- async searchInfo() {
- const res = await this.classList(this.user.userid);
- if (this.$checkRes(res)) {
- this.$set(this, `headClassList`, res.data);
- }
- },
- // 班主任跳转到班级信息
- clickStu(id) {
- this.$router.push({ path: '/class/classStuList', query: { id: id } });
- },
- //学生
- async searchstu() {
- let classid = this.user.classid;
- const res = await this.stuQery({ classid });
- this.$set(this, `stuNameList`, res.data);
- },
- // 查询组
- async findGroup() {
- let stuid = this.user.userid;
- const result = await this.query();
- const groupList = result.data;
- this.$set(this, 'groupList', groupList);
- // 找出登陆者在哪个组
- // 找出组id
- let groupId = '';
- // 所有有组学生id
- let studentIds = [];
- var i = groupList.findIndex(value => {
- var v = value.students.findIndex(value => {
- studentIds.push(value.stuid);
- return stuid === value.stuid;
- });
- return v != -1;
- });
- if (i != -1) {
- groupId = groupList[i].id;
- }
- // 學生id+組id
- let stuIdAndGroupId = {};
- // 登陆者id
- stuIdAndGroupId.stuid = stuid;
- // 登陆者属于哪个组id
- stuIdAndGroupId.groupId = groupId;
- // 登陆者身份是否为班长
- // let job = this.user.job;
- // console.log(stuIdAndGroupId.job);
- // stuIdAndGroupId.job = job;
- this.$set(this, 'stuIdAndGroupId', stuIdAndGroupId);
- let studentList = this.stuNameList;
- // 没有组的学生名字
- let noGroupStudentNames = [];
- // 循环所有学生id
- for (let i = 0; i < studentList.length; i++) {
- // 循环有组学生id
- for (let j = 0; j < studentIds.length; j++) {
- if (studentList[i].id != studentIds[j]) {
- noGroupStudentNames.push(studentList[i].name);
- }
- }
- }
- // 未分组学生id(studentIds(有组学生id))(studentList所有学生)(noGroupStudentNames没有组的学生名字)
- this.$set(this, 'noGroupStudentNames', noGroupStudentNames);
- },
- // 创建分组-打開dialog
- createGroup() {
- this.createGroupDialog = true;
- },
- // 提交创建分组-班长职责
- async saveGroup({ data }) {
- const result = await this.create(data);
- if (result.errcode == 0) {
- this.createGroupDialog = false;
- this.findGroup();
- }
- },
- // 删除分组-班长职责
- async deleteGroup({ groupId }) {
- const result = await this.delete(groupId);
- if (result.errcode == 0) {
- this.findGroup();
- }
- },
- // 退出小组
- async exitGroup({ groupId }) {
- let data = {};
- data.groupid = groupId;
- data.stuid = this.user.userid;
- const result = await this.exit(data);
- if (result.errcode == 0) {
- this.findGroup();
- }
- },
- // 加入小组
- async joinGroup({ groupId }) {
- let data = {};
- data.groupid = groupId;
- data.stuid = this.user.userid;
- data.stuname = this.user.name;
- const result = await this.insert(data);
- if (result.errcode == 0) {
- this.findGroup();
- }
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .style {
- width: 100%;
- min-height: 667px;
- position: relative;
- background-color: #f9fafc;
- }
- .top {
- height: 46px;
- overflow: hidden;
- }
- .main {
- min-height: 570px;
- }
- .foot {
- height: 50px;
- overflow: hidden;
- }
- </style>
|