lsc 2 년 전
부모
커밋
54adbc73d7
1개의 변경된 파일53개의 추가작업 그리고 27개의 파일을 삭제
  1. 53 27
      src/components/pages/addCourse.vue

+ 53 - 27
src/components/pages/addCourse.vue

@@ -4437,6 +4437,7 @@ export default {
           let _chapAarry = [];
           let _unitIndex = this.unitIndex;
           let index = 1;
+          let chapindex;
           if (_unitJson2.length > unitJson.length) {
             for (let c = 0; c < _unitJson2.length; c++) {
               _chapAarry.push(_unitJson2[c].chapterInfo[0].chapterid);
@@ -4476,25 +4477,27 @@ export default {
                 _chapAarry.indexOf(_unitJson2[d].chapterInfo[0].chapterid) != -1
               ) {
                 index = 2;
+                chapindex = d;
                 // this.$message.error("您所修改的阶段已经被其他老师删除了");
               }
             }
           } else {
             _unitJson = _unitJson2;
           }
-          if (index == 1) {
-            for (let i = 0; i < unitJson.length; i++) {
-              if (i == _unitIndex) {
-                continue;
-              } else if (i > this.unitJson.length - 1) {
-                _unitJson.push(unitJson[i]);
-              } else if (
-                _unitJson[i].chapterInfo[0].chapterid ==
-                unitJson[i].chapterInfo[0].chapterid
-              ) {
-                _unitJson[i] = unitJson[i];
-              }
+
+          for (let i = 0; i < unitJson.length; i++) {
+            if (i == _unitIndex) {
+              continue;
+            } else if (i > this.unitJson.length - 1) {
+              _unitJson.push(unitJson[i]);
+            } else if (
+              _unitJson[i].chapterInfo[0].chapterid ==
+              unitJson[i].chapterInfo[0].chapterid
+            ) {
+              _unitJson[i] = unitJson[i];
             }
+          }
+          if (index == 1) {
             this.unitJson = _unitJson;
             this.$forceUpdate();
             this.timer = setTimeout(() => {
@@ -4507,30 +4510,25 @@ export default {
                 "您所修改的阶段已经被其他老师删除了,需要恢复嘛?",
                 "提示",
                 {
-                  confirmButtonText: "确定",
+                  confirmButtonText: "需要",
                   cancelButtonText: "取消",
                   type: "warning",
                 }
               )
-              .then(() => {})
+              .then(() => {
+                _this.restoreWork(
+                  _chapAarry[0],
+                  _unitJson,
+                  chapindex,
+                  _unitJson2
+                );
+              })
               .catch(() => {
-                for (let i = 0; i < unitJson.length; i++) {
-                  if (i == _unitIndex) {
-                    continue;
-                  } else if (i > _this.unitJson.length - 1) {
-                    _unitJson.push(unitJson[i]);
-                  } else if (
-                    _unitJson[i].chapterInfo[0].chapterid ==
-                    unitJson[i].chapterInfo[0].chapterid
-                  ) {
-                    _unitJson[i] = unitJson[i];
-                  }
-                }
                 _this.unitJson = _unitJson;
                 _this.$forceUpdate();
                 _this.timer = setTimeout(() => {
                   _this.seleteCourseUpdate();
-                }, 5000);
+                }, 3000);
               });
           }
         })
@@ -4538,6 +4536,34 @@ export default {
           console.error(err);
         });
     },
+    restoreWork(chapid, unitJson, chapindex, unitJson2) {
+      let params = [
+        {
+          cid: this.cid,
+          chapters: JSON.stringify(this.unitJson),
+          uid: this.userid,
+          chapid: chapid,
+        },
+      ];
+      this.ajax
+        .post(this.$store.state.api + "restoreWork", params)
+        .then((res) => {
+          this.$message({
+            message: "恢复成功",
+            type: "success",
+          });
+          unitJson.splice(chapindex, 0, unitJson2[chapindex]);
+          this.unitJson = unitJson;
+          this.$forceUpdate();
+          this.timer = setTimeout(() => {
+            this.seleteCourseUpdate();
+          }, 3000);
+        })
+        .catch((err) => {
+          this.$message.error("修改失败");
+          console.error(err);
+        });
+    },
     getTypeName() {
       console.log(this.courseTypeId);
       this.$forceUpdate();