<template>
  <ks-page-scroll-container :page="page" :page-count="pageCount" @page-change="getPaperRecordList">
    <div class="contianer">
      <!-- 头部标题 -->
      <van-nav-bar title="练习记录" left-arrow @click-left="onClickLeft()" />
      <!-- 间距 -->
      <div class="margin20"></div>
      <!-- 顶部搜索框 -->
      <div class="examRecord-top">
        <div class="examRecord-top_search">
          <van-search v-model="value" placeholder="请输入搜索关键词" shape="round" @search="onSearch"></van-search>
        </div>
      </div>
      <!-- 考试记录列表 -->
      <div class="examRecord-item" v-if="showList">
        <div class="examRecord-box" v-for="(item, i) in allData" :key="i">
          <div class="examRecord-box_top">
            <div class="examRecord-box_title">
              <ul>
                <li>{{title}}</li>
              </ul>
            </div>
            <span>总{{item.tk_num}}题/对{{item.tk_num-item.error_num}}题</span>
            
          </div>
          <div class="examRecord-box_bottom">
            <div class="examRecord-box_type">
                <div>
                    <span>练习时间：{{item.adddate_mm}}</span>
                    <span class="ml15">
                    用时：{{
                    Math.floor(item.exam_time / 3600) >= 10
                    ? Math.floor(item.exam_time / 60)
                    : "0" + Math.floor(item.exam_time / 60)
                    }}:{{
                    Math.floor(item.exam_time / 60) >= 10
                    ? Math.floor(item.exam_time / 60)
                    : "0" + Math.floor(item.exam_time / 60)
                    }}:{{
                    item.exam_time % 60 >= 10 ? item.exam_time % 60 : "0" + (item.exam_time % 60)
                    }}
                    </span>
                </div>
  
            </div>
            <router-link
              class="examRecord-box_see"
              v-if="item.show_analysis"
              style="margin-right: 10px;"
              :to="{
                name: 'ExamResult',
                query: {
                    id: item.id,
                    type: 2,
                    paperid: $route.query.typeid,
                    typeid:$route.query.typeid,
                    categoryid:0
                }
              }"
              tag="div"
            >查看解析</router-link>
            <!-- <router-link
              class="examRecord-box_see"
              :to="{
                name: 'PaperInfo',
                query: {
                  paperid: item.paperid,
                  categoryid: $route.query.categoryid
                }
              }"
              tag="div"
            >重新练习</router-link> -->
          </div>
        </div>
      </div>
      <!-- 无数据提示 -->
      <Nodata v-if="showNodata" />
    </div>
  </ks-page-scroll-container>
</template>

<script>
import { GetTestRecordList } from "@/api/exam";
export default {
  name: "ExamRecord",
  data() {
    return {
      showList: true,
      showNodata: false,
      value: "",
      allData: [],
      pageCount: 0,
      page: 0,
      title:''
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSearch(value) {
      this.value = value;
      this.getPaperRecordList();
    },
    getPaperRecordList(p = 1) {
      GetTestRecordList({
        courseid:this.$route.query.courseid,
        typeid:this.$route.query.typeid,
        page: p,
        pagesize: 10,
        key: this.value
      }).then(res => {
        if (res.result == true) {
            this.title = res.periodname+'练习记录'
            this.allData = this.allData.concat(res.data);
            this.pageCount = res.pagecount;
            this.page = p;
            this.showList = true;
            this.showNodata = false;
        } else {
            this.title = '练习记录'
            this.showList = false;
            this.showNodata = true;
            this.page = 0;
            this.pageCount = 0;
        }
        document.title = this.title
      });
    }
  },
  activated() {
    this.allData = [];
    document.title = "练习记录";
    this.getPaperRecordList();
  }
};
</script>

<style scoped>
.van-icon-arrow-left {
  color: #4d4c4c !important;
}
.contianer {
  width: 100%;
  min-height: 100vh;
  background: #fff;
}
/* 间距 */
.margin20 {
  width: 100%;
  height: 0.5rem;
  background: #f5f5f5;
}
.ml15{
    margin-left: 15px;
}
/* 考试记录列表 */
.examRecord-item {
  width: 90%;
  margin: 0 auto;
  background: #fff;
}
.examRecord-box {
  margin-bottom: 13px;
  border-bottom: 1px solid #ebedef;
}
.examRecord-box_top {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
}
.examRecord-box_top span {
  font-size: 14px;
  color: #ff795c;
}
.examRecord-box_title {
  width: 75%;
  font-size: 14px;
  color: #333;
  float: left;
}
.examRecord-box_title ul li {
  list-style: disc inside none;
}
.examRecord-box_top span {
  width: 25%;
  float: right;
  text-align: right;
}
.examRecord-box_bottom {
  margin-top: 6px;
  width: 100%;
  height: 32px;
  display: flex;
  justify-content: space-between;
}
.examRecord-box_type {
  width: 75%;
  font-size: 10px;
  font-family: PingFangSC-Light;
  font-weight: 300;
  color: #999;
  display: flex;
  justify-content: space-between;
}
.examRecord-box_see {
  font-size: 12px;
  color: #fff;
  width: 65px;
  height: 20px;
  border-radius: 10px;
  background: #ff795c;
  text-align: center;
  line-height: 20px;
}
.type-flex {
  display: flex;
}
</style>
