<template>
  <div class="page-exam-item-result-box">
    <van-nav-bar title="答题" left-arrow @click-left="handleBackFun" />
    <div class="exam-item-result-div">
      <div class="exam-item-result-title">本次答对题目数</div>
      <div class="exam-item-result-grade">{{ grades }}</div>
      <div>正确率：{{ accuracyVal }}</div>
      <div>积分+{{ grades }}</div>
      <div class="exam-item-detial-button-box">
        <van-button
          class="exam-item-detial-button"
          type="primary"
          color="#0088e9"
          @click="handleBackFun"
          >返回</van-button
        >
        <van-button
        v-if="answerRecruitId !='weekly-questions' && answerRecruitId !='special-questions'"
          class="exam-item-detial-button"
          type="primary"
          color="#0088e9"
          @click="handleGoOnFun"
          >再来一组</van-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "page-answer-recruit-result",
  components: {},
  data() {
    return {
      grades: 0,
      allQuestionsNum: 0
    };
  },
  created() {
    this.grades = this.$route.params.grades || 0;
    this.allQuestionsNum = this.$route.params.allQuestionsNum || 0;
    this.setLanXinNavigator();
  },
  activated() {
    this.setLanXinNavigator();
  },
  mounted() {},
  computed: {
    ...mapState({
      answerRecruitId: state => state.answer.answerRecruitId
    }),
    accuracyVal() {
      let that = this;
      if (isNaN(that.grades) || isNaN(that.allQuestionsNum)) {
        return "-";
      }
      return that.allQuestionsNum <= 0
        ? "0%"
        : Math.round((that.grades / that.allQuestionsNum) * 10000) / 100.0 +
            "%";
    }
  },
  methods: {
    // 设置蓝信navigator
    setLanXinNavigator() {
      lx.ui.setNavigationBarTitle({
        title: "答题"
      });
    },
    // 操作：返回
    handleBackFun() {
      this.$router.back();
    },
    // 操作：再来一组
    handleGoOnFun() {
      this.$store.commit("updateAnswerItemStore", {
        field: "answerRecruitId",
        value: "daily-questions" // item.id
      });
      this.$router.replace({ name: "answerRecruit" });
    }
  }
};
</script>

<style lang="scss" scoped>
@import "~@/styles/mixin";
.page-exam-item-result-box {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 0.6rem;
  .exam-item-result-div {
    margin: 0.5rem 0.5rem;
    border: 1px solid #e4e8eb;
    background-color: #fff;
    border-radius: 4px;
    padding: 0.5rem 0.5rem;
    .exam-item-result-title {
      font-size: 0.7rem;
    }
    .exam-item-result-grade {
      font-size: 1.5rem;
      text-align: center;
      margin: 0.5rem 0;
      border-bottom: 1px solid #e4e8eb;
    }

    .exam-item-detial-button-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 0.5rem;
      .exam-item-detial-button {
        width: 48%;
        height: auto;
        padding: 0.5rem 0.5rem;
        font-size: 0.65rem;
      }
    }
  }
}
</style>
