lrf402788946 пре 5 година
родитељ
комит
84202c7c70
3 измењених фајлова са 242 додато и 6 уклоњено
  1. 7 1
      src/router/index.js
  2. 46 5
      src/views/student/index.vue
  3. 189 0
      src/views/train-plan/bedroom.vue

+ 7 - 1
src/router/index.js

@@ -275,9 +275,15 @@ const train = [
   {
     path: '/train/plan/classes',
     name: 'train_plan_classes',
-    meta: { title: '班级管理' },
+    meta: { title: '学生分班' },
     component: () => import('@/views/train-plan/classes.vue'),
   },
+  {
+    path: '/train/plan/bedroom',
+    name: 'train_plan_bedroom',
+    meta: { title: '寝室管理' },
+    component: () => import('@/views/train-plan/bedroom.vue'),
+  },
   {
     path: '/train/plan/quest',
     name: 'train_plan_quest',

+ 46 - 5
src/views/student/index.vue

@@ -21,13 +21,23 @@
           <el-button type="primary" @click="search">查询</el-button>
         </el-form-item>
       </el-form>
-      <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete"></data-table>
+      <data-table :fields="fields" :data="list" :opera="opera" @turnClass="toTurnClass" @edit="toEdit" @delete="toDelete"></data-table>
     </list-frame>
+    <el-dialog :visible.sync="dialog" title="转班" @close="toClose" width="30%">
+      <data-form :data="studInfo" :fields="turnFields" :rules="{}" @save="turnSave">
+        <template #options="{item,form}">
+          <template v-if="item.model == 'classid'">
+            <el-option v-for="(i, index) in selectClassList" :key="index" :label="`第${i.batch}批-${i.name}`" :value="i._id"></el-option>
+          </template>
+        </template>
+      </data-form>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import listFrame from '@frame/layout/admin/list-frame';
+import dataForm from '@frame/components/form';
 import dataTable from '@frame/components/data-table';
 import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions } = createNamespacedHelpers('student');
@@ -41,14 +51,21 @@ export default {
   components: {
     listFrame,
     dataTable,
+    dataForm,
   },
   data: () => ({
+    dialog: false,
     opera: [
       {
         label: '编辑',
         icon: 'el-icon-edit',
         method: 'edit',
       },
+      {
+        label: '转班',
+        icon: 'el-icon-refresh',
+        method: 'turnClass',
+      },
       {
         label: '删除',
         icon: 'el-icon-delete',
@@ -70,13 +87,19 @@ export default {
       { label: '手机号', prop: 'phone' },
       { label: '邮箱', prop: 'email' },
     ],
+    turnFields: [
+      { label: '姓名', model: 'name', type: 'text' },
+      { label: '学校', model: 'school_name', type: 'text' },
+      { label: '班级', model: 'classid', type: 'select' },
+    ],
     form: {},
-    searchInfo: {},
+    studInfo: {},
     list: [],
     classList: [],
     batchList: [],
     termList: [],
     total: 0,
+    selectClassList: [],
   }),
   created() {
     this.getPlan();
@@ -84,11 +107,9 @@ export default {
   computed: { ...mapState(['user', 'defaultOption']) },
   methods: {
     ...trainplan({ planfetch: 'fetch' }),
-    ...mapActions(['query', 'delete']),
+    ...mapActions(['query', 'delete', 'update']),
     ...classes({ classesquery: 'query' }),
     async search({ skip = 0, limit = 10, ...info } = {}) {
-      //let data;
-      // this.searchInfo.termid && this.searchInfo.termid !== '' ? (data = { termid: this.searchInfo.termid }) : '';
       const res = await this.query({ skip, limit, termid: this.form.termid, classid: this.form.classid });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);
@@ -123,6 +144,26 @@ export default {
       const res = await this.classesquery({ batchid });
       this.$set(this, `classList`, res.data);
     },
+    async toTurnClass({ data }) {
+      let { termid } = data;
+      this.$set(this, `studInfo`, data);
+      let res = await this.classesquery({ termid });
+      if (this.$checkRes(res)) this.$set(this, `selectClassList`, res.data);
+      this.dialog = true;
+    },
+    //转班保存
+    async turnSave({ data }) {
+      let msg = '转班';
+      let res = await this.update(data);
+      if (this.$checkRes(res, `${msg}成功`, res.errmsg || `${msg}失败`)) {
+        this.search();
+        this.toClose();
+      }
+    },
+    toClose() {
+      this.dialog = false;
+      this.form = {};
+    },
   },
   watch: {
     defaultOption: {

+ 189 - 0
src/views/train-plan/bedroom.vue

@@ -0,0 +1,189 @@
+<template>
+  <div id="bedroom">
+    <detail-frame :title="pageTitle" v-show="view == 'list'">
+      <el-alert type="warning" title="请确认好学生已经报道后再进行分寝" center :closable="false" class="btn_bar"></el-alert>
+      <el-row type="flex" align="middle" justify="end" class="btn_bar">
+        <el-col :span="2">
+          <el-button type="primary" size="mini" @click="toApart">一键分寝</el-button>
+        </el-col>
+      </el-row>
+      <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" :usePage="false"></data-table>
+    </detail-frame>
+    <detail-frame :title="classInfo.name" :returns="toReturns" v-if="view != 'list'">
+      <el-table :data="stuBedroom" size="mini" border stripe>
+        <el-table-column align="center" label="寝室号" prop="bedroom"></el-table-column>
+        <el-table-column align="center" label="学生">
+          <template v-slot="{ row }">
+            <el-row>
+              <el-col v-for="(i, index) in row.list" :key="index" :span="6">
+                <el-link @click="turnBedroom(i)">{{ i.name }}</el-link>
+              </el-col>
+            </el-row>
+          </template>
+        </el-table-column>
+      </el-table>
+    </detail-frame>
+    <el-dialog :visible.sync="dialog" title="修改寝室" @close="toClose" width="30%">
+      <data-form :data="form" :fields="turnBedRoomFields" :rules="{}" @save="turnSave">
+        <template #options="{item,form}">
+          <template v-if="item.model == 'bedroom'">
+            <template v-for="(i, index) in bedroomList">
+              <el-option :key="index" :label="`${i.code}`" :value="i.code"></el-option>
+            </template>
+          </template>
+        </template>
+      </data-form>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import _ from 'lodash';
+import axios from 'axios';
+import dataForm from '@frame/components/form';
+import dataTable from '@frame/components/filter-page-table';
+import detailFrame from '@frame/layout/admin/detail-frame';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: classes } = createNamespacedHelpers('classes');
+const { mapActions: student } = createNamespacedHelpers('student');
+const { mapActions: bedroom } = createNamespacedHelpers('bedroom');
+export default {
+  name: 'bedroom',
+  props: {},
+  components: { detailFrame, dataTable, dataForm },
+  data: function() {
+    return {
+      view: 'list',
+      dialog: false,
+      form: {},
+      list: [],
+      stuBedroom: [],
+      bedroomList: [],
+      classInfo: {},
+      opera: [
+        {
+          label: '查看寝室',
+          icon: 'el-icon-view',
+          method: 'edit',
+        },
+      ],
+      fields: [
+        { label: '期', prop: 'term' },
+        { label: '批', prop: 'batch' },
+        { label: '班级', prop: 'name' },
+      ],
+      turnBedRoomFields: [
+        { label: '姓名', model: 'name', type: 'text' },
+        { label: '学校', model: 'school_name', type: 'text' },
+        { label: '寝室', model: 'bedroom', type: 'select' },
+      ],
+      options: undefined,
+    };
+  },
+  created() {},
+  methods: {
+    ...classes(['query']),
+    ...student({ getStudentList: 'query', updateStudent: 'update' }),
+    ...bedroom({ bedroomApart: 'apart', getBedroomList: 'query' }),
+    async search() {
+      let termid = _.get(this.defaultOption, 'termid');
+      if (!termid) return;
+      let res = await this.query({ termid });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+      }
+    },
+    toEdit({ data }) {
+      this.$set(this, `classInfo`, data);
+      this.view = 'class';
+      this.getSL();
+    },
+    async getSL() {
+      let res = await this.getStudentList({ classid: this.classInfo._id });
+      if (this.$checkRes(res)) {
+        let duplicate = _.cloneDeep(res.data);
+        let mid = _.groupBy(duplicate, 'bedroom');
+        let keys = Object.keys(mid);
+        let arr = [];
+        for (const key of keys) {
+          let o = {};
+          o['bedroom'] = !key || key == 'undefined' ? '未分寝' : key;
+          o['list'] = mid[key];
+          arr.push(o);
+        }
+        this.$set(this, `stuBedroom`, arr);
+      }
+    },
+    async toApart() {
+      let { planid: trainplanid, termid } = this.options;
+      let batchList = _.uniq(this.list.map(i => i.batchid));
+      let axiosArr = [];
+      batchList.map(batchid => {
+        axiosArr.push(this.bedroomApart({ trainplanid, termid, batchid }));
+      });
+      axios.all(axiosArr).then(
+        axios.spread((...res) => {
+          let r = res.every(e => e && e.errcode == '0');
+          this.$message({
+            type: r ? 'success' : 'error',
+            message: r ? '分寝成功' : '分寝失败',
+          });
+        })
+      );
+    },
+    toReturns() {
+      this.view = 'list';
+      this.$set(this, `classInfo`, {});
+      this.$set(this, `stuBedroom`, []);
+    },
+    async turnBedroom(data) {
+      this.$set(this, `form`, data);
+      let res = await this.getBedroomList({ status: '0', batch: this.classInfo.batch });
+      if (this.$checkRes(res)) this.$set(this, `bedroomList`, res.data);
+      this.dialog = true;
+    },
+    //转寝保存
+    async turnSave({ data }) {
+      let res = await this.updateStudent(data);
+      if (this.$checkRes(res, `转寝成功`, res.errmsg || `转寝失败`)) {
+        this.getSL();
+        this.toClose();
+      }
+    },
+    toClose() {
+      this.dialog = false;
+      this.form = {};
+    },
+  },
+  watch: {
+    defaultOption: {
+      immediate: true,
+      deep: true,
+      handler(val) {
+        if (!_.get(this, 'options')) {
+          this.$set(this, `options`, _.cloneDeep(val));
+          this.search();
+        } else {
+          let ntermid = _.get(val, 'termid');
+          let otermid = _.get(this.options, 'termid');
+          if (ntermid && !_.isEqual(ntermid, otermid)) {
+            this.$set(this, `options`, _.cloneDeep(val));
+            this.search();
+          }
+        }
+      },
+    },
+  },
+  computed: {
+    ...mapState(['user', 'defaultOption']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped></style>