<template>
  <div class="end_box">
    <div class="head" id="top-view3">
      <i class="el-icon-arrow-left"></i>
      <div class="title">成绩报告</div>
    </div>
    <div id="bottom-view3">
      <div class="end_con">
        <div class="cs_type"><span>测试内容：</span>能力自测</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="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>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      questionType: {
        1: '单选题：',
        2: '多选题：',
        5: '案例题：',
        6: '判断题：'
      },
      ratio: 0,
      ratioNum: 0
    }
  },
  props: {
    questionsData: {
      type: Object,
      default () {
        return {}
      }
    },
    requestData: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  methods: {
    go(id) {
      this.$emit('cardChange', id)
    },
    scrollDom() {
      const topViewH = document.getElementById('top-view3').offsetHeight
      const clientHeight = document.documentElement.clientHeight
      const bottomView = document.getElementById('bottom-view3')
      bottomView.style.height = (clientHeight - topViewH) + 'px'
      console.log(bottomView.style.height)
    }
  },
  created() {
    const count = this.questionsData.score / this.questionsData.total_score
    this.ratio = `${count * 158} 158`
    this.ratioNum = parseInt(count * 100)
    console.log(this.questionsData.score, this.questionsData.total_score)
    console.log(this.ratio)
  },
  mounted() {
    this.scrollDom()
  }
}
</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: 0 .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);
          }
        }
      }
    }
  }
}
</style>
