123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <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-if="this.user.type === '3'">
- <teacherClassList :newclassList="newclassList"></teacherClassList>
- </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"
- :classid="this.user.classid"
- @onSubmit="onSubmit"
- @openClick="openClick"
- @opanSubmit="opanSubmit"
- :form="form"
- :show="show"
- :columns="columns"
- @onvalue="onvalue"
- @queren="queren"
- ></classList>
- </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 teacherClassList from '@/layout/class/teacherClassList.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');
- const { mapActions: mapSethead } = createNamespacedHelpers('sethead');
- export default {
- metaInfo: { title: '班级名单' },
- name: 'index',
- props: {},
- components: {
- NavBar, //头部导航
- headClassList, //班主任中管理的学生列表
- classList, //班级名单
- footInfo, //底部导航
- teacherClassList, //教师班级列表
- },
- data: () => ({
- form: {},
- columns: [],
- show: false,
- // 班主任看班级名单
- headClassList: [],
- // 学生看学生名单
- stuNameList: [],
- // 班级分组
- newclassList: [],
- groupList: [],
- createGroupDialog: false,
- groupForm: {},
- stuIdAndGroupId: {},
- noGroupStudentNames: [],
- title: '',
- isleftarrow: '',
- navShow: true,
- }),
- async created() {
- await this.searchInfo();
- await this.searchstu();
- await this.findGroup();
- this.class();
- },
- 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', 'update']),
- ...mapSethead({ Setheadupdates: 'update' }),
- // 班主任查询管理班级列表
- async searchInfo() {
- const res = await this.classList({ headteacherid: 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 });
- console.log(res.data);
- 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;
- });
- console.log(studentIds);
- 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);
- console.log(stuIdAndGroupId);
- let studentList = this.stuNameList;
- // 没有组的学生名字
- let noGroupStudentNames = [];
- // 循环所有学生id
- for (let i = 0; i < studentList.length; i++) {
- if (studentIds.length === 0) {
- noGroupStudentNames.push(studentList[i].name);
- } else {
- // 循环有组学生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();
- }
- },
- async openClick() {},
- async onSubmit({ data }) {
- console.log(data);
- let res = await this.Setheadupdates(data);
- console.log(res);
- this.show = false;
- },
- opanSubmit(item) {
- this.form.groupid = item.id;
- console.log(item);
- this.$set(this, 'columns', item.students);
- if (this.user.job === '班长') {
- if (item.status != '1') {
- this.show = true;
- }
- }
- },
- onvalue(value) {
- this.form.stuid = value.value.stuid;
- },
- async queren(item) {
- item.status = '1';
- console.log(item);
- const res = await this.create(item);
- },
- //教师查看班级列表
- async class() {
- const res = await this.classList();
- console.log(res.data);
- this.$set(this, 'newclassList', res.data);
- },
- },
- };
- </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: 90px;
- overflow: hidden;
- }
- </style>
|