123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <template>
- <view class="red_packet_list">
- <view v-for="(packet, index) in redpackets" :key="packet.id" class="red_packet_item" :class="{ disabled: packet.status !== 0 }" @click="handleClick(packet)">
- <img src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/packet_list_backerground.png" alt="" class="redpacket_background" />
- <view class="packet_header">
- <view class="packet_image">福</view>
- <view class="packet_info">
- <h3 class="packet_title">{{ packet.active_name }}</h3>
- <p class="packet_date">{{ common.timestampToString(packet.start_time) }} - {{ common.timestampToString(packet.end_time) }}</p>
- </view>
- </view>
- </view>
- <Empty v-if="redpackets.length == 0 && !isReqing" text="----- 还没有红包啦 -----" />
- <view class="to_bottom" v-if="isLast && redpackets.length"> -----到底啦-----</view>
- </view>
- </template>
- <script setup>
- import { ref, onMounted } from "vue";
- import { onReachBottom, onPullDownRefresh, onShow } from "@dcloudio/uni-app";
- import Empty from "@/components/Empty/Empty.vue";
- import common from "@/utils/common";
- import http from "@/utils/request";
- const redpackets = ref([]);
- const page = ref(1);
- const pageSize = ref(10);
- const isLast = ref(false);
- const isReqing = ref(false);
- // onMounted(() => {
- // _getPacketlist();
- // });
- onShow(() => {
- _getPacketlist();
- });
- const handleClick = (packet) => {
- if (packet.status !== 0) return;
- uni.navigateTo({
- url: `/pages/redpacket/index?packet_id=${packet.custom_redpacket_id}`,
- });
- };
- const _getPacketlist = () => {
- http.request("api/redpacket/get_list", { page: page.value, limit: pageSize.value }).then((callback) => {
- if (callback.code == "success") {
- if (callback.data.last_page <= page.value) isLast.value = true;
- const packetData = callback.data.data || [];
- redpackets.value = page.value == 1 ? packetData : [...redpackets.value, ...packetData];
- }
- });
- };
- onReachBottom(() => {
- // 如果页码是0,避免第一页重复
- if (page.value < 1) return;
- // 最后一页不请求
- if (isLast.value) return;
- isReqing.value = true;
- page.value = page.value + 1;
- _getPacketlist();
- });
- onPullDownRefresh(() => {
- page.value = 1;
- redpackets.value = [];
- isReqing.value = true;
- isLast.value = false;
- _getPacketlist();
- uni.stopPullDownRefresh();
- });
- </script>
- <style lang="less" scoped>
- .red_packet_list {
- display: flex;
- flex-direction: column;
- gap: 20rpx;
- padding: 40rpx;
- }
- .red_packet_item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- background-color: #c30a0a;
- border-radius: 20rpx;
- padding: 20rpx;
- box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
- cursor: pointer;
- position: relative;
- height: 140rpx;
- overflow: hidden;
- &.disabled {
- cursor: not-allowed;
- opacity: 0.3;
- }
- .redpacket_background {
- width: 100%;
- height: 100%;
- position: absolute;
- top: 0;
- left: 120px;
- z-index: 1;
- }
- .packet_header {
- display: flex;
- align-items: center;
- z-index: 10;
- .packet_image {
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- background-color: #fede9f;
- color: #af3636;
- font-size: 48rpx;
- font-weight: bold;
- text-align: center;
- line-height: 100rpx;
- }
- .packet_info {
- display: flex;
- flex-direction: column;
- .packet_title {
- font-size: 32rpx;
- font-weight: bold;
- margin: 0;
- color: #fff;
- }
- .packet_date {
- font-size: 24rpx;
- color: #fff;
- margin: 0;
- margin-top: 10rpx;
- }
- }
- }
- .packet_amount {
- font-size: 36rpx;
- font-weight: bold;
- color: #e74c3c;
- }
- }
- </style>
|