index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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="25"></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.regStartTime);
  58. if (e.status == 0 || isDateTime < startTime) e.statusText = '未开始';
  59. if (e.status !== 3 && isDateTime > startTime) e.statusText = '进行中';
  60. // if (isDateTime > endTime && e.status !== 3) e.statusText = '积分发放中';
  61. if (e.status == 3) e.statusText = '已结束';
  62. e.image = BASE_URL.fileUrl + e.image;
  63. return e;
  64. })
  65. this.list.push(...res.rows)
  66. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  67. this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
  68. },
  69. btn(e) {
  70. uni.navigateTo({ url: `/pages/activity/details?activityId=${e.activityId}` })
  71. }
  72. },
  73. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  74. onReachBottom() {
  75. if(this.more != 'noMore') {
  76. this.more = 'more';
  77. this.query();
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. .slot-box {
  84. position: relative;
  85. }
  86. .slot-image {
  87. width: 80px;
  88. height: 80px;
  89. }
  90. .status {
  91. position: absolute;
  92. left: 0;
  93. top: 0;
  94. font-size: 12px;
  95. color: #fff;
  96. background: #999;
  97. }
  98. .slot-body {
  99. width: 70%;
  100. margin-left: 10px;
  101. }
  102. .slot-title {
  103. font-size: 1.2em;
  104. font-weight: 600;
  105. color: #000;
  106. line-height: 2em;
  107. }
  108. .slot-text {
  109. font-size: 14px;
  110. color: #999;
  111. line-height: 3em;
  112. }
  113. .footerIcon {
  114. line-height: 3em;
  115. }
  116. </style>