<template>
  <div class="answer-report">
    <div class="title">测试报告</div>
    <div class="answer-info">
      <div>
        <span>耗时</span>
        <span>{{ secondFormatConversion(answer_record.answer_duration, 'chinese') }}</span>
      </div>
      <div>
        <span>正确</span>
        <span>{{ answer_record.right_count }}</span>
      </div>
      <div>
        <span>错误</span>
        <span>{{ answer_record.error_count }}</span>
      </div>
    </div>
    <div
      v-if="
        answer_record.answer_mode === 1 || (answer_record.answer_mode === 2 && answer_record.is_remarked === 'true')
      "
      class="answer-list"
    >
      <span
        v-for="({ question_id, is_objective, answer_status }, i) in question_list"
        :key="question_id"
        :class="['answer-list-item', { subjectivity: is_objective === 'false', error: answer_status === 2 }]"
        @click="selectQuestion(i)"
      >
        {{ i + 1 }}
      </span>
    </div>
  </div>
</template>

<script>
import { GetAnswerRecordReport } from '@/api/exercise';

import { secondFormatConversion } from '@/utils/transform';

export default {
  name: 'AnswerReport',
  props: {
    answerRecordId: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      secondFormatConversion,
      answer_record: {
        answer_duration: 0,
        right_count: 0,
        error_count: 0,
      },
      question_list: [],
    };
  },
  created() {
    this.getAnswerRecordReport();
  },
  methods: {
    selectQuestion(i) {
      this.$emit('selectQuestion', i);
    },

    // 获取答题报告
    getAnswerRecordReport() {
      GetAnswerRecordReport({ answer_record_id: this.answerRecordId })
        .then(({ answer_record, question_list }) => {
          this.answer_record = answer_record;
          this.question_list = question_list;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.answer-report {
  display: flex;
  flex-direction: column;
  row-gap: 24px;
  align-items: center;
  height: 100%;
  padding: 24px 40px;

  .title {
    font-size: 32px;
    font-weight: bold;
    color: $light-main-color;
  }

  .answer-info {
    display: flex;
    column-gap: 120px;
    justify-content: center;
    width: 770px;
    padding: 24px 40px;
    background-color: #f7f7f7;
    border-radius: 8px;

    > div {
      display: flex;
      flex-direction: column;
      row-gap: 8px;

      :first-child {
        color: #949494;
      }

      :last-child {
        font-size: 24px;
        font-weight: bold;
        color: #000;
      }
    }
  }

  .answer-list {
    display: flex;
    gap: 24px;
    width: 770px;

    &-item {
      width: 56px;
      height: 40px;
      padding: 8px;
      text-align: center;
      cursor: pointer;
      background-color: #f0f0f0;
      border-radius: 20px;

      &.error {
        color: #fff;
        background-color: #f2555a;
      }

      &.subjectivity {
        background-color: #fef2a4;
      }
    }
  }
}
</style>
