|
@@ -21,8 +21,9 @@
|
|
|
import NavBar from '@/layout/common/topInfo.vue';
|
|
|
import footInfo from '@/layout/common/footInfo.vue';
|
|
|
import questionInfo from '@question/src/views/question.vue';
|
|
|
-import { createNamespacedHelpers, mapGetters } from 'vuex';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
const { mapActions: mapQuestion } = createNamespacedHelpers('questionnaire');
|
|
|
+const { mapActions: questionAnswer } = createNamespacedHelpers('questionAnswer');
|
|
|
export default {
|
|
|
name: 'question',
|
|
|
props: {},
|
|
@@ -45,6 +46,7 @@ export default {
|
|
|
this.searchInfo();
|
|
|
},
|
|
|
computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
id() {
|
|
|
return this.$route.query.id;
|
|
|
},
|
|
@@ -61,16 +63,45 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
...mapQuestion(['query', 'fetch', 'update']),
|
|
|
+ ...questionAnswer({ getAnswer: 'query', sendAnswer: 'create', updateAnswer: 'update' }),
|
|
|
async searchInfo({ ...info } = {}) {
|
|
|
+ let answer = await this.getAnswer({ questionnaireid: this.id, studentid: this.user.userid });
|
|
|
+ let asArr = [];
|
|
|
+ let asObject = {};
|
|
|
+ if (this.$checkRes(answer)) {
|
|
|
+ let tAnswer = answer.data[0];
|
|
|
+ asArr = _.get(tAnswer, `answers`, []);
|
|
|
+ asObject.answerid = _.get(tAnswer, `_id`);
|
|
|
+ }
|
|
|
let result = await this.fetch(this.id);
|
|
|
+ // 将答案塞进去
|
|
|
result.data.question.map(i => {
|
|
|
if (!i.answer) i.type === '1' ? (i.answer = []) : '';
|
|
|
+ let mid = asArr.find(f => f.questionid === i.id);
|
|
|
+ if (_.get(mid, `answer`)) {
|
|
|
+ i.answer = JSON.parse(mid.answer);
|
|
|
+ }
|
|
|
return i;
|
|
|
});
|
|
|
- this.$set(this, `info`, result.data);
|
|
|
+ this.$set(this, `info`, { ...result.data, ...asObject });
|
|
|
},
|
|
|
- submit(task) {
|
|
|
- console.log(task);
|
|
|
+ async submit(task) {
|
|
|
+ let { answerid } = task;
|
|
|
+ let { termid, batchid, classid, userid: studentid } = this.user;
|
|
|
+ let answers = task.question.map(i => {
|
|
|
+ let { answer, _id: questionid } = i;
|
|
|
+ answer ? (answer = JSON.stringify(answer)) : '';
|
|
|
+ return { answer, questionid };
|
|
|
+ });
|
|
|
+ let object = { termid, batchid, classid, studentid, questionnaireid: this.id, answers };
|
|
|
+ let res;
|
|
|
+ if (!answerid) {
|
|
|
+ res = await this.sendAnswer(object);
|
|
|
+ } else {
|
|
|
+ object.id = answerid;
|
|
|
+ res = await this.updateAnswer(object);
|
|
|
+ }
|
|
|
+ this.$checkRes(res, '提交成功', res.errmsg);
|
|
|
},
|
|
|
},
|
|
|
};
|