<template>
  <div class="question-view">
    <div class="question-body" v-html="question.body"></div>
    <div class="ops">
      <div class="stu-answer"> {{stuAnswer}}</div>
      <i-button @click="resetQuestion(examQuestion.id)">重置</i-button>
      <div class="score">({{question.questionScore}}分)</div>
    </div>
    <div @click="answerQuestion(examQuestion.id, '正确')">
      <input type="radio" name="question" value="正确" :checked="stuAnswer === '正确'" />
      <span class="question-options">正确</span>
    </div>
    <div @click="answerQuestion(examQuestion.id, '错误')">
      <input type="radio" name="question" value="错误" :checked="stuAnswer === '错误'" />
      <span class="question-options">错误</span>
    </div>

  </div>
</template>

<script>
export default {
  name: "BooleanQuestionView",
  data() {
    return {
      stuAnswer: this.examQuestion.stuAnswer
    };
  },
  props: {
    question: Object,
    examQuestion: Object
  },
  methods: {
    answerQuestion: function(examQuestionId, stuAnswer) {
      this.stuAnswer = stuAnswer;
      this.$http.put("/api/exam_question/" + examQuestionId, { stuAnswer });
    },
    resetQuestion: function(examQuestionId) {
      this.stuAnswer = null;
      this.$http.put("/api/exam_question/" + examQuestionId, {
        stuAnswer: null
      });
    }
  },
  watch: {}
};
</script>

<style scoped>
.question-view {
  display: block;
}

.ops {
  display: flex;
  align-items: flex-end;
}

.stu-answer {
  width: 100px;
  border-bottom: 1px solid black;
}

.option {
  display: flex;
}
.question-options {
  text-align: left;
  padding-left: 10px;
}
</style>
