<template>
  <div class="comp-x">
    <div class="mock-box">
      <div class="top-tit">
        <div class="left">考试时间：90分钟</div>
        <!-- <div class="right">总分100分</div> -->
      </div>
      <div class="top-tit">
        <div class="left">考试通过：80分</div>
        <div class="right">总分：100分</div>
      </div>
      <div class="top-tit">
        <div class="left new-w">试题类型：</div>
        <div class="txt">单项选择题、多项选择题、判断题和
  案例题，全部为客观题</div>
      </div>
      <div class="intr">考试说明：</div>
      <div class="answer-type">
        <div class="tit">1.模考目的：</div>
        <div class="type">
          <p>考核道路运输企业主要负责人和安全生产管理人员对安全生产管理知识掌握程度</p>
          <!-- <p>单选题共1题</p>
          <p>单选题共1题</p> -->
        </div>
      </div>
      <div class="answer-type">
        <div class="tit">2.考核范围：</div>
        <div class="type">
          <p>道路运输安全生产相关法律法规及标准规范、道路运输企业安全生产主体责任、道路运输企业安全管理知识、道路运输安全生产务实务等内容</p>
          <!-- <p>单选题共1题</p>
          <p>单选题共1题</p> -->
        </div>
      </div>
      <div class="answer-type">
        <div class="tit">3.模考试卷：</div>
        <div class="type">
          <p>道路运输安全生产相关法律法规及标准规范、道路运输企业安全生产主体责任、道路运输企业安全管理知识、道路运输安全生产务实务等内容</p>
          <!-- <p>单选题共1题</p>
          <p>单选题共1题</p> -->
        </div>
      </div>
      <div class="role-tit">选择角色：</div>
      <div class="describe">请认真选择角色，选定后,模拟考试题型会针对角色为您匹配最准确的题型！</div>
      <div class="sele-role">
        <div @click="changeActive(1)" :class="roleChange == 1 ? 'btn active' : 'btn'">
          <i></i>
          <div class="txt">管理人员</div>
        </div>
        <div @click="changeActive(2)" :class="roleChange == 2 ? 'btn active' : 'btn'">
          <i></i>
          <div class="txt">安全人员</div>
        </div>
      </div>
      <div class="new-btit">试卷组卷比例见下表：</div>
      <img src="../../assets/images/table.png" alt="" class="table">
      <div class="start-exam">
        <div class="b" @click="setRole">开始考试</div>
      </div>
      <div class="exam_submit" v-if="isExamPop">
        <div class="pop">
          <div class="tit">模拟考试</div>
          <div class="txt">您上次未做完试题</div>
          <div class="btn_box">
            <div class="btn" @click="goAbilityExam(1)">重新答题</div>
            <div class="btn btn2" @click="goAbilityExam(0)">继续答题</div>
          </div>
        </div>
      </div>
      <div class="exam_submit" v-if="isExamPopTo">
        <div class="pop">
          <div class="tit">模拟考试</div>
          <div class="txt">考试还未结束确定退出考试？</div>
          <div class="btn_box">
            <div class="btn" @click="isExamPopTo = false">退出考试</div>
            <div class="btn btn2" @click="goAbilityExam(0)">继续考试</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as api from '@/api/courseExam.js'
export default {
  metaInfo () {
    return {
      title: '模拟考试'
    }
  },
  data() {
    return {
      roleChange: 1,
      isExamPop: false,
      isExamPopTo: false
    }
  },
  mounted() {
    const userRole = parseInt(this.$store.state.user.student_info.role)
    if (userRole !== 0) {
      this.roleChange = userRole
    }
    if (window.localStorage.isExamEnd === 'true' || window.localStorage.isExamEnd === true) {
      this.abilityExam()
    }
  },
  methods: {
    changeActive(e) {
      this.roleChange = e
    },
    abilityExam() {
      const param = {
        type: 2
      }
      api.getExamStatus(param).then(res => {
        if (parseInt(res.status) === 0 || parseInt(res.status) === 3) {
          this.isExamPopTo = true
        }
      })
    },
    goAbilityExam(n) {
      window.localStorage.isExamEnd = true
      this.$router.push({
        path: '/mock/answer',
        query: {
          type: 2,
          is_create: n,
          papersUrl: 'zy/v2/examination/examination-papers'
        }
      })
    },
    setRole() {
      const param = {
        type: 2
      }
      api.setRole({ role: this.roleChange }).then(res => {
        if (res.code === 0) {
          api.getExamStatus(param).then(res => {
            if (res.status === '0' || res.status === 0 || res.status === '3' || res.status === 3) {
              this.isExamPop = true
            } else {
              this.goAbilityExam(1)
            }
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.comp-x{
  padding-bottom: env(safe-area-inset-bottom);
}
.mock-box{
  padding: 0 0.4rem 1rem 0.4rem;
}
.top-tit{
  padding-top: .3rem;
  // border-bottom: 0.01rem solid #EEE;
  display: flex;
  // line-height: 1.1rem;
  div{
    font-weight: bold;
    font-size: .3rem;
    color: #222;
    line-height: 100%;
  }
  .new-w{
    width: 2.5rem;
  }
  .txt{
    font-weight: normal;
    line-height: .4rem;
  }
  .right{
    margin-left: auto;
  }
}
.intr{
  line-height: .6rem;
  font-weight: bold;
  font-size: .3rem;
  color: #222;
}
.answer-type{
  padding-bottom: .2rem;
  display: flex;
  .tit{
    font-size: .26rem;
    color: #222;
    line-height: .4rem;
  }
  p{
    line-height: 100%;
    font-size: .26rem;
    color: #222;
    line-height: .4rem;
    width: 5rem;
    // font-weight: bold;
    // margin-bottom: .2rem;
  }
}
.role-tit{
  line-height: 100%;
  font-size: .3rem;
  color: #222;
  font-weight: bold;
  margin: .4rem 0 .18rem 0;
}
.describe{
  font-size: .26rem;
  color: #222;
}
.sele-role{
  width: 5.09rem;
  margin: .4rem auto 0 auto;
  display: flex;
  .btn:nth-child(2){
    margin-left: auto;
  }
  .btn{
    width: 1.76rem;
    height: .8rem;
    border: 0.01rem solid #3a7be6;
    display: flex;
    justify-content: center;
    border-radius: .1rem;
    align-items: center;
    .txt{
      font-size: .26rem;
      color: #222;
      font-weight: bold;
    }
    i{
      width: .28rem;
      height: .28rem;
      margin-right: .1rem;
      background: url('../../assets/images/radio2.png');
      background-size: 100% 100%;
    }
  }
  .btn.active{
    background:#3a7be6;
    .txt{
      color: #fff;
    }
    i{
      background: url('../../assets/images/radio.png');
      background-size: 100% 100%;
    }
  }
}
.start-exam{
  position: fixed;
  bottom: 0;
  left: 0;
  width:7.5rem;
  height:1rem;
  background:rgba(255,255,255,1);
  box-shadow:0 0 .06 0px rgba(0,0,0,0.05);
  padding-bottom: env(safe-area-inset-bottom);
  .b{
    width:6.7rem;
    height:.7rem;
    background:#FF6767;
    border-radius:.12rem;
    margin: .15rem auto;
    text-align: center;
    line-height: .7rem;
    color: #fff;
    font-size: .3rem;
  }
}
.exam_submit{
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999999;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  .pop{
    width: 5.9rem;
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%,-50%);
    background:rgba(255,255,255,1);
    border-radius:.12rem;
    padding: 0.4rem 0;
    .tit{
      font-weight:bold;
      color:rgba(34,34,34,1);
      font-size:.3rem;
      text-align: center;
      line-height: 100%;
    }
    .txt{
      color:rgba(34,34,34,1);
      font-size:.3rem;
      text-align: center;
      line-height: 100%;
      margin-top: .8rem;
    }
    .btn_box{
      padding:0 0.2rem;
      display: flex;
      margin-top: .8rem;
      .btn{
        width:2.6rem;
        height:.7rem;
        background:rgba(43,124,233,1);
        border-radius:.12rem;
        text-align: center;
        line-height: .7rem;
        color: #fff;
        font-size: .3rem;
      }
      .btn2{
        margin-left: auto;
      }
    }
  }
}
.new-btit{
  font-size: .3rem;
  color: #222;
  line-height: 100%;
  margin-top: .4rem;
  font-weight: bold;
}
.table{
  width: 6.79rem;
  margin: 0.2rem auto;
  display: block;
}
</style>
