瀏覽代碼

更新在线作答

wuhongyuq 5 年之前
父節點
當前提交
17fb9b9437
共有 1 個文件被更改,包括 88 次插入19 次删除
  1. 88 19
      src/views/user/dati.vue

+ 88 - 19
src/views/user/dati.vue

@@ -40,6 +40,8 @@ export default {
     answer: [],
     form: {},
     taskid: '',
+    resdata: '',
+    valid: '',
   }),
   mounted() {
     this.title = this.$route.meta.title;
@@ -75,7 +77,6 @@ export default {
     async search() {
       console.log(this.name);
       const res = await this.list();
-
       var tilist = res.data.filter(item => item.code === this.id);
       let result = tilist[0];
       console.log(result.id);
@@ -87,44 +88,62 @@ export default {
           i.answers = '';
         }
 
-        // i.answers = JSON.parse(i.answers);
         return i;
         console.log(result.question);
       });
       this.$set(this, `datilist`, result);
+      let stuid = this.user.userid;
+      let lessonid = this.lessonid;
+
+      let ress = await this.Uploadtasklist({ lessonid });
+      console.log(ress.data);
 
+      this.$set(this, `resdata`, ress.data);
+      //回显
+      for (const val of ress.data) {
+        let less = val.answers;
+        console.log(val.id);
+        this.$set(this, `valid`, val.id);
+        console.log(less);
+        result.question.map(i => {
+          if (i.type == 1) {
+            val.answers.map(m => {
+              if (i._id == m.questionid) {
+                // 将string类型还原
+                i.answers = JSON.parse(m.answer);
+                return m;
+              }
+            });
+          } else {
+            less.map(n => {
+              if (i._id == n.questionid) {
+                i.answers = n.answer;
+                return n;
+              }
+            });
+          }
+          return i;
+          console.log(result.question);
+        });
+      }
       this.loading = false;
     },
 
     async onsave() {
-      // let data = this.datilist.question;
-      // let new_arr = [];
-      // for (const acc of data) {
-
-      //   let less = { questionid: acc._id };
-      //   less.answer = JSON.stringify(acc.answers);
-      //   new_arr.push(less.answer);
-      //   console.log(less);
-      //   let answers = [less];
-      //   let lesson = { termid: this.user.termid, lessonid: this.lessonid, batchid: this.user.batchid, classid: this.user.classid, studentid: this.user.userid };
-      //   lesson.answers = answers;
-      //   console.log(lesson);
-      // }
       let answerss = {
         termid: this.user.termid,
         batchid: this.user.batchid,
         classid: this.user.classid,
         lessonid: this.lessonid,
+        id: this.valid,
         studentid: this.user.userid,
         taskid: this.taskid,
       };
       let answers = {};
-
       let data = this.datilist.question;
       var answer = data.map(i => {
         answers.questionid = i._id;
         answers.answer = JSON.stringify(i.answers);
-
         if (i.type == 1) {
           return {
             answer: JSON.stringify(i.answers),
@@ -139,8 +158,58 @@ export default {
       });
       console.log(answer);
 
-      answerss.answer = answer;
-      let res = await this.Uploadtaskadd(answerss);
+      //上传
+      let dati = this.resdata;
+      //作业
+      let task = this.datilist;
+      console.log(task);
+      //合并集合时使用
+      let newsc = [];
+      for (const shangchan of dati) {
+        console.log(shangchan);
+        task.question.map(n => {
+          if (n.type == 1) {
+            // a b array类型
+            let a = n.answer.split(';');
+            let b = n.answers;
+            console.log(b);
+            let c = new Set(a);
+            let d = new Set(b);
+            //差集判断答案
+            let differenceABSet = new Set([...d].filter(x => !c.has(x)));
+            var sc = shangchan.answers.map(a => {
+              if (n._id == a.questionid) {
+                if (differenceABSet.size === 0) {
+                  return {
+                    // 转换成string
+                    answer: JSON.stringify(n.answers),
+                    questionid: n._id,
+                    questionscore: n.score,
+                  };
+                }
+              }
+            });
+          } else {
+            var sc = shangchan.answers.map(a => {
+              //字符串判断答案
+              if (n._id == a.questionid) {
+                if (n.answers === n.answer) {
+                  return {
+                    answer: n.answers,
+                    questionid: n._id,
+                    questionscore: n.score,
+                  };
+                }
+              }
+            });
+          }
+          //合并数组
+          newsc = [...sc, ...newsc];
+          var arr = newsc.filter(item => item);
+          answerss.answers = arr;
+        });
+      }
+      let res = await this.Uploadtaskupdates(answerss);
     },
   },
 };