<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">
            您本次模拟考试得{{ correctScore }}分。<span
              v-if="correctScore >= 90"
              >及格</span
            ><span v-else>不及格</span>，祝你下次
          </div>
          <div class="mid-line3" v-if="correctScore >= 90">再接再励</div>
          <div class="mid-line3" v-else>考试成功</div>
        </div>
        <div class="bottom">
          <button
            @click="
              () => {
                back();
              }
            "
          >
            关闭
          </button>
          <div class="bottom-line">页面将在{{ time }}s内返回</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      time: 8,
      option: {},
    };
  },
  methods: {
    back() {
      let page = getCurrentPages()[0];
      let params = page.$page.fullPath.split("?")[1];
      uni.navigateTo({
        url: `/pages/mockExam/begin?${params}`,
      });
    },
  },
  // 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,
  //   };
  // },
  destroyed() {
    window.clearInterval(this.timer);
  },
  mounted() {
    const timer = setInterval((e) => {
      this.time = this.time - 1;
      let str;
      if (this.time === 0) {
        clearInterval(timer);
        let page = getCurrentPages()[0];
        console.log(page, "page");
        let params = page.$page.fullPath.split("?")[1];
        console.log(params);
        uni.navigateTo({
          url: `/pages/mockExam/begin?${params}`,
        });
        // backView()
        // router.push({
        //   name: "examBegin",
        //   query: {
        //     ...router.currentRoute.value.query,
        //   },
        // });
      }
    }, 1000);
  },
  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: 750rpx;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.65);
  z-index: 10;
  display: flex;
  align-content: center;
  align-items: center;
  justify-content: center;
  .dialog {
    width: 400rpx;
    height: 205rpx;
    background: #fff;
    .title {
      width: 100%;
      line-height: 40rpx;
      height: 40rpx;
      background: #306ace;
      color: #fff;
      font-size: 12rpx;
      text-align: center;
    }
    .mid {
      width: 100%;
      background: #fff;
      height: 100rpx;
      padding-left: 10rpx;
      padding-right: 10rpx;
      font-size: 14rpx;
      .mid-line1 {
        line-height: 25rpx;
        height: 25rpx;
        text-align: left;
      }
      .mid-line2 {
        text-align: left;
        line-height: 30rpx;
      }
      .mid-line3 {
        text-align: left;
        line-height: 30rpx;
      }
      .mid-line4 {
        text-align: left;
        line-height: 30rpx;
      }
    }
    .bottom {
      background: #306ace;
      width: 100%;
      height: 70rpx;
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      align-items: flex-start;
      align-content: flex-start;

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