scoresList.vue 2.0 KB

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