scoresList.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. >
  10. <view>123</view>
  11. </view>
  12. <view v-if="!scoreList[0] && !scoreLoading" class="empty-tip">暂无考试记录</view>
  13. <view v-if="scoreLoading" class="loading-tip">加载中...</view>
  14. <view v-if="scoreNoMore && scoreList[0]" class="loading-tip">没有更多了</view>
  15. </scroll-view>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. parseTime
  21. } from '@/component/public.js'
  22. import {
  23. examElUserExamAttemptAttemptRecord,
  24. } from '@/pages_safetyEducationExamination/api/index.js'
  25. export default {
  26. data() {
  27. return {
  28. scoreList: [],
  29. scoreLoading: false,
  30. scorePage: 1,
  31. scorePageSize: 10,
  32. scoreTotal: 0,
  33. scoreNoMore: false,
  34. }
  35. },
  36. created() {
  37. },
  38. onShow() {
  39. },
  40. methods: {
  41. goToScoreDetail(){
  42. // 跳转答题详情,传递 attemptId / examId
  43. uni.navigateTo({
  44. url: `/pages_safetyEducationExamination/views/exam/scoreDetail?attemptId=${item.attemptId || ''}&examId=${item.examId || ''}`
  45. });
  46. },
  47. // 滚动到底部加载更多
  48. onScrollToLower() {
  49. this.loadScoreList();
  50. },
  51. // 考试列表(支持分页)
  52. async loadScoreList() {
  53. if (this.scoreLoading || this.scoreNoMore) return;
  54. this.scoreLoading = true;
  55. try {
  56. const obj = {
  57. page: this.scorePage,
  58. pageSize: this.scorePageSize,
  59. examId: '',
  60. };
  61. const { data } = await examElUserExamAttemptAttemptRecord(obj);
  62. if (data.code === 200) {
  63. for(let i=0;i<data.data.records.length;i++){
  64. data.data.records[i].startTime = parseTime(data.data.records[i].startTime, "{y}-{m}-{d}")
  65. }
  66. const records = data.data.records || [];
  67. const newList = this.scorePage === 1 ? records : [...this.scoreList, ...records];
  68. this.$set(this, 'scoreList', newList);
  69. this.scoreTotal = data.data.total;
  70. if (newList.length >= this.scoreTotal) {
  71. this.scoreNoMore = true;
  72. } else {
  73. this.scorePage++;
  74. }
  75. }
  76. } catch (e) {
  77. console.error('获取成绩列表失败', e);
  78. } finally {
  79. this.scoreLoading = false;
  80. }
  81. },
  82. }
  83. }
  84. </script>
  85. <style lang="stylus" scoped>
  86. .scoreList{
  87. height 100%
  88. display flex
  89. flex-direction column
  90. overflow hidden
  91. background-color #f0f4fb
  92. }
  93. </style>