|
@@ -8,7 +8,7 @@
|
|
|
<el-col :span="24" class="main">
|
|
|
<el-col :span="24" class="leaveBtn"> </el-col>
|
|
|
<el-col :span="24" class="leaveList">
|
|
|
- <datiList :datilist="datilist"></datiList>
|
|
|
+ <datiList :datilist="datilist" :form="form" :answer="answer" @submit="onsave"></datiList>
|
|
|
</el-col>
|
|
|
</el-col>
|
|
|
</el-col>
|
|
@@ -21,6 +21,8 @@ import NavBar from '@/layout/common/topInfo.vue';
|
|
|
import datiList from '@/layout/user/datiList.vue';
|
|
|
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
|
|
|
const { mapActions: mapTask } = createNamespacedHelpers('task');
|
|
|
+const { mapActions: mapTaskUploadtask } = createNamespacedHelpers('uploadtask');
|
|
|
+
|
|
|
export default {
|
|
|
name: 'homework',
|
|
|
props: {},
|
|
@@ -35,6 +37,11 @@ export default {
|
|
|
navShow: true,
|
|
|
title: '',
|
|
|
isleftarrow: '',
|
|
|
+ answer: [],
|
|
|
+ form: {},
|
|
|
+ taskid: '',
|
|
|
+ resdata: '',
|
|
|
+ valid: '',
|
|
|
}),
|
|
|
mounted() {
|
|
|
this.title = this.$route.meta.title;
|
|
@@ -55,26 +62,155 @@ export default {
|
|
|
name() {
|
|
|
return this.$route.query.name;
|
|
|
},
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
+ lessonid() {
|
|
|
+ return this.$route.query.lessonid;
|
|
|
+ },
|
|
|
},
|
|
|
methods: {
|
|
|
...mapTask({ list: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
|
|
|
+ ...mapTaskUploadtask({ Uploadtasklist: 'query', Uploadtaskadd: 'create', Uploadtaskfet: 'fetch', Uploadtaskupdates: 'update' }),
|
|
|
+
|
|
|
+ //查询作业
|
|
|
async search() {
|
|
|
console.log(this.name);
|
|
|
const res = await this.list();
|
|
|
- var tilist = res.data.filter(item => item.name === this.name);
|
|
|
- for (const result of tilist) {
|
|
|
- this.$set(this, `datilist`, result);
|
|
|
-
|
|
|
- for (const option of result.question) {
|
|
|
-
|
|
|
- console.log(answer);
|
|
|
+ var tilist = res.data.filter(item => item.code === this.id);
|
|
|
+ let result = tilist[0];
|
|
|
+ console.log(result.id);
|
|
|
+ this.$set(this, `taskid`, result.id);
|
|
|
+ result.question = result.question.map(i => {
|
|
|
+ if (i.type == 1) {
|
|
|
+ i.answers = [];
|
|
|
+ } else {
|
|
|
+ i.answers = '';
|
|
|
}
|
|
|
|
|
|
- // let answer=[]
|
|
|
- }
|
|
|
+ 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 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),
|
|
|
+ questionid: i._id,
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ answer: i.answers,
|
|
|
+ questionid: i._id,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log(answer);
|
|
|
+
|
|
|
+ //上传
|
|
|
+ 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);
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|