<template>
  <div class="result-box">
    <div class="pop-layer"></div>
    <report @getScore="getScore" @errorResolution="errorResolution">
      <div class="trophy-box">
        <img src="https://webapp-pub.ezijing.com/x-training-new/trophy.png" />
        <div class="text">
          你的得分是<span>{{ parseInt(score) }}</span
          >分
        </div>
      </div>
    </report>
    <div class="analysis-box" v-if="isShow">
      <div class="content">
        <div class="close" @click="close">×</div>
        <div class="tit">错题解析</div>
        <ul>
          <li v-for="(item, index) in answerList" :key="index">
            <div class="title">{{ `${index + 1}.${item.subject}` }}：（分值：{{ parseInt(item.sum_score) }}）</div>
            <div class="my">我的答案：{{ item.commit_answer }}</div>
            <div class="answer">正确答案：{{ item.answer }}</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import Report from '../components/Report.vue'
export default {
  components: { Report },
  data() {
    return {
      score: '',
      isShow: false,
      answerList: []
    }
  },
  created() {
    document.body.scrollTop = document.documentElement.scrollTop = 0
  },
  methods: {
    errorResolution(data) {
      if (data.tag === 'performance_benchmark') {
        const replaceData = data.completions[0].commit_answer.replace(/,/g, '×').replace(/;/g, '+')
        data.completions[0].commit_answer = replaceData
      }
      this.answerList = data.completions
      this.isShow = true
    },
    getScore(res) {
      this.score = res.score
    },
    close() {
      this.isShow = false
    }
  }
}
</script>

<style lang="scss" scoped>
.analysis-box{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 99999;
  .content{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 824px;
    padding: 40px 40px 100px;
    background: #FFFFFF;
    opacity: 1;
    border-radius: 16px;
    max-height: 500px;
    overflow-y: scroll;
    .close{
      position: absolute;
      top: 10px;
      right: 28px;
      width: 20px;
      height: 20px;
      font-size: 40px;
      color: #999999;
      line-height: 100%;
      cursor: pointer;
    }
    .tit{
      font-size: 20px;
      line-height: 100%;
      color: #333333;
    }
    ul{
      li{
        margin-top: 38px;
        div{
          line-height: 100%;
        }
        .title{
          font-size: 16px;
          color: #999999;
          margin-bottom: 18px;
        }
        .my{
          font-size: 16px;
          color: #333333;
          margin-bottom: 12px;
        }
        .answer{
          font-size: 16px;
          color: #4DB299;
        }
      }
    }
  }
}
.result-box {
  margin: 66px auto;
  width: 714px;
  background: #ffffff;
  border: 1px solid #dcdcdc;
  border-radius: 10px;
  padding: 20px;
  box-sizing: border-box;
  position: relative;
  .pop-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 99;
    width: 100%;
    height: 100%;
  }
  .trophy-box {
    padding: 50px 0 38px 0;
    position: relative;
    &::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 620px;
      border-bottom: 1px dashed #c0c0c0;
    }
    img {
      width: 69px;
      display: block;
      margin: 0 auto;
    }
    .text {
      font-size: 18px;
      color: #666666;
      text-align: center;
      margin-top: 18px;
      span {
        color: rgba(67, 169, 143, 1);
        font-size: 26px;
      }
    }
  }
}
</style>
