lrf402788946 há 4 anos atrás
pai
commit
471c7202d8
1 ficheiros alterados com 40 adições e 2 exclusões
  1. 40 2
      src/views/train-plan/term-lesson.vue

+ 40 - 2
src/views/train-plan/term-lesson.vue

@@ -244,8 +244,9 @@ export default {
     // 操作部分
     // 修改教师
     async lessonSave(data) {
+      console.log(data);
       // lessonObjectId:lessonList的某项id; _id:lessons中指定的课
-      const { lessonObjectId, _id, ...info } = data;
+      const { lessonObjectId, _id, is_last, ...info } = data;
       let lobj = this.lessonList.find(f => f._id === lessonObjectId);
       if (!lobj) {
         this.$message.error('未找到该班课表');
@@ -280,6 +281,9 @@ export default {
       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();
@@ -328,7 +332,41 @@ export default {
         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) {