<template>
  <div class="end_box">
    <div id="bottom-view3">
      <div class="end_con">
        <div class="cs_type"><span>测试内容：</span>{{ title }}</div>
        <div class="cs_time"><span>测试时间：</span>{{ questionsData.created_time }}</div>
        <div class="charts">
          <svg width="86%" height="86%" viewBox="0 0 100 100">
            <circle r="25" cx="50" cy="50" fill="none" stroke="rgba(255,193,79,1)" stroke-width="50" stroke-dasharray="158 158" />
          </svg>
          <svg class="w_svg" width="100%" height="100%" viewBox="0 0 100 100">
            <circle r="25" cx="50" cy="50" fill="none" stroke="#07cb78" stroke-width="50" :stroke-dasharray="ratio" />
          </svg>
          <div class="circle">
            <p class="p1">正确率</p>
            <p class="p2">{{ratioNum}}%</p>
          </div>
        </div>
        <div class="assess">
          <div class="tit">测试评估：</div>
          <img v-show="ratioNum < 20" src="../assets/images/mountain0.png" alt="">
          <img v-show="ratioNum >= 20 && ratioNum < 40" src="../assets/images/mountain1.png" alt="">
          <img v-show="ratioNum >= 40 && ratioNum < 60" src="../assets/images/mountain2.png" alt="">
          <img v-show="ratioNum >= 60 && ratioNum < 99" src="../assets/images/mountain3.png" alt="">
          <img v-show="ratioNum == 100" src="../assets/images/mountain4.png" alt="">
          <div v-if="ratioNum == 100" class="txt">成功近在眼前，再接再厉！</div>
          <div v-else class="txt">您离成功还有一段距离，继续努力！</div>
        </div>
        <div class="nl-btn" v-if="title == '能力自测'">
          <div class="btn" @click="$router.go(-1)">重做测试</div>
          <div class="btn">学习课程</div>
        </div>
        <div class="card">
          <div class="tit">答题卡：</div>
          <div class="card_con">
            <div class="flag">
              <ul>
                <li>
                  <div class="circle active1">1</div>
                  <div class="txt">正确</div>
                </li>
                <li>
                  <div class="circle active2">1</div>
                  <div class="txt">错误</div>
                </li>
                <li>
                  <div class="circle active3">1</div>
                  <div class="txt">未答</div>
                </li>
              </ul>
            </div>
            <div class="question">
              <template v-for="(item, index) in questionsData.questions">
                <div :key="index">
                  <div class="title">{{ questionType[item.type] }}</div>
                  <ul>
                    <template v-for="(cItem, cIndex) in item.question_list">
                      <template v-if="requestData[item.id]">
                        <template v-if="requestData[item.id][cItem.id]">
                          <!-- <template v-if="questionsData.score_items[item.id]">
                            {{ questionsData.score_items[item.id] }}
                          </template> -->
                          <template v-if="requestData[item.id][cItem.id].answer.length != 0">
                            <template v-if="questionsData.score_items[item.id]">
                              <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" :class="questionsData.score_items[item.id][cItem.id].is_right ? 'active1' : 'active2'">{{ cIndex+1 }}</li>
                            </template>
                            <template v-else>
                              <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active3">{{ cIndex+1 }}</li>
                            </template>
                          </template>
                          <template v-else>
                            <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active3">{{ cIndex+1 }}</li>
                          </template>
                            <!-- <li @click="go(cItem.id)" :data-id="cItem.id" v-else :key="cIndex" class="active3">{{ cIndex+1 }}</li> -->
                        </template>
                        <template v-else>
                          <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active3">{{ cIndex+1 }}</li>
                        </template>
                      </template>
                      <template v-else>
                        <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active3">{{ cIndex+1 }}</li>
                      </template>
                    </template>
                  </ul>
                </div>
              </template>
            </div>
          </div>
        </div>
        <div class="st-btn" v-if="title === '随堂测试'">
          <div class="btn" @click="go(0)">全部解析</div>
          <div class="btn" @click="go(-1)">错误解析</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Exam from '../action'
export default {
  name: 'ExamEnd',
  data() {
    return {
      questionType: {
        1: '单选题：',
        2: '多选题：',
        5: '案例题：',
        6: '判断题：'
      },
      ratio: 0,
      ratioNum: 0,
      questionsData: {
        questions: []
      },
      requestData: {},
      title: ''
    }
  },
  created() {
  },
  mounted() {
    if (this.$route.query.course_id) {
      this.$route.query.type === 1 || this.$route.query.type === '1' ? this.title = '随堂测试' : this.title = '知识点测试'
    } else {
      this.$route.query.type === 1 || this.$route.query.type === '1' ? this.title = '能力自测' : this.title = '模拟考试'
    }
    // this.title
    this.initData()
  },
  methods: {
    go(id) {
      const param = this.$route.query
      param.id = id
      this.$emit('cardChange', param)
    },
    initData() {
      const param = this.$route.query
      Exam.getExam(param, param.papersUrl).then(res => {
        this.questionsData = res
        this.requestData = res.answers
        const count = this.questionsData.score / this.questionsData.total_score
        this.ratio = `${count * 158} 158`
        this.ratioNum = parseInt(count * 100)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.end_box{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 9999999;
  background: #fff;
}
.head{
  color: #222;
  display: flex;
  padding: .4rem 0;
  align-items: center;
  i{
    font-size: .35rem;
    margin-left: .28rem;
  }
  .title{
    margin-left: .03rem;
    font-size: .3rem;
  }
}
#bottom-view3{
  overflow: scroll;
}
.end_con{
  padding: .4rem 0.4rem 1rem .4rem;
  .cs_type{
    font-size: .3rem;
    color: #222;
    line-height: 100%;
    span{
      font-weight: bold;
    }
  }
  .cs_time{
    font-size: .3rem;
    color: #222;
    line-height: 100%;
    margin-top: .2rem;
    span{
      font-weight: bold;
    }
  }
  .charts{
    width: 3rem;
    height: 3rem;
    margin: .4rem auto;
    position: relative;
    svg{
      position: absolute;
      top: 50%;
      left: 50%;
      -webkit-transform: translate(-50%,-50%);
    }
    .w_svg{
      -webkit-transform:rotate(-90deg) translate(50%,-50%);
    }
    .circle{
      width: .96rem;
      height: .96rem;
      position: absolute;
      top: 50%;
      left: 50%;
      z-index: 999;
      -webkit-transform: translate(-50%,-50%);
      background: #FF8000;
      border-radius: 50%;
      text-align: center;
      .p1{
        font-size: .2rem;
        color: #fff;
        line-height: 100%;
        margin: 0.18rem 0 0.15rem 0;
        opacity: .7;
      }
      .p2{
        font-size: .26rem;
        color: #fff;
        line-height: 100%;
        font-weight: bold;
        margin: 0;
      }
    }
  }
  .assess{
    .tit{
      font-size: .3rem;
      color: #333;
      font-weight: bold;
    }
    img{
      width: 4rem;
      height: 1.93rem;
      display: block;
      margin: 0 auto;
    }
    .txt{
      font-weight: bold;
      font-size: .3rem;
      color: #333;
      text-align: center;
      margin-top: .18rem;
    }
  }
  .card{
    margin-top: .38rem;
    .tit{
      font-size: .3rem;
      color: #333;
      font-weight: bold;
    }
    .card_con{
      overflow-y: scroll;
      .flag{
        border-bottom: 0.01rem solid #EEEEEE;
        ul{
          list-style: none;
          margin: 0;
          padding: 0;
          display: flex;
          justify-content: center;
          li{
            margin: 0 .4rem 0.1rem .4rem;
            text-align: center;
            .circle{
              width: .6rem;
              height: .6rem;
              border-radius: 50%;
              font-size: .26rem;
              text-align: center;
              line-height: .6rem;
              color: #fff;
            }
            .active1{
              background: #67C23A;
            }
            .active2{
              background:#FA5555;
            }
            .active3{
              background:rgba(204,204,204,1);
            }
            .txt{
              color: #222222;
              font-size: .26rem;
              margin-top: 0.1rem;
            }
          }
        }
      }
      .question{
        .title{
          font-size: .3rem;
          color: #333333;
          margin-top: .1rem;
          margin-bottom: .4rem;
        }
        ul{
          list-style: none;
          margin: 0;
          padding: 0 0.6rem;
          border-bottom: 0.01rem solid #EEEEEE;
          display: flex;
          flex-wrap: wrap;
          li{
            width: .6rem;
            height: .6rem;
            border-radius: 50%;
            font-size: .26rem;
            text-align: center;
            line-height: .6rem;
            color: #fff;
            margin-right: .6rem;
            margin-bottom: .4rem;
          }
          :nth-child(5n+5){
            margin: 0;
          }
          .active1{
              background: #67C23A;
            }
          .active2{
            background:#FA5555;
          }
          .active3{
            background:rgba(204,204,204,1);
          }
        }
      }
    }
  }
}
.nl-btn{
  display: flex;
  margin-top: .3rem;
  .btn{
    width:3rem;
    height:.7rem;
    background:linear-gradient(90deg,rgba(43,124,233,1) 0%,rgba(103,168,255,1) 100%);
    border-radius:.12rem;
    font-size: .3rem;
    color: #fff;
    text-align: center;
    line-height: .7rem;
  }
  .btn:nth-child(2){
    margin-left: auto;
  }
}
.st-btn{
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  height: 1rem;
  background:rgba(255,255,255,1);
  box-shadow:0px 0px 6px 0px rgba(0,0,0,0.05);
  z-index: 99;
  display: flex;
  align-items: center;
  padding: 0 .4rem;
  .btn{width:3rem;
    height:.7rem;
    background:rgba(43,124,233,1);
    border-radius:.12rem;
    color: #fff;
    font-size: .3rem;
    text-align: center;
    line-height: .7rem;
  }
  .btn:nth-child(2){
    margin-left: auto;
  }
}
</style>
