<template>
  <ks-page-scroll-container :page="page" :page-count="pageCount" @page-change="getTestRecordList">
    <div class="practiceRecord">
      <!-- 头部标题 -->
      <van-nav-bar title="练习记录" left-arrow @click-left="onClickLeft()" />
      <!-- 间距 -->
      <div class="margin20"></div>
      <!-- 顶部搜索框 -->
      <div class="practiceRecord-top">
        <!-- <div class="practiceRecord-top_search">
          <van-search v-model="value" placeholder="请输入搜索关键词" shape="round" @search="onSearch"></van-search>
        </div>-->
      </div>
      <!-- 练习记录列表 -->
      <div class="practiceRecord-item" v-if="showList">
        <div class="practiceRecord-box" v-for="(item, i) in allData" :key="i">
          <div class="practiceRecord-box_top">
            <div class="practiceRecord-box_title">
              <ul>
                <li>{{ item.title }}</li>
              </ul>
            </div>
            <span>正确率：{{ item.zhunquelv }}%</span>
          </div>
          <div class="practiceRecord-box_bottom">
            <div class="practiceRecord-box_type">
              <div>
                练习时间：{{
                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)
                }}
              </div>
              <div class="type-flex">练习类型：{{ item.type_name }}</div>
            </div>
            <div
              class="practiceRecord-box_see"
              @click="
                viewAnalysis(item.id, item.type, item.categoryid, item.title)
              "
              v-if="item.show_analysis"
            >查看详情</div>
          </div>
        </div>
      </div>
      <!-- 无数据提示 -->
      <Nodata v-if="showNodata" />
    </div>
  </ks-page-scroll-container>
</template>

<script>
import { GetTestRecordList } from "@/api/user";
export default {
  name: "PracticeRecord",
  data() {
    return {
      value: null,
      allData: [],
      pageCount: 0,
      page: 0,
      showList: true,
      showNodata: false,
      loading:false
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSearch() {},
    getTestRecordList(p = 1) {
      
      if(this.loading){
        return
      }
      this.loading = true;
      GetTestRecordList({
        categoryid: this.$route.query.categoryid,
        page: p,
        pagesize: 10
      }).then(res => {
        if (res.result == true) {
          this.allData = this.allData.concat(res.data);
          this.page = p;
          this.pageCount = res.pagecount;
          this.showList = true;
          this.showNodata = false;
        } else {
          this.showList = false;
          this.showNodata = true;
          this.page = 0;
          this.pageCount = 0;
        }
        this.loading = false
      });
    },
    viewAnalysis(id, type, categoryid, title) {
      this.$router.push({
        path: "/exam/analysis",
        query: {
          id: id,
          type: 2,
          paperid: 0,
          categoryid: categoryid,
          title: title
        }
      });
    }
  },
  activated() {
    this.allData = [];
    document.title = "练习记录";
    this.getTestRecordList();
  }
};
</script>

<style scoped>
.van-icon-arrow-left {
  color: #4d4c4c !important;
}
.practiceRecord {
  width: 100%;
  min-height: 100vh;
  background: #fff;
}
/* 间距 */
.margin20 {
  width: 100%;
  height: 10px;
  background: #f5f5f5;
}

/* 练习记录列表 */
.practiceRecord-item {
  width: 90%;
  margin: 0 auto;
  background: #fff;
}
.practiceRecord-box {
  margin-bottom: 13px;
  border-bottom: 1px solid #ebedef;
}
.practiceRecord-box_top {
  margin-top: 3px;
  width: 100%;
  min-height: 16px;
}
.practiceRecord-box_title {
  width: 75%;
  font-size: 14px;
  color: #333;
  float: left;
}
.practiceRecord-box_title ul li {
  list-style: disc inside none;
}
.practiceRecord-box_top span {
  width: 25%;
  float: right;
  text-align: right;
}
.practiceRecord-box_bottom {
  margin-top: 6px;
  width: 100%;
  height: 32px;
  display: flex;
  justify-content: space-between;
}

.practiceRecord-box_type {
  width: 75%;
  font-size: 10px;
  color: #999;
  display: flex;
  justify-content: space-between;
}
.practiceRecord-box_see {
  font-size: 11px;
  color: #fff;
  width: 58px;
  height: 18px;
  border-radius: 9px;
  background: #ff795c;
  text-align: center;
  line-height: 18px;
}
.type-flex {
  display: flex;
}
</style>
