浏览代码

Merge branch 'master' of https://git.cocorobo.cn/CocoRoboLabs/pbl-teacher-table

zengyicheng 2 年之前
父节点
当前提交
8cb01a2ab3
共有 1 个文件被更改,包括 184 次插入24 次删除
  1. 184 24
      src/components/pages/addCourse.vue

+ 184 - 24
src/components/pages/addCourse.vue

@@ -2630,7 +2630,8 @@ export default {
       courseUserid: "",
       timer: null,
       checkId: "",
-      isDelete:1,
+      isDelete: 1,
+      addindex: 0,
     };
   },
   computed: {
@@ -2644,7 +2645,7 @@ export default {
   },
   watch: {
     unitIndex(newValue, oldValue) {
-      if(this.isDelete == 2){
+      if (this.isDelete == 2) {
         this.isDelete = 1;
         return;
       }
@@ -2696,6 +2697,12 @@ export default {
           this.unitIndex = oldValue;
           return;
         }
+        for (var i = 0; i < this.unitJson.length; i++) {
+          if (this.addindex != i) {
+            delete this.unitJson[i].isUpdate;
+          }
+        }
+        this.addindex = -1;
         let params = [
           {
             cid: this.cid,
@@ -3353,6 +3360,7 @@ export default {
     addunit() {
       this.unitJson.push({
         dyName: "", //单元标题
+        isUpdate: 1,
         chapterInfo: [
           {
             isread: false,
@@ -3393,6 +3401,7 @@ export default {
           },
         ],
       });
+      this.addindex = this.unitJson.length - 1;
       setTimeout(() => {
         this.unitIndex = this.unitJson.length - 1;
         this.unitSet(this.unitIndex);
@@ -3603,10 +3612,14 @@ export default {
           }
         }
       }
+
       if (cPan == 2) {
         this.steps--;
         return;
       }
+      for (var i = 0; i < this.unitJson.length; i++) {
+        delete this.unitJson[i].isUpdate;
+      }
       let params = [
         {
           uid: this.userid,
@@ -3762,6 +3775,9 @@ export default {
         this.steps--;
         return;
       }
+      for (var i = 0; i < this.unitJson.length; i++) {
+        delete this.unitJson[i].isUpdate;
+      }
       let params = [
         {
           cid: this.cid,
@@ -4413,50 +4429,194 @@ export default {
       this.ajax
         .get(this.$store.state.api + "select_course_detail", params)
         .then((res) => {
+          // console.log(this.unitJson);
           let unitJson = JSON.parse(res.data[0][0].chapters);
-          // this.unitJson2 = JSON.parse(res.data[0][0].chapters);
+          this.unitJson2 = JSON.parse(res.data[0][0].chapters);
           let _unitJson2 = JSON.parse(JSON.stringify(this.unitJson));
           let _unitJson = [];
-          let _chapAarry = []
-          let _unitIndex = this.unitIndex;
-          if(_unitJson2.length > unitJson.length){
-            for(let c = 0;c<_unitJson2.length;c++){
-              _chapAarry.push(_unitJson2[c].chapterInfo[0].chapterid)
+          let _chapAarry = [];
+          let _unitIndex = JSON.parse(JSON.stringify(this.unitIndex));
+          let _unitIndex2 = JSON.parse(JSON.stringify(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);
             }
-            for(let j = 0;j<unitJson.length;j++){
-              let count = 0
-              for(let k = 0;k<_unitJson2.length;k++){
-                if(unitJson[j].chapterInfo[0].chapterid == _unitJson2[k].chapterInfo[0].chapterid){
-                  count++
-                  _chapAarry.splice(_chapAarry.indexOf(_unitJson2[k].chapterInfo[0].chapterid),1)
+            for (let j = 0; j < unitJson.length; j++) {
+              let count = 0;
+              for (let k = 0; k < _unitJson2.length; k++) {
+                if (
+                  unitJson[j].chapterInfo[0].chapterid ==
+                  _unitJson2[k].chapterInfo[0].chapterid
+                ) {
+                  count++;
+                  _chapAarry.splice(
+                    _chapAarry.indexOf(_unitJson2[k].chapterInfo[0].chapterid),
+                    1
+                  );
                   _unitJson.push(unitJson[j]);
                   break;
                 }
               }
-              if(count === 0){
-                this.$message.error("您所修改的阶段已经被其他老师删除了");
+              // if(count === 0){
+              //   this.$message.error("您所修改的阶段已经被其他老师删除了");
+              // }
+            }
+            for (let k = 0; k < _unitJson2.length; k++) {
+              if (_unitJson2[k].isUpdate == 1) {
+                _chapAarry.splice(
+                  _chapAarry.indexOf(_unitJson2[k].chapterInfo[0].chapterid),
+                  1
+                );
+                _unitJson.push(_unitJson2[k]);
               }
             }
             console.log(_chapAarry);
-          }else{
-            _unitJson = _unitJson2
+            for (let d = 0; d < _unitJson2.length; d++) {
+              if (
+                _chapAarry.indexOf(_unitJson2[d].chapterInfo[0].chapterid) != -1
+              ) {
+                if (_unitIndex == d) {
+                  index = 2;
+                }
+                chapindex = d;
+                // this.$message.error("您所修改的阶段已经被其他老师删除了");
+              }
+            }
+          } else {
+            _unitJson = JSON.parse(JSON.stringify(_unitJson2));
           }
+
           for (let i = 0; i < unitJson.length; i++) {
-            if (i == _unitIndex) {
-              continue;
-            } else if (i > this.unitJson.length - 1) {
+            if (
+              (i < _unitJson.length - 1 || i == _unitJson.length - 1) &&
+              _unitJson[i].chapterInfo[0].chapterid !=
+                unitJson[i].chapterInfo[0].chapterid
+            ) {
+              if (i == _unitJson.length - 1) {
+                // this.unitIndex++
+                _unitIndex2++;
+              }
+              _unitJson.splice(i, 0, unitJson[i]);
+            } else if (i > _unitJson.length - 1) {
               _unitJson.push(unitJson[i]);
-            } else if(_unitJson[i].chapterInfo[0].chapterid == unitJson[i].chapterInfo[0].chapterid){
+            } else if (
+              _unitJson[i].chapterInfo[0].chapterid ==
+              unitJson[i].chapterInfo[0].chapterid
+            ) {
               _unitJson[i] = unitJson[i];
             }
+            // if (i == _unitIndex) {
+            //   continue;
+            // } else
+          }
+
+          if (_chapAarry.length && index != 2) {
+            if (chapindex < _unitIndex) {
+              this.isDelete = 2;
+              // this.unitIndex--;
+              _unitIndex2--;
+            } else if (
+              _unitJson2[_unitIndex].chapterInfo[0].chapterid !=
+              _unitJson[_unitIndex].chapterInfo[0].chapterid
+            ) {
+              this.isDelete = 2;
+              for (let n = 0; n < _unitJson.length; n++) {
+                if (
+                  _unitJson2[_unitIndex].chapterInfo[0].chapterid ==
+                  _unitJson[n].chapterInfo[0].chapterid
+                ) {
+                  // this.unitIndex = n;
+                  _unitIndex2 = n;
+                  _unitJson[n] = _unitJson2[_unitIndex];
+                  break;
+                }
+              }
+            }
+          } else if (index != 2) {
+            // _unitJson[this.unitIndex] = _unitJson2[_unitIndex];
+            _unitJson[_unitIndex2] = _unitJson2[_unitIndex];
+          }
+          if (index == 1) {
+            this.unitJson = _unitJson;
+            this.$forceUpdate();
+            setTimeout(() => {
+              this.isDelete = 2;
+              this.unitIndex = _unitIndex2;
+            }, 0);
+            this.timer = setTimeout(() => {
+              this.seleteCourseUpdate();
+            }, 2000);
+          } else if (index == 2) {
+            let _this = this;
+            _this
+              .$confirm(
+                "您所修改的阶段已经被其他老师删除了,需要恢复嘛?",
+                "提示",
+                {
+                  confirmButtonText: "需要",
+                  cancelButtonText: "取消",
+                  type: "warning",
+                }
+              )
+              .then(() => {
+                if (_this.time()) {
+                  _this.restoreWork(
+                    _chapAarry[0],
+                    _unitJson,
+                    chapindex,
+                    _unitJson2,
+                    _unitIndex2
+                  );
+                }
+              })
+              .catch(() => {
+                _this.unitJson = _unitJson;
+                _this.$forceUpdate();
+                setTimeout(() => {
+                  this.isDelete = 2;
+                  this.unitIndex = _unitIndex2;
+                }, 0);
+                _this.timer = setTimeout(() => {
+                  _this.seleteCourseUpdate();
+                }, 2000);
+              });
           }
-          this.unitJson = _unitJson;
+        })
+        .catch((err) => {
+          console.error(err);
+        });
+    },
+    restoreWork(chapid, unitJson, chapindex, unitJson2, unitIndex2) {
+      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();
+          setTimeout(() => {
+            this.isDelete = 2;
+            this.unitIndex = unitIndex2;
+          }, 0);
           this.timer = setTimeout(() => {
             this.seleteCourseUpdate();
-          }, 5000);
+          }, 2000);
         })
         .catch((err) => {
+          this.$message.error("修改失败");
           console.error(err);
         });
     },