<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>{{ item.title }}</li>
              </ul>
            </div>
            <span v-if="item.batch==0">- -</span>

            <span v-else-if="item.iscorrect==0">待批卷</span>
            <span v-else-if="item.is_publish==0">待公布</span>
            <span v-else>{{item.sumscore}}分</span>
          </div>
          <div class="examRecord-box_bottom">
            <div class="examRecord-box_type">
              练习时间：{{
              Math.floor(item.time / 3600) >= 10
              ? Math.floor(item.time / 60)
              : "0" + Math.floor(item.time / 60)
              }}:{{
              Math.floor(item.time / 60) >= 10
              ? Math.floor(item.time / 60)
              : "0" + Math.floor(item.time / 60)
              }}:{{
              item.time % 60 >= 10 ? item.time % 60 : "0" + (item.time % 60)
              }}
            </div>
            <div class="examRecord-box_method">
              <div
                class="examRecord-box_see"
                v-if="item.is_delrecord == 1"
                style="margin-right:10px;"
                @click="delrecord(item.id)"
              >删除记录</div>
              <router-link
                class="examRecord-box_see"
                v-if="item.show_analysis&&item.batch==1"
                style="margin-right: 10px;"
                :to="{
                name: 'analysis',
                query: {
                  id: item.id,
                  type: 1,
                  paperid: item.paperid,
                  categoryid: $route.query.categoryid,
                  title: item.title
                }
              }"
                tag="div"
              >查看解析</router-link>
              <router-link
                v-if="item.is_repractice!=0"
                class="examRecord-box_see"
                :to="{
                name: 'PaperInfo',
                query: {
                  paperid: item.paperid,
                  categoryid: $route.query.categoryid
                }
              }"
                tag="div"
              >{{item.is_repractice==2?'继续练习':'重新练习'}}</router-link>
            </div>
          </div>
        </div>
      </div>
      <!-- 无数据提示 -->
      <Nodata v-if="showNodata" />
    </div>
  </ks-page-scroll-container>
</template>

<script>
import { GetPaperRecordList, DeletePaperRecord } from "@/api/user";
export default {
  name: "ExamRecord",
  data() {
    return {
      showList: true,
      showNodata: false,
      value: "",
      allData: [],
      pageCount: 0,
      page: 0,
      loading:false
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSearch(value) {
      this.value = value;
      this.getPaperRecordList();
    },
    delrecord: function(id) {
      //删除考试记录
      var that = this;
      DeletePaperRecord({
        ids: id,
        categoryid: this.$route.query.categoryid
      }).then(function(res) {
        that.allData = [];
        that.getPaperRecordList();
      });
    },
    getPaperRecordList(p = 1) {
      if(this.loading){
        return
      }
      this.loading = true;
      GetPaperRecordList({
        categoryid: this.$route.query.categoryid,
        page: p,
        pagesize: 10,
        key: this.value
      }).then(res => {
        if (res.result == true) {
          this.allData = this.allData.concat(res.data);
          this.pageCount = res.pagecount;
          this.page = p;
          this.showList = true;
          this.showNodata = false;
        } else {
          this.showList = false;
          this.showNodata = true;
          this.page = 0;
          this.pageCount = 0;
        }
        this.loading = false
      });
    }
  },
  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;
}

/* 考试记录列表 */
.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: 40%;
  font-size: 10px;
  font-family: PingFangSC-Light;
  font-weight: 300;
  color: #999;
  display: flex;
  justify-content: space-between;
}
.examRecord-box_method {
  display: flex;
  justify-content: flex-end;
}
.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>
