index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="container">
  3. <uni-list>
  4. <uni-list-item v-for="(item, index) in list" :key="index">
  5. <!-- 自定义 header -->
  6. <template v-slot:header>
  7. <view class="slot-box">
  8. <image class="slot-image" :src=" item.image"></image>
  9. <text class="status">{{ item.statusText }}</text>
  10. </view>
  11. </template>
  12. <!-- 自定义 body -->
  13. <template v-slot:body>
  14. <view class="slot-body">
  15. <view class="slot-box slot-title">{{ item.topic }}</view>
  16. <view class="slot-box slot-text">人数限制: {{ item.regMaxCount }}人</view>
  17. </view>
  18. </template>
  19. <!-- 自定义 footer-->
  20. <template v-slot:footer>
  21. <view class="slot-footer">
  22. <uni-icons class="footerIcon" type="forward" size="35" @click="btn(item)"></uni-icons>
  23. </view>
  24. </template>
  25. </uni-list-item>
  26. </uni-list>
  27. <uni-load-more :status="more" />
  28. </view>
  29. </template>
  30. <script>
  31. import request from '../../api/activity.js';
  32. import { BASE_URL } from '../../env.js';
  33. export default {
  34. data() {
  35. return {
  36. list: [],
  37. more: 'more',
  38. page: 0,
  39. size: 12,
  40. }
  41. },
  42. mounted() {
  43. this.query();
  44. },
  45. methods: {
  46. async query() {
  47. this.page += 1;
  48. this.more = 'loading';
  49. const res = await request.getActivity({ pageNum: this.page, pageSize: this.size });
  50. res.rows?.map(e => {
  51. if (e.status == 0) e.statusText = '未开始';
  52. // if (e.status == 1) e.statusText = '进行中';
  53. if (e.status == 2) e.statusText = '已结束';
  54. e.image = BASE_URL.fileUrl + e.image;
  55. return e;
  56. })
  57. this.list.push(...res.rows)
  58. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  59. this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
  60. },
  61. btn(e) {
  62. uni.navigateTo({ url: `/pages/activity/details?activityId=${e.activityId}` })
  63. }
  64. },
  65. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  66. onReachBottom() {
  67. if(this.more != 'noMore') {
  68. this.more = 'more';
  69. this.query();
  70. }
  71. }
  72. }
  73. </script>
  74. <style>
  75. .slot-box {
  76. position: relative;
  77. }
  78. .slot-image {
  79. width: 70px;
  80. height: 70px;
  81. }
  82. .status {
  83. position: absolute;
  84. left: 0;
  85. top: 0;
  86. font-size: 12px;
  87. color: #fff;
  88. background: #999;
  89. }
  90. .slot-body {
  91. width: 70%;
  92. margin-left: 10px;
  93. }
  94. .slot-title {
  95. font-size: 1.2em;
  96. font-weight: 600;
  97. color: #000;
  98. line-height: 1.5em;
  99. }
  100. .slot-text {
  101. font-size: 14px;
  102. color: #999;
  103. line-height: 3em;
  104. }
  105. .footerIcon {
  106. line-height: 4em;
  107. }
  108. </style>