index.vue 2.1 KB

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