|
@@ -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>
|