<template>
  <div class="mask">
    <div>
      <div class="dialog">
        <div class="title">
          <span>信息提示</span>
        </div>
        <div class="mid">
          <div class="mid-line1">亲爱的考生：</div>
          <div class="mid-line2">
            您本次模拟考试得{{ score }}分。<span v-if="score >= 90">及格</span
            ><span v-else>不及格</span>，祝你下次
          </div>
          <div class="mid-line3" v-if="score >= 90">再接再励</div>
          <div class="mid-line3" v-else>考试成功</div>
        </div>
        <div class="bottom">
          <button
            @click="
              () => {
                router.push({
                  name: 'examBegin',
                  query: {
                    ...router.currentRoute.value.query,
                  },
                });
              }
            "
          >
            关闭
          </button>
          <div class="bottom-line">页面将在{{ time }}s内返回</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineProps, reactive, toRefs, ref } from 'vue';
import router from '@/router/';
import Phone from '@/utils/phone';

export default {
  setup(props, { emit }) {
    const state = reactive({
      count: 0,
    });
    
    const phone = new Phone();
    const backView = phone.backView.bind(phone);
    const time = ref(8);
    const timer = window.setInterval((e) => {
      time.value = time.value - 1;
      if (time.value === 0) {
        window.clearInterval(timer);
        // backView()
        router.push({
          name: 'examBegin',
          query: {
            ...router.currentRoute.value.query,
          },
        });
      }
    }, 1000);
    const sendPaper = () => {
      emit('confirm');
    };
    const cancelSubmit = () => {
      emit('cancel');
    };

    return {
      ...toRefs(state),
      props,
      sendPaper,
      cancelSubmit,
      time,
      timer,
      router,
      backView,
    };
  },
  beforeUnmount() {
    window.clearInterval(this.timer);
  },
  computed: {
    score() {
      console.log(router.currentRoute.value.query)
      if (router.currentRoute.value.query.subject == "4") {
        return this.correctScore * 2;
      }
      return  this.correctScore;
    },
  },
  props: {
    correctScore: {
      type: Number,
      required: true,
      default: 0,
    },
  },
};
</script>

<style lang="scss" scoped>
button {
  border-radius: 0;
  border: none;
}
.mask {
  position: fixed;
  top: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgb(0, 0, 0, 0.65);
  z-index: 10;
  display: flex;
  align-content: center;
  align-items: center;
  justify-content: center;
  .dialog {
    width: 400px;
    height: 205px;
    background: #fff;
    .title {
      width: 100%;
      line-height: 40px;
      height: 40px;
      background: #306ace;
      color: #fff;
      font-size: 12px;
    }
    .mid {
      width: 100%;
      background: #fff;
      height: 100px;
      padding-left: 10px;
      padding-right: 10px;
      font-size: 14px;
      .mid-line1 {
        line-height: 25px;
        height: 25px;
        text-align: left;
      }
      .mid-line2 {
        text-align: left;
        line-height: 30px;
      }
      .mid-line3 {
        text-align: left;
        line-height: 30px;
      }
      .mid-line4 {
        text-align: left;
        line-height: 30px;
      }
    }
    .bottom {
      background: #306ace;
      width: 100%;
      height: 70px;
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      align-items: flex-start;
      align-content: flex-start;

      button:nth-child(1) {
        height: 30px;
        margin-top: 10px;
      }
      .bottom-line {
        width: 100%;
        text-align: center;
        color: #fff;
        font-size: 12px;
        margin-top: 5px;
      }
      button:nth-child(2) {
        height: 30px;
      }
    }
  }
}
</style>