Quellcode durchsuchen

分组完成,还差底部显示未分组学生

nihao vor 5 Jahren
Ursprung
Commit
6fca72174b

+ 80 - 0
src/layout/class/classGroup.vue

@@ -0,0 +1,80 @@
+<template>
+  <div id="classGroup">
+    <el-row>
+      <el-col :span="24" class="button_class">
+        <van-button v-if="stuIdAndGroupId.type === '班长'" round type="info" icon="smile" @click="dialogFormVisible = true">创建小组</van-button>
+      </el-col>
+      <el-col :span="24">
+        <groupList :groupList="groupList" v-on="$listeners" :stuIdAndGroupId="stuIdAndGroupId"></groupList>
+      </el-col>
+      <el-col :span="24" class="foot">
+        <noGroup></noGroup>
+      </el-col>
+    </el-row>
+    <el-dialog class="createGroup" title="创建小组" :visible.sync="dialogFormVisible" width="100%">
+      <el-form :model="form">
+        <el-form-item label="名称" prop="name" :label-width="formLabelWidth" :rules="[{ required: true, message: '小组名称不能为空' }]">
+          <el-input v-model="form.name" autocomplete="off"></el-input>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button
+          type="primary"
+          @click="
+            saveGroup();
+            dialogFormVisible = false;
+          "
+          >提 交</el-button
+        >
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import groupList from '@/layout/class/groupList.vue';
+import noGroup from '@/layout/class/noGroup.vue';
+export default {
+  name: 'classGroup',
+  props: {
+    groupList: null,
+    stuIdAndGroupId: null, //登陆者id和小组id
+  },
+  components: {
+    groupList,
+    noGroup,
+  },
+  data: () => ({
+    dialogTableVisible: false,
+    dialogFormVisible: false,
+    form: {
+      name: '',
+    },
+    formLabelWidth: '80px',
+  }),
+  created() {},
+  computed: {},
+  methods: {
+    saveGroup() {
+      this.$emit('saveGroup', { data: this.form });
+      dialogFormVisible: false;
+    },
+    // createGroup() {
+    //   this.$emit('createGroup');
+    // },
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.button_class {
+  padding: 0 100px;
+  line-height: 100px;
+}
+button {
+  width: 100%;
+}
+.createGroup {
+  width: 100%;
+}
+</style>

+ 6 - 1
src/layout/class/classList.vue

@@ -12,7 +12,7 @@
             </span>
           </van-tab>
           <van-tab title="班级分组">
-            班级分组,需要有创建分组按钮,显示小组名称,小组人数,加入小组。(未分组学生显示)
+            <classGroup :groupList="groupList" v-on="$listeners" :stuIdAndGroupId="stuIdAndGroupId"></classGroup>
           </van-tab>
         </van-tabs>
       </el-col>
@@ -23,6 +23,7 @@
 <script>
 import headNameList from '@/layout/class/nameList/headNameList.vue';
 import stuNameList from '@/layout/class/nameList/stuNameList.vue';
+import classGroup from '@/layout/class/classGroup.vue';
 export default {
   name: 'classList',
   props: {
@@ -30,6 +31,8 @@ export default {
     assignShow: null, //指派职务弹窗
     assignForm: null, //指派职务form表单
     stuNameList: null, //学生看班级学生名单
+    groupList: null,
+    stuIdAndGroupId: null, //登陆者id和小组id
   },
   components: {
     // 显示班级学生名称(带有职务)
@@ -37,10 +40,12 @@ export default {
     // 学委:给学生上分(平时成绩只有一个,课程作业成绩,都要显示)
     headNameList, //班主任班级学生名单
     stuNameList, //学生班级学生名单
+    classGroup, //班级分组
   },
   data: () => ({
     active: 0,
     role: '4',
+    // groupList: [],
   }),
   created() {},
   computed: {},

+ 76 - 9
src/layout/class/groupList.vue

@@ -2,31 +2,91 @@
   <div id="groupList">
     <el-row>
       <el-col :span="24" class="list" v-for="(item, index) in groupList" :key="index">
-        <el-col :span="20" class="name"> 组名:{{ item.name }} </el-col>
-        <el-col :span="4" class="name">
-          <el-button type="success" size="mini" @click="$router.push({ path: '/class/joinGroup', query: { id: item.id } })">加入</el-button>
-          <!-- <el-button type="success" size="mini" @click="deteles(item.id)">删除</el-button> -->
-        </el-col>
+        <el-collapse accordion>
+          <el-collapse-item>
+            <template slot="title">
+              <el-col :span="2" class="groupName">{{ index + 1 }}.</el-col>
+              <el-col :span="5" class="groupName"> {{ item.name }} </el-col>
+              <el-col :span="4" class="groupName">
+                <el-button v-if="item.students.length >= 10" round plain type="danger" size="mini" disabled>已满员</el-button>
+              </el-col>
+              <el-col :span="1" class="groupName"></el-col>
+              <el-col :span="4" class="groupName">
+                <el-button v-if="stuIdAndGroupId.type === '班长' && item.students.length === 0" round type="danger" size="mini" @click="deleteGroup(item.id)"
+                  >删除</el-button
+                >
+              </el-col>
+              <el-col :span="1" class="groupName"></el-col>
+              <el-col :span="4" class="groupName">
+                <el-button v-if="stuIdAndGroupId.groupId === '' && item.students.length <= 10" round type="success" size="mini" @click="joinGroup(item.id)">加入</el-button>
+                <el-button v-if="stuIdAndGroupId.groupId === item.id" round type="danger" size="mini" @click="exitGroup(item.id)">退出</el-button>
+              </el-col>
+            </template>
+            <el-col :span="24" class="list" v-for="(itemStrudent, indexStudent) in item.students" :key="indexStudent">
+              <el-col :span="6" class="childName">{{ itemStrudent.stuname }}</el-col>
+            </el-col>
+          </el-collapse-item>
+        </el-collapse>
       </el-col>
     </el-row>
   </div>
 </template>
 
 <script>
+import Vue from 'vue';
+import { Dialog } from 'vant';
+// 全局注册
+Vue.use(Dialog);
 export default {
   name: 'groupList',
   props: {
     groupList: null,
+    stuIdAndGroupId: null,
   },
   components: {},
   data: () => ({}),
   created() {},
   computed: {},
   methods: {
+    // 进组
+    joinGroup(groupId) {
+      Dialog.confirm({
+        title: '进组',
+        message: '确认要加入此组?',
+      })
+        .then(() => {
+          this.$emit('joinGroup', { groupId });
+        })
+        .catch(() => {
+          // on cancel
+        });
+    },
+    // 退出组
+    exitGroup(groupId) {
+      Dialog.confirm({
+        title: '退组',
+        message: '确认要退出此组?',
+      })
+        .then(() => {
+          this.$emit('exitGroup', { groupId });
+        })
+        .catch(() => {
+          // on cancel
+        });
+    },
     // 删除组
-    // deteles(id) {
-    //   this.$emit('shanchu', id);
-    // },
+    deleteGroup(groupId) {
+      Dialog.confirm({
+        title: '删除',
+        message: '确认删除此组?',
+      })
+        .then(() => {
+          this.$emit('deleteGroup', { groupId });
+        })
+        .catch(() => {
+          // on cancel
+        });
+    },
   },
 };
 </script>
@@ -43,8 +103,15 @@ p {
   padding: 0 10px;
   border-radius: 15px;
 }
-.list .name {
+.list .groupName {
   padding: 15px 0;
   font-size: 18px;
 }
+.childName {
+  padding: 15px 0;
+  font-size: 15px;
+}
+button {
+  width: 120%;
+}
 </style>

+ 32 - 0
src/layout/class/noGroup.vue

@@ -0,0 +1,32 @@
+<template>
+  <div id="noGroup">
+    <el-row>
+      <el-col :span="24">未分组学生</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+      <el-col :span="6">顾宏伟</el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'noGroup',
+  props: {
+    noGroupList: null,
+  },
+  components: {},
+  data: () => ({}),
+  created() {},
+  computed: {},
+  methods: {},
+};
+</script>
+
+<style lang="less" scoped></style>

+ 3 - 3
src/store/group.js

@@ -11,8 +11,8 @@ const state = () => ({});
 const mutations = {};
 
 const actions = {
-  async query({ commit }, { skip = 0, limit, ...info } = {}) {
-    const res = await this.$axios.$get(`${api.groupInfo}`, { skip, limit, ...info });
+  async query({ commit }, { skip = 0, limit, termid, batchid, classid, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.groupInfo}`, { skip, limit, ...info, termid, batchid, classid });
     return res;
   },
   async create({ commit }, payload) {
@@ -36,7 +36,7 @@ const actions = {
     return res;
   },
   async exit({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.groupInfo}/exit`, payload);
+    const res = await this.$axios.$post(`${api.groupInfo}/exit`, payload);
     return res;
   },
 };

+ 88 - 3
src/views/class/index.vue

@@ -14,6 +14,12 @@
             @outForm="outAssignShow"
             @onForm="onAssignShow"
             :stuNameList="stuNameList"
+            :groupList="groupList"
+            @saveGroup="saveGroup"
+            @exitGroup="exitGroup"
+            @deleteGroup="deleteGroup"
+            @joinGroup="joinGroup"
+            :stuIdAndGroupId="stuIdAndGroupId"
           ></classList>
         </el-col>
         <el-col :span="24" class="foot">
@@ -28,7 +34,14 @@
 import topInfo from '@/layout/common/topInfo.vue';
 import footInfo from '@/layout/common/footInfo.vue';
 import classList from '@/layout/class/classList.vue';
-
+import { createNamespacedHelpers, mapGetters } from 'vuex';
+const { mapActions: mapQuestion } = createNamespacedHelpers('group');
+let site = JSON.parse(sessionStorage.getItem('site'));
+const termid = site.termid;
+const batchid = site.batchid;
+const classid = site.classid;
+const stuid = site.id;
+const type = '班长';
 export default {
   name: 'index',
   props: {},
@@ -78,20 +91,92 @@ export default {
         job: '班长',
       },
     ],
+    groupList: [],
+    stuIdAndGroupId: '',
   }),
-  created() {},
+  created() {
+    this.findList();
+  },
   computed: {},
   methods: {
     clickAssign() {
       this.assignShow = true;
     },
     onAssignShow(assignForm) {
-      console.log(assignForm);
       this.assignShow = false;
     },
     outAssignShow() {
       this.assignShow = false;
     },
+    ...mapQuestion(['query', 'create', 'delete', 'insert', 'exit']),
+    // 查询小组列表
+    async findList() {
+      let data = {};
+      data.termid = termid;
+      data.batchid = batchid;
+      data.classid = classid;
+      const result = await this.query(data);
+      const groupList = result.data;
+      this.$set(this, 'groupList', groupList);
+      // 找出登陆者在哪个组
+      // 找出组id
+      let groupId = '';
+      var i = groupList.findIndex(value => {
+        var v = value.students.findIndex(value => {
+          return stuid === value.stuid;
+        });
+        return v != -1;
+      });
+      if (i != -1) {
+        groupId = groupList[i].id;
+      }
+      let stuIdAndGroupId = {};
+      // 登陆者id
+      stuIdAndGroupId.stuid = stuid;
+      // 登陆者属于哪个组id
+      stuIdAndGroupId.groupId = groupId;
+      // 登陆者身份是否为班长
+      stuIdAndGroupId.type = type;
+      this.$set(this, 'stuIdAndGroupId', stuIdAndGroupId);
+    },
+    // 创建小组
+    async saveGroup({ data }) {
+      data.termid = termid;
+      data.batchid = batchid;
+      data.classid = classid;
+      const result = await this.create(data);
+      if (result.errcode == 0) {
+        this.findList();
+      }
+    },
+    // 加入小组
+    async joinGroup({ groupId }) {
+      let data = {};
+      data.groupid = groupId;
+      data.stuid = stuid;
+      data.stuname = site.name;
+      const result = await this.insert(data);
+      if (result.errcode == 0) {
+        this.findList();
+      }
+    },
+    // 退出小组
+    async exitGroup({ groupId }) {
+      let data = {};
+      data.groupid = groupId;
+      data.stuid = stuid;
+      const result = await this.exit(data);
+      if (result.errcode == 0) {
+        this.findList();
+      }
+    },
+    // 删除小组
+    async deleteGroup({ groupId }) {
+      const result = await this.delete(groupId);
+      if (result.errcode == 0) {
+        this.findList();
+      }
+    },
   },
 };
 </script>