index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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" @click="btn(item)">
  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" @click="btn(item)">
  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" @click="btn(item)">
  22. <uni-icons class="footerIcon" type="forward" size="35"></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. type: null
  41. }
  42. },
  43. mounted() {
  44. this.query();
  45. },
  46. onLoad(option) {
  47. this.type = option.type;
  48. },
  49. methods: {
  50. async query() {
  51. this.page += 1;
  52. this.more = 'loading';
  53. const res = await request.getActivity({ pageNum: this.page, pageSize: this.size, types: this.type });
  54. const isDateTime = new Date().getTime();
  55. res.rows?.map(e => {
  56. const endTime = Date.parse(e.endTime);
  57. const startTime = Date.parse(e.startTime);
  58. if (e.status == 0) e.statusText = '未开始';
  59. if (e.status !== 3 && isDateTime < endTime && isDateTime > startTime) e.statusText = '进行中';
  60. if (e.status == 3) e.statusText = '已结束';
  61. e.image = BASE_URL.fileUrl + e.image;
  62. return e;
  63. })
  64. this.list.push(...res.rows)
  65. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  66. this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
  67. },
  68. btn(e) {
  69. uni.navigateTo({ url: `/pages/activity/details?activityId=${e.activityId}` })
  70. }
  71. },
  72. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  73. onReachBottom() {
  74. if(this.more != 'noMore') {
  75. this.more = 'more';
  76. this.query();
  77. }
  78. }
  79. }
  80. </script>
  81. <style>
  82. .slot-box {
  83. position: relative;
  84. }
  85. .slot-image {
  86. width: 70px;
  87. height: 70px;
  88. }
  89. .status {
  90. position: absolute;
  91. left: 0;
  92. top: 0;
  93. font-size: 12px;
  94. color: #fff;
  95. background: #999;
  96. }
  97. .slot-body {
  98. width: 70%;
  99. margin-left: 10px;
  100. }
  101. .slot-title {
  102. font-size: 1.2em;
  103. font-weight: 600;
  104. color: #000;
  105. line-height: 1.5em;
  106. }
  107. .slot-text {
  108. font-size: 14px;
  109. color: #999;
  110. line-height: 3em;
  111. }
  112. .footerIcon {
  113. line-height: 4em;
  114. }
  115. </style>