|
@@ -1,106 +1,228 @@
|
|
|
<template>
|
|
|
- <div id="lesson">
|
|
|
- <detail-frame title="课程表" returns="/classes/index">
|
|
|
- <el-card v-loading="loading">
|
|
|
- <time-table v-if="!loading" :data="previews"></time-table>
|
|
|
- </el-card>
|
|
|
- </detail-frame>
|
|
|
+ <div id="lesson-table">
|
|
|
+ <el-card>
|
|
|
+ <template #header>
|
|
|
+ <el-row type="flex" align="middle" justify="space-between">
|
|
|
+ <el-col :span="4">课程安排</el-col>
|
|
|
+ </el-row>
|
|
|
+ </template>
|
|
|
+ <el-table :data="lessonList" border stripe>
|
|
|
+ <el-table-column align="center" label="时间" prop="time"></el-table-column>
|
|
|
+ <el-table-column align="center" v-for="(i, index) in dateList" :key="index" :label="i" :prop="`subname_day${index + 1}`">
|
|
|
+ <template v-slot="{ row, $index }">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24">{{ getProp(row, `subname_day${index + 1}`) }}</el-col>
|
|
|
+ <el-col
|
|
|
+ @click.native="searchTeacher(getProp(row, `teaid_day${index + 1}`))"
|
|
|
+ class="teaname"
|
|
|
+ :span="24"
|
|
|
+ v-if="getProp(row, `teaname_day${index + 1}`)"
|
|
|
+ >{{ getProp(row, `teaname_day${index + 1}`) }}</el-col
|
|
|
+ >
|
|
|
+ </el-row>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <el-dialog title="教师信息" :visible.sync="dialogVisible">
|
|
|
+ <teacherForm :teacherId="teacherId" style="height:1200px;"></teacherForm>
|
|
|
+ </el-dialog>
|
|
|
+ </el-card>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
|
|
|
-import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
-import axios from 'axios';
|
|
|
-import timeTable from '@frame/parts/time-table';
|
|
|
+var moment = require('moment');
|
|
|
import _ from 'lodash';
|
|
|
-const { mapActions: classes } = createNamespacedHelpers('classes'); //班级
|
|
|
-const { mapActions: lesson } = createNamespacedHelpers('lesson'); //课程
|
|
|
-const { mapActions: location } = createNamespacedHelpers('location'); //地点
|
|
|
-const { mapActions: subject } = createNamespacedHelpers('subject'); //科目
|
|
|
-const { mapActions: teacher } = createNamespacedHelpers('teacher'); //教师
|
|
|
-const { mapActions: director } = createNamespacedHelpers('director'); //班主任
|
|
|
+import teacherForm from '@frame/parts/teacher';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: lesson } = createNamespacedHelpers('lesson');
|
|
|
+const { mapActions: mapUtil } = createNamespacedHelpers('util');
|
|
|
+const { mapActions: subject } = createNamespacedHelpers('subject');
|
|
|
+const { mapActions: teacher } = createNamespacedHelpers('teacher');
|
|
|
+const { mapActions: school } = createNamespacedHelpers('school'); //给选老师组件使用.这个页面请求完就不销毁了
|
|
|
+
|
|
|
+// 本页的组合数据,变量用x表示: _id_day[x];subname_day[x];subid_day[x];teaid_day[x];teaname_day:[x]
|
|
|
export default {
|
|
|
- metaInfo: { title: '课程表' },
|
|
|
- name: 'lesson',
|
|
|
- props: {},
|
|
|
- components: { timeTable, detailFrame },
|
|
|
- data: () => ({
|
|
|
- classInfo: {},
|
|
|
- locationList: [],
|
|
|
- subjectList: [],
|
|
|
- previews: {},
|
|
|
- loading: true,
|
|
|
- }),
|
|
|
- async created() {
|
|
|
- await this.getOtherList();
|
|
|
- this.search();
|
|
|
+ name: 'lesson-table',
|
|
|
+ props: {
|
|
|
+ classInfo: { type: Object, default: () => {} },
|
|
|
},
|
|
|
- computed: {
|
|
|
- id() {
|
|
|
- return this.$route.query.id; //班级id
|
|
|
- },
|
|
|
+ components: { teacherForm },
|
|
|
+ data: function() {
|
|
|
+ var that = this;
|
|
|
+ return {
|
|
|
+ lessonInfo: {},
|
|
|
+ lessonList: [],
|
|
|
+ dateList: [],
|
|
|
+ timeList: [],
|
|
|
+ subjectList: [],
|
|
|
+ teacherList: [],
|
|
|
+ schoolList: [], //给选老师组件用
|
|
|
+ form: {},
|
|
|
+ dialogVisible: false,
|
|
|
+ teacherId: {},
|
|
|
+ dayType: [{ label: '活动' }, { label: '课程' }],
|
|
|
+ actList: [
|
|
|
+ { label: '--' },
|
|
|
+ { label: '报道+开班仪式' },
|
|
|
+ { label: '午餐+休息' },
|
|
|
+ { label: '晚餐' },
|
|
|
+ { label: '团队组建' },
|
|
|
+ { label: '拓展交流' },
|
|
|
+ { label: '课程作业小组展示' },
|
|
|
+ { label: '课程作业' },
|
|
|
+ { label: '礼仪课小组面试' },
|
|
|
+ { label: '结业仪式' },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getOtherList();
|
|
|
+ this.search();
|
|
|
},
|
|
|
methods: {
|
|
|
- ...classes(['fetch']),
|
|
|
- ...director({ getDirector: 'fetch' }),
|
|
|
- ...location({ getLocationList: 'query' }),
|
|
|
- ...subject({ getSubjectList: 'query' }),
|
|
|
- ...teacher({ getTeacher: 'fetch' }),
|
|
|
- ...lesson({ getLessonList: 'query' }),
|
|
|
+ ...mapUtil(['fetch']),
|
|
|
+ ...lesson(['query', 'create', 'update']),
|
|
|
+ ...subject({ getSubject: 'query' }),
|
|
|
+ ...teacher({ getTeacher: 'query' }),
|
|
|
+ ...school({ getSchool: 'query' }),
|
|
|
async search() {
|
|
|
- let res = {};
|
|
|
- let lesson = [];
|
|
|
- let start = '';
|
|
|
- let end = '';
|
|
|
- //班级信息,课程合并请求
|
|
|
- await axios.all([this.fetch(this.id), this.getLessonList({ class: this.id })]).then(
|
|
|
- axios.spread((r1, r2) => {
|
|
|
- if (this.$checkRes(r1)) res = r1;
|
|
|
- if (this.$checkRes(r2)) {
|
|
|
- if (r2.data.length > 0) {
|
|
|
- lesson = r2.data[0];
|
|
|
- start = _.get(_.head(lesson.lessons), 'date');
|
|
|
- end = _.get(_.last(lesson.lessons), 'date');
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- );
|
|
|
+ let res = await this.fetch({ model: 'lesson', classid: this.id });
|
|
|
if (this.$checkRes(res)) {
|
|
|
- let tcc = res.data;
|
|
|
- let numArr = tcc.name.match(/\d+/g);
|
|
|
- let term = numArr[0];
|
|
|
- let classes = numArr[2];
|
|
|
- let js = this.locationList.find(f => f.id === tcc.jslocationid);
|
|
|
- let kbys = this.locationList.find(f => f.id === tcc.kbyslocationid);
|
|
|
- let tzxl = this.locationList.find(f => f.id === tcc.kzjhlocationid);
|
|
|
- let yc = this.locationList.find(f => f.id === tcc.yclocationid);
|
|
|
- let lyTeacher = {};
|
|
|
- let headteacher = {};
|
|
|
- //礼仪老师,班主任合并请求
|
|
|
- if (tcc.lyteacherid && tcc.headteacherid)
|
|
|
- await axios.all([this.getTeacher(tcc.lyteacherid), this.getDirector(tcc.headteacherid)]).then(
|
|
|
- axios.spread((r1, r2) => {
|
|
|
- if (this.$checkRes(r1)) lyTeacher = r1.data;
|
|
|
- if (this.$checkRes(r2)) headteacher = r2.data;
|
|
|
- })
|
|
|
- );
|
|
|
- let object = { term, class: classes, lessons: lesson.lessons, start, end, headteacher, lyTeacher, js, kbys, tzxl, yc };
|
|
|
- this.$set(this, `previews`, object);
|
|
|
- this.$set(this, `loading`, false);
|
|
|
+ if (res.data.lessons.length <= 0) this.$message.warning('请先将本期的课程按模板进行初始化');
|
|
|
+ this.$set(this, `lessonInfo`, _.omit(res.data, ['lessons']));
|
|
|
+ let arr = _.get(res.data, `lessons`, []);
|
|
|
+ let x = this.getX(JSON.parse(JSON.stringify(arr)));
|
|
|
+ this.getY(JSON.parse(JSON.stringify(arr)));
|
|
|
+ this.$set(this, `dateList`, x);
|
|
|
+ arr = this.aData(arr);
|
|
|
+ this.$set(this, `lessonList`, arr);
|
|
|
}
|
|
|
},
|
|
|
- async getOtherList() {
|
|
|
- //地点,科目合并请求
|
|
|
- let res = await axios.all([this.getLocationList(), this.getSubjectList()]).then(
|
|
|
- axios.spread((r1, r2, r3) => {
|
|
|
- if (this.$checkRes(r1)) this.$set(this, `locationList`, r1.data);
|
|
|
- if (this.$checkRes(r2)) this.$set(this, `subjectList`, r2.data);
|
|
|
- })
|
|
|
+ //请求后整理数据方法
|
|
|
+ aData(data) {
|
|
|
+ let duplicate = JSON.parse(JSON.stringify(data));
|
|
|
+ //按时间分组
|
|
|
+ duplicate = _.flatten(_.toPairs(_.groupBy(data, 'time'))).filter(f => _.isArray(f));
|
|
|
+ let r = duplicate.map(i => {
|
|
|
+ //按日期排序
|
|
|
+ let aa = i.sort((a, b) => moment(a.date).format('X') - moment(b.date).format('X'));
|
|
|
+ //组合数据:{time,day1,id_day1,subid_day1}
|
|
|
+ let object = { time: _.get(i[0], 'time') };
|
|
|
+ aa.map(a => {
|
|
|
+ let index = this.dateList.findIndex(f => f == a.date);
|
|
|
+ if (index >= 0) {
|
|
|
+ index = index + 1;
|
|
|
+ }
|
|
|
+ let obj = this.resetData(a, index);
|
|
|
+ object = { ...object, ...obj };
|
|
|
+ });
|
|
|
+ return object;
|
|
|
+ });
|
|
|
+ r = this.getOrderForTime(r);
|
|
|
+ return r;
|
|
|
+ },
|
|
|
+ //获取指定数据
|
|
|
+ getOrderDate(data, index, needDate = false) {
|
|
|
+ let obj = { index: index };
|
|
|
+ if (_.get(data, `_id_day${index}`)) obj[`_id`] = _.get(data, `_id_day${index}`);
|
|
|
+ obj[`subname`] = _.get(data, `subname_day${index}`, `--`);
|
|
|
+ if (_.get(data, `subid_day${index}`)) obj[`subid`] = _.get(data, `subid_day${index}`);
|
|
|
+ if (_.get(data, `teaid_day${index}`)) obj[`teaid`] = _.get(data, `teaid_day${index}`);
|
|
|
+ if (_.get(data, `teaname_day${index}`)) obj[`teaname`] = _.get(data, `teaname_day${index}`);
|
|
|
+ if (needDate) {
|
|
|
+ //所有的数据都还原了,没必要遥index了
|
|
|
+ delete obj.index;
|
|
|
+ obj.date = this.dateList[index - 1];
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+ },
|
|
|
+ //整理,匹配数据是哪天,该显示在哪
|
|
|
+ resetData(data, index) {
|
|
|
+ let obj = {};
|
|
|
+ if (_.get(data, '_id')) obj[`_id_day${index}`] = _.get(data, '_id');
|
|
|
+ obj[`subname_day${index}`] = _.get(data, 'subname', '--');
|
|
|
+ if (_.get(data, 'subid')) obj[`subid_day${index}`] = _.get(data, 'subid');
|
|
|
+ if (_.get(data, 'teaid')) obj[`teaid_day${index}`] = _.get(data, 'teaid');
|
|
|
+ if (_.get(data, 'teaname')) obj[`teaname_day${index}`] = _.get(data, 'teaname');
|
|
|
+ return obj;
|
|
|
+ },
|
|
|
+ //根据时间排序
|
|
|
+ getOrderForTime(data) {
|
|
|
+ let duplicate = JSON.parse(JSON.stringify(data));
|
|
|
+ duplicate = duplicate.sort((a, b) => {
|
|
|
+ let a_arr = a.time.split('-');
|
|
|
+ let b_arr = b.time.split('-');
|
|
|
+ let at = moment(`${moment().format('YYYY-MM-DD')} ${a_arr[0]}`).format('X');
|
|
|
+ let bt = moment(`${moment().format('YYYY-MM-DD')} ${b_arr[0]}`).format('X');
|
|
|
+ return at - bt;
|
|
|
+ });
|
|
|
+ return duplicate;
|
|
|
+ },
|
|
|
+ //整理出标头,根据日期排序
|
|
|
+ getX(data) {
|
|
|
+ let r = _.uniqBy(data, 'date').map(i => i.date);
|
|
|
+ r = r.sort((a, b) => moment(a).format('X') - moment(b).format('X'));
|
|
|
+ return r;
|
|
|
+ },
|
|
|
+ //获得时间列表
|
|
|
+ getY(data) {
|
|
|
+ let duplicate = JSON.parse(JSON.stringify(data));
|
|
|
+ let arr = _.uniqBy(
|
|
|
+ duplicate.map(i => _.pick(i, ['time'])),
|
|
|
+ 'time'
|
|
|
);
|
|
|
+ arr = this.getOrderForTime(arr);
|
|
|
+ this.$set(
|
|
|
+ this,
|
|
|
+ `timeList`,
|
|
|
+ arr.map(i => i.time)
|
|
|
+ );
|
|
|
+ },
|
|
|
+ //教师列表,课程列表
|
|
|
+ async getOtherList() {
|
|
|
+ let res = await this.getSubject();
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `subjectList`, res.data);
|
|
|
+ res = await this.getTeacher({ status: '4' });
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `teacherList`, res.data);
|
|
|
+ },
|
|
|
+ //显示
|
|
|
+ getProp(data, prop) {
|
|
|
+ return _.get(data, prop);
|
|
|
},
|
|
|
+ async searchTeacher(id) {
|
|
|
+ this.dialogVisible = true;
|
|
|
+ this.teacherId = id;
|
|
|
+ console.log(id);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ pageTitle() {
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
+ },
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ classInfo: {
|
|
|
+ handler(val) {
|
|
|
+ let id = _.get(val, '_id');
|
|
|
+ if (id) this.search();
|
|
|
+ },
|
|
|
+ immediate: true,
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
-<style lang="less" scoped></style>
|
|
|
+<style lang="less" scoped>
|
|
|
+.teaname {
|
|
|
+ border-top: 1px dashed #cccccc;
|
|
|
+}
|
|
|
+</style>
|