list.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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, onShow } 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. onShow(() => {
  32. _getPacketlist();
  33. });
  34. const handleClick = (packet) => {
  35. if (packet.status !== 0) return;
  36. uni.navigateTo({
  37. url: `/pages/redpacket/index?packet_id=${packet.custom_redpacket_id}`,
  38. });
  39. };
  40. const _getPacketlist = () => {
  41. http.request("api/redpacket/get_list", { page: page.value, limit: pageSize.value }).then((callback) => {
  42. if (callback.code == "success") {
  43. if (callback.data.last_page <= page.value) isLast.value = true;
  44. const packetData = callback.data.data || [];
  45. redpackets.value = page.value == 1 ? packetData : [...redpackets.value, ...packetData];
  46. }
  47. });
  48. };
  49. onReachBottom(() => {
  50. // 如果页码是0,避免第一页重复
  51. if (page.value < 1) return;
  52. // 最后一页不请求
  53. if (isLast.value) return;
  54. isReqing.value = true;
  55. page.value = page.value + 1;
  56. _getPacketlist();
  57. });
  58. onPullDownRefresh(() => {
  59. page.value = 1;
  60. redpackets.value = [];
  61. isReqing.value = true;
  62. isLast.value = false;
  63. _getPacketlist();
  64. uni.stopPullDownRefresh();
  65. });
  66. </script>
  67. <style lang="less" scoped>
  68. .red_packet_list {
  69. display: flex;
  70. flex-direction: column;
  71. gap: 20rpx;
  72. padding: 40rpx;
  73. }
  74. .red_packet_item {
  75. display: flex;
  76. align-items: center;
  77. justify-content: space-between;
  78. background-color: #c30a0a;
  79. border-radius: 20rpx;
  80. padding: 20rpx;
  81. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
  82. cursor: pointer;
  83. position: relative;
  84. height: 140rpx;
  85. overflow: hidden;
  86. &.disabled {
  87. cursor: not-allowed;
  88. opacity: 0.3;
  89. }
  90. .redpacket_background {
  91. width: 100%;
  92. height: 100%;
  93. position: absolute;
  94. top: 0;
  95. left: 120px;
  96. z-index: 1;
  97. }
  98. .packet_header {
  99. display: flex;
  100. align-items: center;
  101. z-index: 10;
  102. .packet_image {
  103. width: 100rpx;
  104. height: 100rpx;
  105. border-radius: 50%;
  106. margin-right: 20rpx;
  107. background-color: #fede9f;
  108. color: #af3636;
  109. font-size: 48rpx;
  110. font-weight: bold;
  111. text-align: center;
  112. line-height: 100rpx;
  113. }
  114. .packet_info {
  115. display: flex;
  116. flex-direction: column;
  117. .packet_title {
  118. font-size: 32rpx;
  119. font-weight: bold;
  120. margin: 0;
  121. color: #fff;
  122. }
  123. .packet_date {
  124. font-size: 24rpx;
  125. color: #fff;
  126. margin: 0;
  127. margin-top: 10rpx;
  128. }
  129. }
  130. }
  131. .packet_amount {
  132. font-size: 36rpx;
  133. font-weight: bold;
  134. color: #e74c3c;
  135. }
  136. }
  137. </style>