scoresList.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="scoreList">
  3. <scroll-view scroll-y class="scroll-content" @scrolltolower="onScrollToLower">
  4. <view
  5. v-for="(item, index) in scoreList"
  6. :key="index"
  7. class="score-card"
  8. @click="goToScoreDetail(item)">
  9. <view class="left-box">
  10. <view>考试时间:{{item.startTime}}</view>
  11. <view>得分:{{item.totalScore}}</view>
  12. <view>及格分:{{item.passScore}}</view>
  13. </view>
  14. <view class="right-box" :class="item.passStatus ==0?'colorA':'colorB'">{{item.passStatus ==0?'未通过':'通过'}}</view>
  15. </view>
  16. <view v-if="!scoreList[0] && !scoreLoading" class="empty-tip">暂无考试记录</view>
  17. <view v-if="scoreLoading" class="loading-tip">加载中...</view>
  18. <view v-if="scoreNoMore && scoreList[0]" class="loading-tip">没有更多了</view>
  19. </scroll-view>
  20. </view>
  21. </template>
  22. <script>
  23. import {
  24. parseTime
  25. } from '@/component/public.js'
  26. import {
  27. examElUserExamAttemptAttemptRecord,
  28. } from '@/pages_safetyEducationExamination/api/index.js'
  29. export default {
  30. data() {
  31. return {
  32. scoreList: [],
  33. scoreLoading: false,
  34. scorePage: 1,
  35. scorePageSize: 10,
  36. scoreTotal: 0,
  37. scoreNoMore: false,
  38. examId:'',
  39. }
  40. },
  41. created() {
  42. },
  43. onLoad(options){
  44. this.$set(this,'examId',options.examId);
  45. },
  46. onShow() {
  47. this.loadScoreList();
  48. },
  49. methods: {
  50. goToScoreDetail(item){
  51. // 跳转答题详情,传递 attemptId / examId
  52. uni.navigateTo({
  53. url: `/pages_safetyEducationExamination/views/exam/scoreDetail?attemptId=${item.attemptId || ''}&examId=${item.examId || ''}`
  54. });
  55. },
  56. // 滚动到底部加载更多
  57. onScrollToLower() {
  58. this.loadScoreList();
  59. },
  60. // 考试列表(支持分页)
  61. async loadScoreList() {
  62. if (this.scoreLoading || this.scoreNoMore) return;
  63. this.scoreLoading = true;
  64. try {
  65. const obj = {
  66. page: this.scorePage,
  67. pageSize: this.scorePageSize,
  68. examId: this.examId,
  69. };
  70. const { data } = await examElUserExamAttemptAttemptRecord(obj);
  71. if (data.code === 200) {
  72. for(let i=0;i<data.data.records.length;i++){
  73. data.data.records[i].startTime = parseTime(data.data.records[i].startTime, "{y}-{m}-{d}")
  74. }
  75. const records = data.data.records || [];
  76. const newList = this.scorePage === 1 ? records : [...this.scoreList, ...records];
  77. this.$set(this, 'scoreList', newList);
  78. this.scoreTotal = data.data.total;
  79. if (newList.length >= this.scoreTotal) {
  80. this.scoreNoMore = true;
  81. } else {
  82. this.scorePage++;
  83. }
  84. }
  85. } catch (e) {
  86. console.error('获取成绩列表失败', e);
  87. } finally {
  88. this.scoreLoading = false;
  89. }
  90. },
  91. }
  92. }
  93. </script>
  94. <style lang="stylus" scoped>
  95. .scoreList{
  96. height: 100%;
  97. display: flex;
  98. flex-direction: column;
  99. overflow: hidden;
  100. background-color: #f0f4fb;
  101. .scroll-content{
  102. height:100%;
  103. }
  104. .score-card{
  105. margin:28rpx 28rpx 0;
  106. background-color: #fff;
  107. border-radius:10rpx;
  108. padding:20rpx;
  109. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  110. border: 1rpx solid #dde3ed;
  111. display: flex;
  112. font-size:28rpx;
  113. .left-box{
  114. flex:1;
  115. }
  116. .right-box{
  117. line-height:110rpx;
  118. margin-right:20rpx;
  119. }
  120. .colorA{
  121. color:#f5222d;
  122. }
  123. .colorB{
  124. color:#52c41a;
  125. }
  126. }
  127. .empty-tip{
  128. text-align: center;
  129. line-height: 100rpx;
  130. color: #aaa;
  131. font-size: 24rpx;
  132. }
  133. .loading-tip{
  134. text-align: center;
  135. line-height: 100rpx;
  136. color: #aaa;
  137. font-size: 22rpx;
  138. }
  139. }
  140. </style>