<template>
  <view>
    <div class="result-box" v-if="score >= 90">
      <img class="img" :src="hege" />
      <span class="text">恭喜你,测试通过~</span>
      <div class="fraction-box">
        <span class="fraction">{{ score }}</span
        >分
      </div>
      <span class="hint">（满分:100；合格:90）</span>
      <span class="time">用时：{{ useTime }}</span>
      <span class="evaluation"
        >天赋异禀、骨骼惊奇，想来是百年难得一见的考试奇才。</span
      >
    </div>
    <div class="result-box" v-else>
      <img class="img" :src="buhege" />
      <span class="text">抱歉,测试未通过~</span>
      <div class="fraction-box">
        <span class="fraction">{{ score  }}</span
        >分
      </div>
      <span class="hint">（满分:100；合格:90）</span>
      <span class="time">用时：{{ useTime }}</span>
      <span class="evaluation"
        >学车之路，任重而道远！路漫漫其修远兮，吾将上下而求索。</span
      >
    </div>
    <div class="btn-box">
      <m-button
        width="270rpx"
        height="90rpx"
        @tap="goExerciseSpecify"
        class="btn1"
        text="错题重做"
      />
      <m-button
        width="270rpx"
        height="90rpx"
        @tap="refreshTest"
        class="btn2"
        text="重新测试"
      />
    </div>
  </view>
</template>
<script>

import api from "@/api/index";
import utils from "@/utils/index";
export default {
  data() {
    return {
      hege:"https://ct.zzxcx.net/ctjk/mp-wx/mockExamEnd/%E8%80%83%E8%AF%95%E5%90%88%E6%A0%BC.png",
      buhege:"https://ct.zzxcx.net/ctjk/mp-wx/mockExamEnd/%E8%80%83%E8%AF%95%E4%B8%8D%E5%90%88%E6%A0%BC.png",
      score: 0,
      useTime: "",
      subject: 1,
      query: {},
      gs: "",
      gsMap: {
        xc: "小车",
        hc: "货车",
        kc: "客车",
        mtc: "摩托车",
      },
    };
  },
  methods: {
    refreshTest() {
      let routes = getCurrentPages();
      if (routes.length < 2) {
        uni.showToast({
          title: "无法重新测试",
          icon: "fail",
        });
        return;
      }
      let prePage = routes[routes.length - 2];
      console.log(prePage);
      uni.redirectTo({
        url: decodeURIComponent(prePage.$page.fullPath),
      });
    },
    goExerciseSpecify() {
      if(!this.query.questionIds){
        uni.showToast({
          title:"没有错题",
          icon:"none"
        })
        return
      }
      uni.navigateTo({
        url:
          "/otherPages/exerciseSpecify/index?" +
          utils.mapToUrlQuery(this.query),
      });
    },
  },
  onLoad(query) {
    this.query = query;
    // console.log(getCurrentPages())
    this.score = query.score;
    this.useTime = query.useTime;
    this.subject = query.subject;
    this.gs = query.gs;
    if (query.type === "exam") {
      api.exam.studentScoreInfo({
        score: Number(this.score),
        kskm: this.subject == 1 ? "科目一" : "科目四",
        type: this.gsMap[this.gs],
      });
    }
  },
};
//提交考试成绩
//score=1&useTime=0%3A5&liceCar=1&liceTruck=&liceBus=&liceMoto=&name=%E7%A7%91%E7%9B%AE%E4%B8%80&gs=xc&cert=C1%2FC2%2FC3&vehicle=%E8%BD%BF%E8%BD%A6&subject=1&title=%E6%A8%A1%E6%8B%9F%E8%80%83%E8%AF%95&sort=3&__id__=3
// createTestScores({
// 	type: query.vehicle as string,
// 	kskm: query.name as string,
// 	score: props.userTestData.testScores,
// });
</script>

<style lang="scss" scoped>
.result-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60rpx 30rpx;
  .img {
    width: 246px;
    height: 216px;
  }
  .text {
    margin-top: 23px;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #5c6066;
    line-height: 23px;
  }
  .fraction-box {
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: bold;
    color: #8a9099;
    line-height: 23px;
    margin-top: 30px;
    .fraction {
      font-size: 60px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #ff4d53;
    }
  }
  .hint {
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #8a9099;
    line-height: 23px;
  }
  .time {
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #498ef5;
    line-height: 23px;
  }
  .evaluation {
    margin-top: 30px;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #5c6066;
    line-height: 23px;
  }
}
.btn-box {
  margin: 0 auto;
  width: 600rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #ffffff;
  font-size: 15px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 23px;
  .btn1 {
    background-color: #498ef5;
  }
  .btn2 {
    background-color: #01c18d;
  }
}
</style>
