123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- <template>
- <div id="term-lesson">
- <detail-frame :title="pageTitle">
- <el-row type="flex" align="middle" justify="end" class="btn_bar" v-if="!loading">
- <el-col :span="2">
- <el-button type="primary" size="mini" plain @click="toArrange">按模板排课</el-button>
- </el-col>
- <el-col :span="2">
- <el-button type="primary" size="mini" plain @click="toCollateTime">校对每日时间安排</el-button>
- </el-col>
- <el-col :span="2">
- <!-- <el-button type="primary" size="mini" @click="allSave">保存期课表</el-button> -->
- </el-col>
- <el-col :span="2">
- <el-button type="primary" size="mini" plain @click="toStatus">确定课表</el-button>
- </el-col>
- </el-row>
- <div style="min-height:800px" v-loading="loading" element-loading-text="期课表加载中,请稍后..." element-loading-background="rgba(0, 0, 0, 0.8)">
- <excel-term-lesson
- :classType="ctList"
- :data="list"
- :teacherList="teacherList"
- :noticeList="noticeList"
- :subjectList="subjectList"
- :headTeacherList="headTeacherList"
- @lessonChange="toLessonChange"
- @classChange="toClassChange"
- ></excel-term-lesson>
- </div>
- </detail-frame>
- <el-drawer title="课程安排" :visible.sync="lDrawer" :destroy-on-close="true" @close="toClose">
- <lesson-form v-if="lDrawer" :data="form" :subjectList="subjectList" :schoolList="schoolList" @save="lessonSave"></lesson-form>
- </el-drawer>
- <el-drawer title="班级安排" :visible.sync="cDrawer" :destroy-on-close="true" @close="toClose">
- <class-form
- v-if="cDrawer"
- :data="form"
- :locationList="locationList"
- :headTeacherList="headTeacherList"
- :teacherList="teacherList"
- @save="classSave"
- ></class-form>
- </el-drawer>
- </div>
- </template>
- <script>
- import _ from 'lodash';
- import axios from 'axios';
- // const moment = require('moment');
- // moment.locale('zh-cn');
- import excelTermLesson from './parts/excel-term-lesson.vue';
- import lessonForm from './parts/term-lesson-form';
- import classForm from './parts/term-class-from';
- 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');
- const { mapActions: school } = createNamespacedHelpers('school'); //给选老师组件使用.这个页面请求完就不销毁了
- const { mapActions: subject } = createNamespacedHelpers('subject');
- const { mapActions: notice } = createNamespacedHelpers('notice');
- const { mapActions: ct } = createNamespacedHelpers('classtype');
- export default {
- name: 'term-lesson',
- props: {},
- components: { detailFrame, excelTermLesson, lessonForm, classForm },
- data: function() {
- return {
- loading: true,
- lDrawer: false,
- cDrawer: false,
- form: {},
- formType: 'usual',
- options: {},
- list: [],
- classList: [],
- lessonList: [],
- locationList: [],
- teacherList: [],
- deptList: [],
- headTeacherList: [],
- schoolList: [],
- subjectList: [],
- // 班级类型列表
- ctList: [],
- //该期通知列表
- noticeList: [],
- //已经选择的教师列表
- inteaList: [],
- };
- },
- async created() {
- await this.getSettingLists();
- await this.search();
- this.$watch(
- 'defaultOption',
- 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();
- }
- }
- },
- { deep: true }
- );
- },
- methods: {
- ...notice({ getNoticeList: 'query' }),
- ...lesson({
- getLesson: 'query',
- lessonUpdate: 'update',
- plupdate: 'pluralUpdate',
- autoArrange: 'arrange',
- confirmLesson: 'confirmLesson',
- newArrange: 'newArrange',
- timeCollate: 'timeCollate',
- }),
- ...classes({ getClass: 'query', pcupdate: 'pluralUpdate', classUpdate: 'update' }),
- ...ct({ getCt: 'query' }),
- ...subject({ getSubject: 'query' }),
- ...director({ getDirector: 'fetch', getDirectorList: 'query' }),
- ...school({ getSchool: 'findSchool' }),
- ...location({ getLocationList: 'query' }),
- ...teacher({ getTeacherList: 'query', getTeacher: 'fetch', getTeachers: 'lessonteafetch' }),
- ...dirPlan({ dirQuery: 'getDirTeacher' }),
- ...mapDept({ getDept: 'query' }),
- ...teaplan(['findTeacher']),
- async search() {
- this.loading = true;
- // 将 请求班级和 请求课表拆开,以便之后局部修改,保存减少请求次数
- const res = await this.toGetClass();
- if (res === 'noClass') {
- this.loading = false;
- return;
- }
- await this.toGetLesson();
- this.toSetData();
- this.toGetNoticeList();
- this.loading = false;
- },
- // 获取班级
- async toGetClass() {
- let termid = _.get(this.defaultOption, `termid`);
- if (!termid) return;
- let classes = await this.getClass({ termid });
- let classList = [];
- if (this.$checkRes(classes)) {
- classList = classes.data;
- if (classList.length <= 0) {
- this.$message.error('班级未生成,无法查询课表,请先进行学生分班');
- return 'noClass';
- }
- classList = classList.map(i => {
- if (parseInt(i.name)) i.order = parseInt(i.name);
- else i.order = i.name;
- return i;
- });
- classList = _.orderBy(classList, ['order'], ['asc']);
- this.$set(this, `classList`, classList);
- }
- },
- // 获取课程
- async toGetLesson() {
- let termid = _.get(this.defaultOption, `termid`);
- if (!termid) return;
- let lessonList = [];
- let lessons = await this.getLesson({ termid });
- if (this.$checkRes(lessons)) {
- lessonList = lessons.data;
- // 因为操作不当,lesson会产生垃圾数据;所以这里要过滤下,只保留当前班级的lesson
- const classids = this.classList.map(f => f._id);
- lessonList = lessonList.filter(f => classids.includes(f.classid));
- if (lessonList.length <= 0) {
- this.toArrange(false);
- return;
- }
- this.$set(this, `lessonList`, lessonList);
- }
- },
- // 整理班级和课程
- async toSetData() {
- let classList = _.cloneDeep(this.classList);
- classList = classList.map(i => {
- const lesson = this.lessonList.find(f => f.classid === i._id);
- if (lesson) i.lesson = lesson;
- else i.lesson = {};
- return i;
- });
- this.$set(this, `list`, classList);
- },
- // 获取地点,学校,部门,科目,教师,班级类型,班主任
- async getSettingLists() {
- let res;
- let arr = [];
- if (this.locationList.length <= 0) {
- arr.push(this.getLocationList());
- }
- if (this.teacherList.length <= 0) {
- arr.push(this.getTeacherList());
- }
- if (this.schoolList.length <= 0) {
- arr.push(this.getSchool());
- }
- if (this.deptList.length <= 0) {
- arr.push(this.getDept());
- }
- if (this.subjectList.length <= 0) {
- arr.push(this.getSubject());
- }
- if (this.ctList.length <= 0) {
- arr.push(this.getCt());
- }
- if (this.headTeacherList.length <= 0) {
- arr.push(this.getDirectorList());
- }
- axios.all(arr).then(
- axios.spread((r1, r2, r3, r4, r5, r6, r7) => {
- if (r1) this.$set(this, `locationList`, r1.data);
- if (r2) this.$set(this, `teacherList`, r2.data);
- if (r3) this.$set(this, `schoolList`, r3.data);
- if (r4) this.$set(this, `deptList`, r4.data);
- if (r5) this.$set(this, `subjectList`, r5.data);
- if (r6) {
- let d = _.cloneDeep(r6.data);
- d = d.map(i => {
- i.order = parseInt(i.code);
- return i;
- });
- d = _.orderBy(d, ['order'], ['asc']);
- this.$set(this, `ctList`, d);
- }
- if (r7) this.$set(this, `headTeacherList`, r7.data);
- })
- );
- },
- // 操作部分
- // 修改教师
- async lessonSave(data) {
- console.log(data);
- // lessonObjectId:lessonList的某项id; _id:lessons中指定的课
- const { lessonObjectId, _id, is_last, ...info } = data;
- let lobj = this.lessonList.find(f => f._id === lessonObjectId);
- if (!lobj) {
- this.$message.error('未找到该班课表');
- return;
- }
- let { lessons } = lobj;
- if (!lessons) {
- this.$message.error('未找到该班的课程');
- return;
- }
- let r = lessons.find(f => f._id === _id);
- if (!r) {
- this.$message.error('未找到该课程');
- return;
- }
- const ri = lessons.findIndex(f => f._id === _id);
- r = { ...r, ...info };
- lessons[ri] = r;
- let sameDay = lessons.find(f => f.date === r.date && f.subid && f._id !== r._id);
- if (sameDay) {
- const { teaid, teaname, reason } = data;
- sameDay.teaid = teaid;
- sameDay.teaname = teaname;
- sameDay.reason = reason;
- let sameDayIndex = lessons.findIndex(f => f.date === r.date && f.subid && f._id !== r._id);
- lessons[sameDayIndex] = sameDay;
- }
- lobj.lessons = lessons;
- let msg = this.$message({ duration: 0, message: '正在修改课程信息,请稍后...' });
- const res = await this.lessonUpdate(lobj);
- msg.close();
- if (this.$checkRes(res, null, res.errmsg || '修改失败')) {
- msg = this.$message({ duration: 0, message: '重新读取课程信息,请稍后...' });
- await this.toClearSameDay(data);
- if (is_last) {
- await this.toChangeDay(data);
- }
- await this.toGetLesson();
- this.toSetData();
- this.toClose();
- msg.close();
- this.$message.success('已完成重新读取课程信息');
- }
- },
- // 将该教师其他同一天的安排干掉
- async toClearSameDay(data) {
- const { lessonObjectId, date, teaid } = data;
- let lobjs = this.lessonList.filter(f => f._id !== lessonObjectId);
- let needUpdate = [];
- for (let lobj of lobjs) {
- let { lessons } = lobj;
- if (!lessons || !_.isArray(lessons)) continue;
- let ncList = lessons.filter(f => f.date === date && f.teaid === teaid);
- // 该班课表,该天,没有该教师了,继续下一个
- if (ncList.length <= 0) continue;
- // 要是有,就改了,然后放到needUpdate中
- for (let nc of ncList) {
- const ri = lessons.findIndex(f => _.isEqual(f, nc));
- if (ri < 0) continue;
- nc.teaid = undefined;
- nc.teaname = undefined;
- lessons[ri] = nc;
- }
- lobj.lessons = lessons;
- delete lobj.meta;
- needUpdate.push(lobj);
- }
- if (needUpdate.length > 0) {
- const r = await this.plupdate(needUpdate);
- }
- },
- // 修改班级设置
- async classSave(data) {
- let msg = this.$message({ duration: 0, message: '正在修改,请稍后...' });
- const res = await this.classUpdate(data);
- msg.close();
- if (this.$checkRes(res, null, res.errmsg || '修改班级设置失败')) {
- msg = this.$message({ duration: 0, message: '重新读取班级信息,请稍后...' });
- await this.toGetClass();
- this.toSetData();
- this.toClose();
- msg.close();
- this.$message.success('已完成重新读取班级信息');
- }
- },
- // 修改这一批次的所有课程的最后一天为全天/半天
- async toChangeDay(data) {
- const { lessonObjectId, _id, is_last, day, ...info } = data;
- let lobj = this.lessonList.find(f => f._id === lessonObjectId);
- if (!lobj) return;
- const { batchid } = lobj;
- let lobjs = this.lessonList.filter(f => f.batchid === batchid);
- for (let o of lobjs) {
- delete o.meta;
- let { lessons } = o;
- if (!(lessons && _.isArray(lessons))) continue;
- const g = _.groupBy(lessons, 'date');
- console.log(g);
- let dkeys = Object.keys(g);
- dkeys = _.orderBy(
- dkeys.map(i => ({ date: i })),
- ['date'],
- ['asc']
- );
- const k = _.last(dkeys);
- if (!k) continue;
- // 将最后一天的所有day改成data的day
- let needCList = g[k.date];
- console.log(needCList);
- for (let nco of needCList) {
- const i = lessons.findIndex(f => f._id === nco._id);
- if (i < 0) continue;
- nco.day = day;
- console.log(nco);
- lessons[i] = nco;
- }
- o.lessons = lessons;
- }
- const r = await this.plupdate(lobjs);
- },
- // 页面及其他逻辑
- // 打开修改课程框
- toLessonChange(data) {
- this.$set(this, 'form', data);
- this.lDrawer = true;
- },
- // 打开修改班级设置框
- toClassChange(data) {
- this.$set(this, `form`, data);
- this.cDrawer = true;
- },
- // 关闭窗口
- toClose() {
- this.lDrawer = false;
- this.cDrawer = false;
- this.formType = 'usual';
- this.form = {};
- },
- //检查班主任/教室/礼仪课教师
- checkClassConfig(dClass) {
- let res = [];
- for (const cla of dClass) {
- let { headteacherid, jslocationid, lyteacherid, name } = cla;
- let obj = { name };
- // true:表示这个位置没有id
- if (!headteacherid) obj.headteacher = true;
- if (!jslocationid) obj.jslocation = true;
- if (!lyteacherid) obj.lyteacher = true;
- if (Object.keys(obj).length > 1) res.push(obj);
- }
- return res;
- },
- //查看某班课表
- toOneClass(classid) {
- this.$router.push({ path: '/train/plan/class/lesson', query: { classid } });
- },
- //课表模板排课
- async toArrange(needAlert = true) {
- let planid = _.get(this.defaultOption, 'planid');
- let termid = _.get(this.defaultOption, `termid`);
- if (needAlert)
- this.$confirm('此操作将会将后生成且没有课表的班级生成课表,已经生成的课表将不会改变!', '提示', {
- confirmButtonText: '按模板排课',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(async () => {
- let res = await this.newArrange({ planid, termid });
- this.$checkRes(res, '排课成功', res.errmsg || '排课失败');
- this.search();
- })
- .catch(async () => {
- console.log('已取消');
- });
- else {
- let msg = this.$message({
- message: '首次进入,计划未排课,正在按模板进行排课中...',
- duration: 0,
- });
- let res = await this.newArrange({ planid, termid });
- msg.close();
- if (this.$checkRes(res, '排课成功', res.errmsg || '排课失败')) {
- this.search();
- } else {
- this.loading = false;
- }
- }
- },
- // 确定课表
- async toStatus() {
- let lessonIds = this.lessonList.map(i => i.id);
- const classids = this.classList.map(f => f._id);
- const res = await this.confirmLesson({ ids: lessonIds, classids });
- this.$checkRes(res, '课表确定成功', res.errmsg || '课表确定失败');
- },
- // 获取消息
- async toGetNoticeList() {
- const { planid, termid } = this.defaultOption;
- const res = await this.getNoticeList({ planid, termid, type: '4' });
- if (this.$checkRes(res)) this.$set(this, `noticeList`, res.data);
- },
- // 校对时间
- async toCollateTime() {
- let termid = _.get(this.defaultOption, `termid`);
- this.$confirm('此操作将会将把 本期的 每天时间的安排 按 "系统管理->课表模板" 中对应的模板进行覆盖,请确认好 课表模板 中的时间是否正确!', '提示', {
- confirmButtonText: '确认覆盖',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(async () => {
- const res = await this.timeCollate({ termid });
- if (this.$checkRes(res)) {
- this.$message.success('校对成功');
- this.search();
- }
- })
- .catch(async () => {
- console.log('已取消');
- });
- },
- },
- computed: {
- ...mapState(['user', 'defaultOption']),
- pageTitle() {
- return `${this.$route.meta.title}`;
- },
- },
- metaInfo() {
- return { title: this.$route.meta.title };
- },
- };
- </script>
- <style lang="less" scoped></style>
|