lrf402788946 5 年之前
父节点
当前提交
c96fee9cf9
共有 2 个文件被更改,包括 334 次插入6 次删除
  1. 77 0
      src/views/train-plan/parts/term-lesson-table.vue
  2. 257 6
      src/views/train-plan/term-lesson.vue

+ 77 - 0
src/views/train-plan/parts/term-lesson-table.vue

@@ -0,0 +1,77 @@
+<template>
+  <div id="term-lesson-table">
+    <el-table :data="list" size="mini" tooltip-effect="dark" border stripe :cell-style="{ height: '50px' }" :span-method="data => spanTable(data, 't1')">
+      <el-table-column align="center" label="日期" prop="date" :show-overflow-tooltip="true"></el-table-column>
+      <el-table-column align="center" label="星期" :show-overflow-tooltip="true">
+        <template v-slot="{ row, $index }">
+          <template v-if="$index !== list.length - 1">
+            {{ row.date | getWeekDay }}
+          </template>
+        </template>
+      </el-table-column>
+      <el-table-column align="center" label="课程内容" prop="subname" :show-overflow-tooltip="true"></el-table-column>
+      <el-table-column align="center" label="1班" prop="teaname_1" :show-overflow-tooltip="true"></el-table-column>
+      <el-table-column align="center" label="2班" prop="teaname_2" :show-overflow-tooltip="true"></el-table-column>
+    </el-table>
+  </div>
+</template>
+
+<script>
+import _ from 'lodash';
+const moment = require('moment');
+moment.locale('zh-cn');
+import { mapState, createNamespacedHelpers } from 'vuex';
+export default {
+  name: 'term-lesson-table',
+  props: {
+    data: { type: Array, default: () => [] },
+    batch: { type: [String, Array] },
+  },
+  components: {},
+  data: function() {
+    return {};
+  },
+  created() {},
+  methods: {
+    spanTable({ row, column, rowIndex, columnIndex }, arrayName) {
+      let res = { rowspan: 1, colspan: 1 };
+      let l = _.get(this.list, 'length');
+      let b = this.batch * 1;
+      //区别在于改变的行数不一致,错位的
+      //b: 1-3
+      //t1 是要改变 0+6 至 l-1-2 行的内容 => 6 - 8
+      //t2 1+6 至 l-1-1 => 7-9
+      //t3 2+6 至 l-1-0 => 8-10
+      // b为该期的批次 batch
+      // 左侧是:0+6;1+6;2+6 => b-1+6
+      // 右侧是: l-1 -2; l-1  -1; l-1 -0 => l-1 -(3-b)
+      if (_.inRange(rowIndex, b + 5, l - 4 + b) && columnIndex < 1) {
+        res.colspan = 3;
+      }
+      if (_.inRange(rowIndex, b + 5, l - 4 + b) && columnIndex >= 1 && columnIndex <= 2) {
+        res.colspan = 0;
+      }
+      if (rowIndex == l - 1) {
+        res.colspan = 5;
+      }
+      return res;
+    },
+  },
+  filters: {
+    getWeekDay(date) {
+      if (date && moment.isMoment(moment(date)) && moment(date).isValid()) return moment(date).format('dddd');
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    list() {
+      return _.cloneDeep(this.data);
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 257 - 6
src/views/train-plan/term-lesson.vue

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