list.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="red_packet_list">
  3. <view v-for="(packet, index) in redpackets" :key="packet.id" class="red_packet_item" :class="{ disabled: packet.status !== 0 }" @click="handleClick(packet)">
  4. <img src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/packet_list_backerground.png" alt="" class="redpacket_background" />
  5. <view class="packet_header">
  6. <view class="packet_image">福</view>
  7. <view class="packet_info">
  8. <h3 class="packet_title">{{ packet.active_name }}</h3>
  9. <p class="packet_date">{{ common.timestampToString(packet.start_time) }} - {{ common.timestampToString(packet.end_time) }}</p>
  10. </view>
  11. </view>
  12. </view>
  13. <Empty v-if="redpackets.length == 0 && !isReqing" text="----- 还没有红包啦 -----" />
  14. <view class="to_bottom" v-if="isLast && redpackets.length"> -----到底啦-----</view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { ref, onMounted } from "vue";
  19. import { onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
  20. import Empty from "@/components/Empty/Empty.vue";
  21. import common from "@/utils/common";
  22. import http from "@/utils/request";
  23. const redpackets = ref([]);
  24. const page = ref(1);
  25. const pageSize = ref(10);
  26. const isLast = ref(false);
  27. const isReqing = ref(false);
  28. onMounted(() => {
  29. _getPacketlist();
  30. });
  31. const handleClick = (packet) => {
  32. if (packet.status !== 0) return;
  33. uni.navigateTo({
  34. url: `/pages/redpacket/index?packet_id=${packet.custom_redpacket_id}`,
  35. });
  36. };
  37. const _getPacketlist = () => {
  38. http.request("api/redpacket/get_list", { page: page.value, limit: pageSize.value }).then((callback) => {
  39. if (callback.code == "success") {
  40. if (callback.data.last_page <= page.value) isLast.value = true;
  41. const packetData = callback.data.data || [];
  42. redpackets.value = [...redpackets.value, ...packetData];
  43. }
  44. });
  45. };
  46. onReachBottom(() => {
  47. // 如果页码是0,避免第一页重复
  48. if (page.value < 1) return;
  49. // 最后一页不请求
  50. if (isLast.value) return;
  51. isReqing.value = true;
  52. page.value = page.value + 1;
  53. _getPacketlist();
  54. });
  55. onPullDownRefresh(() => {
  56. page.value = 1;
  57. redpackets.value = [];
  58. isReqing.value = true;
  59. isLast.value = false;
  60. _getPacketlist();
  61. uni.stopPullDownRefresh();
  62. });
  63. </script>
  64. <style lang="less" scoped>
  65. .red_packet_list {
  66. display: flex;
  67. flex-direction: column;
  68. gap: 20rpx;
  69. padding: 40rpx;
  70. }
  71. .red_packet_item {
  72. display: flex;
  73. align-items: center;
  74. justify-content: space-between;
  75. background-color: #c30a0a;
  76. border-radius: 20rpx;
  77. padding: 20rpx;
  78. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
  79. cursor: pointer;
  80. position: relative;
  81. height: 140rpx;
  82. overflow: hidden;
  83. &.disabled {
  84. cursor: not-allowed;
  85. opacity: 0.3;
  86. }
  87. .redpacket_background {
  88. width: 100%;
  89. height: 100%;
  90. position: absolute;
  91. top: 0;
  92. left: 120px;
  93. z-index: 1;
  94. }
  95. .packet_header {
  96. display: flex;
  97. align-items: center;
  98. z-index: 10;
  99. .packet_image {
  100. width: 100rpx;
  101. height: 100rpx;
  102. border-radius: 50%;
  103. margin-right: 20rpx;
  104. background-color: #fede9f;
  105. color: #af3636;
  106. font-size: 48rpx;
  107. font-weight: bold;
  108. text-align: center;
  109. line-height: 100rpx;
  110. }
  111. .packet_info {
  112. display: flex;
  113. flex-direction: column;
  114. .packet_title {
  115. font-size: 32rpx;
  116. font-weight: bold;
  117. margin: 0;
  118. color: #fff;
  119. }
  120. .packet_date {
  121. font-size: 24rpx;
  122. color: #fff;
  123. margin: 0;
  124. margin-top: 10rpx;
  125. }
  126. }
  127. }
  128. .packet_amount {
  129. font-size: 36rpx;
  130. font-weight: bold;
  131. color: #e74c3c;
  132. }
  133. }
  134. </style>