lrf402788946 4 سال پیش
والد
کامیت
bc1c2c2836
4فایلهای تغییر یافته به همراه328 افزوده شده و 1 حذف شده
  1. 6 0
      src/router/index.js
  2. 320 0
      src/views/new-plan/teacher-lesson.vue
  3. 1 1
      src/views/train-plan/parts/teacher.vue
  4. 1 0
      src/views/train-plan/term-lesson.vue

+ 6 - 0
src/router/index.js

@@ -301,6 +301,12 @@ const newPlan = [
     meta: { title: '班级人员' },
     component: () => import('@/views/new-plan/class/name-list.vue'),
   },
+  {
+    path: '/plan/teacher/lesson',
+    name: 'newPlan_teacher_lesson',
+    meta: { title: '初步课程表' },
+    component: () => import('@/views/new-plan/teacher-lesson.vue'),
+  },
 ];
 
 const train = [

+ 320 - 0
src/views/new-plan/teacher-lesson.vue

@@ -0,0 +1,320 @@
+<template>
+  <div id="teacher-lesson">
+    <list-frame :title="pageTitle" :needFilter="false" :needAdd="false" :needPag="false">
+      <el-row>
+        <el-col :span="3">
+          <el-select v-model="form.termid" placeholder="请选择期数" size="mini" clearable filterable>
+            <el-option v-for="(i, index) in termList" :key="index" :label="`第${i.term}期`" :value="i.id"></el-option>
+          </el-select>
+        </el-col>
+        <el-col :span="3">
+          <el-select v-model="form.classtype" placeholder="请选择班级类型" size="mini" clearable filterable>
+            <el-option v-for="(i, index) in ctList" :key="index" :label="i.name" :value="i.code"></el-option>
+          </el-select>
+        </el-col>
+        <el-col :span="3">
+          <el-select v-model="form.subject" placeholder="请选择您想申请授课的科目" size="mini" clearable filterable>
+            <el-option v-for="(i, index) in subjectList" :key="index" :label="i.name" :value="i._id"></el-option>
+          </el-select>
+        </el-col>
+        <el-col :span="5">
+          <el-date-picker
+            v-model="form.range"
+            type="daterange"
+            range-separator="至"
+            start-placeholder="开始日期"
+            end-placeholder="结束日期"
+            size="mini"
+            format="yyyy-MM-dd"
+            value-format="yyyy-MM-dd"
+            clearable
+          >
+          </el-date-picker>
+        </el-col>
+      </el-row>
+      <el-table :data="filterList()" border stripe @cell-click="cellClick">
+        <el-table-column align="center" label="期" prop="term" sortable></el-table-column>
+        <el-table-column align="center" label="班级" prop="name" sortable></el-table-column>
+        <el-table-column align="center" label="科目" prop="subname" sortable></el-table-column>
+        <el-table-column align="center" label="日期" prop="day" sortable></el-table-column>
+        <el-table-column align="center" label="已安排授课教师(点击修改)" prop="teaname"></el-table-column>
+      </el-table>
+
+      <el-dialog title="选择教师" width="30%" :visible.sync="dialog" center :destroy-on-close="true" @close="toClose">
+        <el-row class="row">
+          <el-col :span="24">期:{{ info.term }}</el-col>
+          <el-col :span="24">班级:{{ info.name }}</el-col>
+          <el-col :span="24">科目:{{ info.subname }}</el-col>
+          <el-col :span="24">日期:{{ info.day }}</el-col>
+          <el-col :span="24">
+            教师:
+            <el-select v-model="info.teaid" placeholder="请选择教师" size="mini" filterable clearable @change="selectTeacher">
+              <el-option v-for="(i, index) in applyList" :key="index" :label="i.teaname" :value="i.teacherid"></el-option>
+            </el-select>
+          </el-col>
+        </el-row>
+        <span slot="footer" class="dialog-footer">
+          <el-button @click="dialog = false">取 消</el-button>
+          <el-button type="primary" @click="toUpdate">确 定</el-button>
+        </span>
+      </el-dialog>
+    </list-frame>
+  </div>
+</template>
+
+<script>
+import listFrame from '@frame/layout/admin/list-frame';
+const _ = require('lodash');
+const moment = require('moment');
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
+const { mapActions: subject } = createNamespacedHelpers('subject');
+const { mapActions: ct } = createNamespacedHelpers('classtype');
+const { mapActions: teacher } = createNamespacedHelpers('teacher');
+const { mapActions: teaplan } = createNamespacedHelpers('teaPlan');
+export default {
+  name: 'teacher-lesson',
+  props: {},
+  components: {
+    listFrame,
+  },
+  data: function() {
+    return {
+      dialog: false,
+      form: {
+        range: [],
+      },
+      teacherList: [],
+      plan: {},
+      options: null,
+      lessonsList: [],
+      subjectList: [],
+      ctList: [],
+      termList: [],
+      applyList: [],
+      info: {},
+    };
+  },
+  created() {},
+  methods: {
+    ...teaplan({ getApplyTeacher: 'query' }),
+    ...ct({ getCt: 'query' }),
+    ...subject({ getSubject: 'query' }),
+    ...trainplan({ getPlan: 'fetch', updatePlan: 'update' }),
+    ...teacher({ getTeacher: 'query' }),
+    // 手动修改教师
+    async cellClick(row, column, cell) {
+      let prop = _.get(column, 'property');
+      if (prop != 'teaname') return;
+      const { termid, subid, day: date } = row;
+      const r = await this.getApplyTeacher({ termid, subid, date });
+      if (this.$checkRes(r)) {
+        let { data } = r;
+        data = data.map(i => {
+          let r = this.teacherList.find(f => f.id == i.teacherid);
+          if (r) i.teaname = r.name;
+          return i;
+        });
+        this.$set(this, `applyList`, data);
+      }
+      this.$set(this, `info`, _.cloneDeep(row));
+      this.dialog = true;
+    },
+
+    // 保存
+    async toUpdate() {
+      console.log('in function:');
+      let dup = _.cloneDeep(this.info);
+      const { termid, batchid, classid, ...info } = dup;
+      console.log(termid, batchid, classid, info);
+      let updata = _.pick(info, ['day', 'subid', 'subname', 'teaid', 'teaname', 'time']);
+      const data = this.plan.termnum.map(t => {
+        // 找到期
+        if (t._id == termid) {
+          t.batchnum = t.batchnum.map(b => {
+            if (b._id == batchid) {
+              // 找到批次
+              b.class = b.class.map(c => {
+                if (c._id == classid) {
+                  if (c.lessons) {
+                    // 说明有课程安排,找有没有重复的,没有就推进去,有就更改,subid查
+                    let r = c.lessons.find(f => f.subid == updata.subid);
+                    if (r) {
+                      let rindex = c.lessons.findIndex(f => f.subid == updata.subid);
+                      c.lessons[rindex] = updata;
+                    } else {
+                      c.lessons.push(updata);
+                    }
+                  } else {
+                    // 说明没有课程安排,放进去一条保存
+                    c.lessons = [updata];
+                  }
+                }
+                return c;
+              });
+            }
+            return b;
+          });
+        }
+
+        return t;
+      });
+      let planDup = _.cloneDeep(this.plan);
+      planDup.termnum = data;
+      const res = await this.updatePlan(planDup);
+      if (this.$checkRes(res, '修改成功', res.errmsg || '修改失败')) {
+        this.getInfo('reload');
+        this.toClose();
+      }
+    },
+    async getInfo(type) {
+      if (type != 'reload') {
+        await this.getCtList();
+        await this.getSubjectList();
+        await this.getTeacherList();
+      }
+      await this.getTrain();
+      this.setData();
+    },
+    async getTrain() {
+      const { planid } = this.options;
+      const res = await this.getPlan(planid);
+      if (this.$checkRes(res)) this.$set(this, `plan`, res.data);
+    },
+    async getTeacherList() {
+      const res = await this.getTeacher();
+      if (this.$checkRes(res)) this.$set(this, `teacherList`, res.data);
+    },
+    filterList() {
+      let res = this.lessonsList.filter(f => {
+        let r = this.subjectList.find(sf => sf.id == f.subid);
+        if (r) {
+          const { need_teacher } = r;
+          return need_teacher == '0';
+        }
+        return false;
+      });
+      const { subject, range, classtype, termid } = this.form;
+      if (subject) {
+        res = res.filter(f => f.subid == subject);
+      }
+      if (_.isArray(range) && _.get(range, 'length', 0) == 2) {
+        const start = range[0];
+        const end = range[1];
+        res = res.filter(f => moment(f.day).isBetween(start, end, null, '[]'));
+      }
+      if (classtype) res = res.filter(f => f.type == classtype);
+      if (termid) res = res.filter(f => f.termid == termid);
+      res = _.orderBy(res, ['term', 'day'], ['asc', 'asc']);
+      return res;
+    },
+    setData() {
+      let { termnum } = this.plan;
+      if (!termnum) return;
+      termnum = termnum.map(i => {
+        i.term = i.term * 1;
+        return i;
+      });
+      // 期列表
+      let termList = termnum.map(i => ({ term: i.term, id: i._id }));
+      this.$set(this, `termList`, _.orderBy(termList, ['term'], ['asc']));
+      // 整理出课表
+      let arr = [];
+      for (const t of termnum) {
+        const { batchnum, term, _id: termid } = t;
+        // 班级和课程一一匹配显示在列表上
+        for (const b of batchnum) {
+          let { class: classes, lessons, startdate, enddate, _id: batchid } = b;
+          let claslesList = this.setList(term, termid, batchid, classes, lessons);
+          arr.push(...claslesList);
+        }
+      }
+      this.$set(this, `lessonsList`, arr);
+    },
+    setList(term, termid, batchid, classes, lessonTemplate) {
+      let arr = [];
+      // 班级和课程匹配
+      for (let cla of classes) {
+        cla.term = term;
+        cla.termid = termid;
+        cla.batchid = batchid;
+        let { lessons } = cla;
+        if (!lessons) cla.lessons = lessonTemplate;
+        cla.lessons.map(i => {
+          let obj = _.omit(cla, ['lessons']);
+          obj = { ...obj, ...i, classid: _.clone(cla._id) };
+          arr.push(obj);
+        });
+      }
+      return arr;
+    },
+    async getCtList() {
+      const res = await this.getCt();
+      if (this.$checkRes(res)) this.$set(this, `ctList`, res.data);
+    },
+    async getSubjectList() {
+      const res = await this.getSubject();
+      if (this.$checkRes(res)) {
+        let r = res.data.filter(f => f.need_teacher == '0');
+        r = r.map(i => {
+          let ctr = this.ctList.find(f => f.code == i.type);
+          if (ctr) i.name = `${i.name}(${ctr.name})`;
+          return i;
+        });
+        this.$set(this, `subjectList`, r);
+      }
+    },
+    toClose() {
+      this.dialog = false;
+      this.info = {};
+    },
+    selectTeacher(teaid) {
+      let r = this.applyList.find(f => f.teacherid == teaid);
+      console.log(r);
+      if (r) this.info.teaname = r.teaname;
+    },
+  },
+  watch: {
+    defaultOption: {
+      immediate: true,
+      deep: true,
+      handler(val) {
+        if (!_.get(this, 'options')) {
+          this.$set(this, `options`, _.cloneDeep(val));
+          this.getInfo();
+        } else {
+          let nplanid = _.get(val, 'planid');
+          let oplanid = _.get(this.options, 'planid');
+          if (nplanid && !_.isEqual(nplanid, oplanid)) {
+            this.getInfo();
+          }
+          let ntermid = _.get(val, 'termid');
+          let otermid = _.get(this.options, 'termid');
+          if (ntermid && !_.isEqual(ntermid, otermid)) {
+            this.$set(this, `options`, _.cloneDeep(val));
+            this.getInfo();
+          }
+        }
+      },
+    },
+  },
+  computed: {
+    ...mapState(['user', 'defaultOption']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.row {
+  .el-col {
+    font-size: 18px;
+    padding: 10px 5px;
+  }
+}
+</style>

+ 1 - 1
src/views/train-plan/parts/teacher.vue

@@ -2,7 +2,7 @@
   <div id="teacher">
     <el-tabs v-model="teaTab">
       <el-tab-pane style="padding:10px" label="申请授课教师" name="apply">
-        <filter-table :data="applyList" :fields="teaFields" :opera="opera" @select="selectTeacher" :total="applyTotal" @query="toGetApplyList"></filter-table>
+        <filter-table :data="applyList" :fields="teaFields" :opera="opera" @select="selectTeacher" :usePage="false" @query="toGetApplyList"></filter-table>
       </el-tab-pane>
       <el-tab-pane style="padding:10px" label="可授课教师" name="list">
         <filter-table

+ 1 - 0
src/views/train-plan/term-lesson.vue

@@ -410,6 +410,7 @@ export default {
     },
     lessonSave(data) {
       let { index, batch, is_last, allday, listtype, ...info } = data;
+      console.log(data);
       if (is_last) {
         //TODO 改变半天/全天
         if (this.formType == 'usual') this.$set(this.list[batch - 1], this.list[batch - 1].length - 1, { date: allday, type: 'allday' });