<template>
  <view>
    <div class="content">
      <div class="tip">*随机抽题下每道分数根据管理员的设置可能不同，最高分以得分率计算（得分率=得分/总分*100%）</div>

      <div class="list-item" v-for="(item, index) in list" :key="index" @click="handleExamList(item)">
        <div class="title">{{ item.name }}</div>
        <div class="item-title">
          <div class="item-time">{{ item.endTime }}</div>
          <div class="item-tip" v-if="index == 0">最新</div>
          <div class="pass" :class="{ 'un-pass': item.isPass == '不通过' }">{{ item.isPass }}</div>
        </div>

        <div class="item-content">
          <div class="item">
            作答用时：
            <span class="item-info">{{ item.answerTime }}</span>
          </div>
          <div class="item">
            得分/总分：
            <span class="item-info">{{ item.score }}/{{ item.examGrade }}</span>
          </div>
          <div class="item">
            得分率：
            <span class="item-info">{{ item.gradeAverage }}</span>
          </div>
        </div>
      </div>

      <div class="all">已显示全部</div>
      <!-- 底部按钮 -->
      <!-- <div class="bottom-btn">
        <div class="btn">
          <u-button type="primary" size="small" shape="circle" text="重新考试" />
        </div>
      </div> -->
    </div>
  </view>
</template>

<script>
import { getExamRecordById } from '@/api/eduApp'

export default {
  data() {
    return {
      examId: '', // 考试id
      list: [
        {
          id: 1,
          // 时间
          time: '2023年04月27日 14:23',
          // 是否及格
          pass: false,
          // 作答用时
          answerTime: '30分钟',
          // 得分
          score: 60,
          // 总分
          totalScore: 100,
          // 得分率
          scoreRate: '60%'
        },
        {
          id: 2,
          // 时间
          time: '2023年04月27日 14:23',
          // 是否及格
          pass: true,
          // 作答用时
          answerTime: '30分钟',
          // 得分
          score: 60,
          // 总分
          totalScore: 100,
          // 得分率
          scoreRate: '60%'
        }
      ]
    }
  },
  onLoad(opt) {
    opt = JSON.parse(opt.params)
    this.examId = opt.examId
    this.getList()
  },
  methods: {
    // 获取列表
    async getList() {
      const params = {
        examId: this.examId,
        userId: uni.getStorageSync('userId'),
        page: 1,
        limit: 999
      }
      const res = await getExamRecordById(params)
      console.log('🚀 ~ getList ~ res:', res)
      this.list = res.data
    },
    // 处理考试列表
    handleExamList(item) {
      const params = {
        examId: this.examId,
        recordId: item.id
      }
      uni.navigateTo({
        url: '/pages/YNEduApp/exam/examinationResultDetails?params=' + JSON.stringify(params)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  padding: 10px;
  .tip {
    font-weight: 400;
    font-size: 11px;
    color: #8a8a8a;
    margin-bottom: 20px;
  }

  .list-item {
    width: calc(100% - 20px);
    height: 142px;
    background: #fff;
    box-shadow: 0px 3px 5px 0px rgba(231, 231, 231, 0.5);
    border-radius: 5px;
    margin-bottom: 10px;
    padding: 10px;

    .title {
      font-size: 16px;
      font-weight: bold;
    }

    .item-title {
      margin-top: 10px;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .item-time {
        font-size: 14px;
      }
      .item-tip {
        width: 40px;
        height: 23px;
        font-size: 12px;
        color: #fff;
        background: #1989fa;
        border-radius: 4px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .pass {
        font-size: 12px;
        color: #67c23a;
        &.un-pass {
          color: #f0514c;
        }
      }
    }

    .item-content {
      margin-top: 10px;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      font-size: 12px;
      color: #8a8a8a;

      .item {
        margin-bottom: 10px;
        .item-info {
          margin-bottom: 10px;
          color: #333;
        }
      }
    }
  }

  .all {
    margin: 40px auto;
    text-align: center;
    font-size: 13px;
    color: #8a8a8a;
  }
  .bottom-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #fff;
    padding: 10px 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;

    .btn {
      width: 100px;
      margin-right: 10px;
    }
  }
}
</style>
