|
@@ -1,37 +1,288 @@
|
|
|
<template>
|
|
|
<div id="term-lesson">
|
|
|
- <detail-frame :title="pageTitle" returns="/train/plan/lesson"></detail-frame>
|
|
|
+ <detail-frame :title="pageTitle" returns="/train/plan/lesson">
|
|
|
+ <el-row type="flex">
|
|
|
+ <el-col :span="8" v-if="t1.length > 0">
|
|
|
+ <lesson-table :data="t1" batch="1"></lesson-table>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="8">
|
|
|
+ <lesson-table :data="t2" batch="2"></lesson-table>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="8">
|
|
|
+ <lesson-table :data="t3" batch="3"></lesson-table>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </detail-frame>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import _ from 'lodash';
|
|
|
+import axios from 'axios';
|
|
|
+const moment = require('moment');
|
|
|
+moment.locale('zh-cn');
|
|
|
+import lessonTable from './parts/term-lesson-table';
|
|
|
import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
const { mapActions: lesson } = createNamespacedHelpers('lesson');
|
|
|
const { mapActions: classes } = createNamespacedHelpers('classes');
|
|
|
+
|
|
|
+const { mapActions: location } = createNamespacedHelpers('location'); //地点
|
|
|
+const { mapActions: teacher } = createNamespacedHelpers('teacher'); //教师
|
|
|
+const { mapActions: dept } = createNamespacedHelpers('dept'); //配合教师表使用的部门表
|
|
|
+const { mapActions: dirPlan } = createNamespacedHelpers('dirPlan'); //班主任不能上课的列表
|
|
|
+const { mapActions: teaplan } = createNamespacedHelpers('teaPlan');
|
|
|
+const { mapActions: mapDept } = createNamespacedHelpers('dept');
|
|
|
+const { mapActions: director } = createNamespacedHelpers('director');
|
|
|
export default {
|
|
|
name: 'term-lesson',
|
|
|
props: {},
|
|
|
- components: { detailFrame },
|
|
|
+ components: { detailFrame, lessonTable },
|
|
|
data: function() {
|
|
|
return {
|
|
|
options: {},
|
|
|
- lessonList: [],
|
|
|
+ list: [],
|
|
|
+ t1: [],
|
|
|
+ t2: [],
|
|
|
+ t3: [],
|
|
|
classList: [],
|
|
|
+
|
|
|
+ locationList: [],
|
|
|
+ lyTeacherList: [],
|
|
|
+ deptList: [],
|
|
|
+ headTeacherList: [],
|
|
|
};
|
|
|
},
|
|
|
- created() {},
|
|
|
+ created() {
|
|
|
+ this.getSettingLists();
|
|
|
+ },
|
|
|
methods: {
|
|
|
...lesson({ getLesson: 'query' }),
|
|
|
...classes({ getClass: 'query' }),
|
|
|
+
|
|
|
+ ...director({ getDirector: 'fetch' }),
|
|
|
+ ...location({ getLocationList: 'query' }),
|
|
|
+ ...teacher({ getTeacherList: 'query', getTeacher: 'fetch' }),
|
|
|
+ ...dirPlan({ dirQuery: 'getDirTeacher' }),
|
|
|
+ ...mapDept({ getDept: 'query' }),
|
|
|
+ ...teaplan(['findTeacher']),
|
|
|
async search() {
|
|
|
let termid = _.get(this.defaultOption, `termid`);
|
|
|
if (!termid) return;
|
|
|
+ let lessonList = [];
|
|
|
+ let classList = [];
|
|
|
let lessons = await this.getLesson({ termid });
|
|
|
- if (this.$checkRes(lessons)) this.$set(this, `lessonList`, lessons.data);
|
|
|
+ if (this.$checkRes(lessons)) lessonList = lessons.data;
|
|
|
let classes = await this.getClass({ termid });
|
|
|
- if (this.$checkRes(classes)) this.$set(this, `classList`, classes.data);
|
|
|
+ if (this.$checkRes(classes)) {
|
|
|
+ classList = classes.data;
|
|
|
+ for (let cla of classList) {
|
|
|
+ cla = await this.searchClassPerson(cla);
|
|
|
+ }
|
|
|
+ this.$set(this, `classList`, classList);
|
|
|
+ }
|
|
|
+ let arr = classList.map(i => {
|
|
|
+ let r = lessonList.find(f => f.classid == i._id);
|
|
|
+ if (r) {
|
|
|
+ let { lessons = [] } = r;
|
|
|
+ i.lessons = lessons;
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ arr = _.flatten(
|
|
|
+ _.toPairs(
|
|
|
+ _.groupBy(
|
|
|
+ arr.sort((a, b) => a - b),
|
|
|
+ `batch`
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ).filter(f => _.isArray(f));
|
|
|
+ arr.map((i, index) => {
|
|
|
+ // 先转换lessons,此表的情况是:小批次下的班级都是一样的课程,只有教师,教室不一样
|
|
|
+ let a = this.changeLesson(i);
|
|
|
+ let ht = this.setTeacher(a, 'headteacher');
|
|
|
+ let lyt = this.setTeacher(a, 'lyteacher');
|
|
|
+ let js = this.setTeacher(a, 'jslocation');
|
|
|
+ for (let ind = 0; ind < index; ind++) {
|
|
|
+ a.unshift({});
|
|
|
+ // console.log(`ind`);
|
|
|
+ // console.log(ind);
|
|
|
+ // console.log(`index`);
|
|
|
+ // console.log(index);
|
|
|
+ // const element = array[index];
|
|
|
+ }
|
|
|
+ //找到该班额班主任和礼仪课教师
|
|
|
+ a.push(ht);
|
|
|
+ a.push(lyt);
|
|
|
+ a.push(js);
|
|
|
+ for (let ind = 2; ind >= index; ind--) {
|
|
|
+ a.push({});
|
|
|
+ }
|
|
|
+ this.$set(this, `t${index + 1}`, a);
|
|
|
+ });
|
|
|
+ // this.$set(this, `list`, arr);
|
|
|
+ // this.getX();
|
|
|
+ },
|
|
|
+ //课程数据=>页面数据形式
|
|
|
+ changeLesson(array) {
|
|
|
+ //{batch,subname(同一批每天课程一样),subid, classid_1,classid_2, teaid_1, teaid_2, lessonid_1,lessonid_2 }
|
|
|
+ //i(map循环)中获取的参数: batch;classid_*;
|
|
|
+ //lesson中获取的参数: subname;subid_*;teaid_*;lessonid_*
|
|
|
+ let duplicate = _.cloneDeep(array);
|
|
|
+ //按日期排序
|
|
|
+ let res = duplicate.map((i, index) => {
|
|
|
+ let les = _.flatten(
|
|
|
+ _.toPairs(
|
|
|
+ _.groupBy(
|
|
|
+ i.lessons.sort((a, b) => moment(a.date).format('X') - moment(b.date).format('X')),
|
|
|
+ 'date'
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ).filter(f => _.isArray(f));
|
|
|
+ // console.log(i);
|
|
|
+ // console.log(les);
|
|
|
+ //每天按时间排序
|
|
|
+ les = les.map(lesi => _.orderBy(lesi, 'time', 'asc'));
|
|
|
+ let t = les.map(li => {
|
|
|
+ let r = li.find(f => f.subid);
|
|
|
+ // console.log(r);
|
|
|
+ let obj;
|
|
|
+ //有课程,则显示课程;没有,显示安排的活动,反正都是用subname字段
|
|
|
+ if (r) {
|
|
|
+ let { subname, subid, teaid, teaname, _id: lessonid, date } = r;
|
|
|
+ obj = { subname, subid };
|
|
|
+ obj[`teaid_${index + 1}`] = teaid;
|
|
|
+ obj[`teaname_${index + 1}`] = teaname;
|
|
|
+ obj[`lessonid_${index + 1}`] = lessonid;
|
|
|
+ obj[`date`] = date;
|
|
|
+ } else {
|
|
|
+ let { subname, _id: lessonid, date } = _.head(li);
|
|
|
+ obj = { subname };
|
|
|
+ obj[`lessonid_${index + 1}`] = lessonid;
|
|
|
+ obj[`date`] = date;
|
|
|
+ }
|
|
|
+ obj.batch = i.batch;
|
|
|
+ obj[`classid_${index + 1}`] = i._id;
|
|
|
+ return obj;
|
|
|
+ });
|
|
|
+ return t;
|
|
|
+ // console.log(t);
|
|
|
+ //按照例子处理数据
|
|
|
+ });
|
|
|
+ let l = _.get(_.head(res), 'length');
|
|
|
+ let arr = [];
|
|
|
+ for (let i = 0; i < l; i++) {
|
|
|
+ let obj = {};
|
|
|
+ for (const item of res) {
|
|
|
+ obj = { ...obj, ...item[i] };
|
|
|
+ }
|
|
|
+ arr.push(obj);
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ },
|
|
|
+ //班主任/礼仪课老师=>页面数据形式
|
|
|
+ setTeacher(data, type) {
|
|
|
+ let head = _.head(data);
|
|
|
+ let res = { type };
|
|
|
+ res.date = type == 'headteacher' ? '班主任' : type == 'lyteacher' ? '礼仪课教师' : '教室';
|
|
|
+ let keys = Object.keys(head).filter(f => f.includes('classid'));
|
|
|
+ for (const key of keys) {
|
|
|
+ let cla_id = head[key];
|
|
|
+ let i = key.match(/\d+(.\d+)?/g)[0];
|
|
|
+ let r = this.classList.find(f => f._id == cla_id);
|
|
|
+ if (r) {
|
|
|
+ res[`teaid_${i}`] = _.get(r, `${type}id`);
|
|
|
+ res[`teaname_${i}`] = _.get(r, `${type}name`);
|
|
|
+ res[key] = cla_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ },
|
|
|
+ async getSettingLists() {
|
|
|
+ let res;
|
|
|
+ let arr = [];
|
|
|
+ if (this.locationList.length <= 0) {
|
|
|
+ arr.push(this.getLocationList());
|
|
|
+ }
|
|
|
+ if (this.lyTeacherList.length <= 0) {
|
|
|
+ arr.push(this.getTeacherList({ islyteacher: '1', status: '4' }));
|
|
|
+ }
|
|
|
+ if (this.deptList.length <= 0) {
|
|
|
+ arr.push(this.getDept());
|
|
|
+ }
|
|
|
+ axios.all(arr).then(
|
|
|
+ axios.spread((r1, r2, r3) => {
|
|
|
+ if (r1) this.$set(this, `locationList`, r1.data);
|
|
|
+ if (r2) this.$set(this, `lyTeacherList`, r2.data);
|
|
|
+ if (r3) this.$set(this, `deptList`, r3.data);
|
|
|
+ })
|
|
|
+ );
|
|
|
+ // if (this.headTeacherList.length <= 0) {
|
|
|
+ // res = await this.findTeacher({ planid: data.planid, termid: data.termid, batchid: data.batchid });
|
|
|
+ // let duplicate = _.cloneDeep(res.data);
|
|
|
+ // if (this.$checkRes(res)) {
|
|
|
+ // //班主任按部门分组
|
|
|
+ // let group = _.groupBy(res.data, 'department');
|
|
|
+ // let keys = Object.keys(group);
|
|
|
+ // let arr = keys.map(key => {
|
|
|
+ // let r = this.deptList.find(f => f.id == key);
|
|
|
+ // let obj = {};
|
|
|
+ // if (r) {
|
|
|
+ // obj.name = r.name;
|
|
|
+ // obj.list = group[key];
|
|
|
+ // }
|
|
|
+ // return obj;
|
|
|
+ // });
|
|
|
+ // this.$set(this, `headTeacherList`, arr);
|
|
|
+ // //班主任筛选可以当礼仪老师列表,和 礼仪教师列表合并
|
|
|
+ // duplicate = duplicate.filter(f => f.islyteacher == '1');
|
|
|
+ // this.$set(this, `lyTeacherList`, [...this.lyTeacherList, ...duplicate]);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ //初始化,将每个班级的班主任,礼仪课老师,教室id=>名称
|
|
|
+ async searchClassPerson(obj) {
|
|
|
+ let arr = [];
|
|
|
+ if (_.get(obj, 'jslocationid')) {
|
|
|
+ let r = this.locationList.find(f => f._id == _.get(obj, 'jslocationid'));
|
|
|
+ if (r) obj.jslocationname = _.get(r, `name`);
|
|
|
+ }
|
|
|
+ if (_.get(obj, 'headteacherid')) {
|
|
|
+ let r = await this.getDirector(_.get(obj, 'headteacherid'));
|
|
|
+ if (this.$checkRes(r)) obj.headteachername = _.get(r.data, `name`);
|
|
|
+ }
|
|
|
+ if (_.get(obj, 'lyteacherid')) {
|
|
|
+ let r = await this.getDirector(_.get(obj, 'lyteacherid'));
|
|
|
+ if (this.$checkRes(r) && r.data) {
|
|
|
+ obj.lyteachername = _.get(r.data, `name`);
|
|
|
+ } else {
|
|
|
+ r = await this.getTeacher(_.get(obj, 'lyteacherid'));
|
|
|
+ if (this.$checkRes(r) && r.data) obj.lyteachername = _.get(r.data, `name`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // if (_.get(obj, 'jslocationid')) {
|
|
|
+ // arr.push(this.modelFetch({ model: 'director', id: _.get(obj, 'jslocationid') }));
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ //x轴:日期,查询出所有班级的日期为X轴
|
|
|
+ getX() {
|
|
|
+ let duplicate = _.cloneDeep(this.list);
|
|
|
+ let arr = _.flatten(_.toPairs(_.groupBy(duplicate, `batch`))).filter(f => _.isArray(f));
|
|
|
+ let { startdate: start } = _.head(_.head(arr));
|
|
|
+ let { enddate: end } = _.last(_.last(arr));
|
|
|
+ let day = moment(start)
|
|
|
+ .from(moment(end))
|
|
|
+ .match(/\d+(.\d+)?/g)[0];
|
|
|
+ let res = [start];
|
|
|
+ for (let i = 1; i < day; i++) {
|
|
|
+ res.push(
|
|
|
+ moment(start)
|
|
|
+ .add(i, 'd')
|
|
|
+ .format('YYYY-MM-DD')
|
|
|
+ );
|
|
|
+ }
|
|
|
+ res.push(end);
|
|
|
+ this.$set(this, `x`, res);
|
|
|
},
|
|
|
},
|
|
|
watch: {
|