You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

const app = getApp();
Component({
properties: {
data:{
type:Object,
observer:function(data){
this.answers = data.user_answer.map(i=>i.answer_text);
console.log("answers",this.answers);
}
},
is_md: Boolean,
exercise_status: Number,
user_exercise_status: Number,
},
data: {
},
methods: {
triggerAnswer() {
let answered = this.checkAnswered();
if (this.answered != answered) {
let { question_id, q_position } = this.data.data;
this.triggerEvent("answer", { q_position, question_id, answered }, { bubbles: true });
this.answered = answered;
}
},
checkAnswered(){
for(var answer of this.answers){
if(answer)
return 1;
}
return 0;
},
answer_null_question: function ({ detail: { value }, currentTarget: { dataset:{question_id, exercise_choice_id}} }) {
console.log("answer_main_question");
console.log(value);
console.log(question_id, exercise_choice_id);
app.api("exercise_questions.exercise_answers")({ question_id, exercise_choice_id, answer_text: value })
.then(res => {
this.answers[exercise_choice_id-1] = value;
console.log("answers",this.answers);
this.triggerAnswer();
console.log("answer_main_question"); console.log(res);
})
.catch(e => {
console.error(e);
app.showError(e);
});
},
}
})