Feat:礼包卡加载优化

This commit is contained in:
LinCyJang
2026-06-01 00:46:54 +08:00
parent 9c6aa2351b
commit 48e037e44e
+108 -21
View File
@@ -121,6 +121,9 @@
</view> </view>
</view> </view>
</block> </block>
<view v-if="sendList.length > 0" class="load-more">
{{ sendLoading ? '加载中...' : (sendHasMore ? '上拉加载更多' : '没有更多了') }}
</view>
<view v-if="sendList.length === 0" class="noCart"> <view v-if="sendList.length === 0" class="noCart">
<view class="pictrue"> <view class="pictrue">
<image :src="webUrl + '/20240102232734472795.png'"/> <image :src="webUrl + '/20240102232734472795.png'"/>
@@ -203,6 +206,9 @@
</view> </view>
</view> </view>
</block> </block>
<view v-if="receiveList.length > 0" class="load-more">
{{ receiveLoading ? '加载中...' : (receiveHasMore ? '上拉加载更多' : '没有更多了') }}
</view>
<view v-if="receiveList.length === 0" class="noCart"> <view v-if="receiveList.length === 0" class="noCart">
<view class="pictrue"> <view class="pictrue">
<image :src="webUrl + '/20240102232734472795.png'"/> <image :src="webUrl + '/20240102232734472795.png'"/>
@@ -283,6 +289,15 @@ export default {
giftItem: {}, giftItem: {},
orderInfo: {}, orderInfo: {},
isShowPayPwdPop: false, isShowPayPwdPop: false,
pageSize: 10,
sendPage: 1,
receivePage: 1,
sendLoading: false,
receiveLoading: false,
sendHasMore: true,
receiveHasMore: true,
sendInited: false,
receiveInited: false
} }
}, },
computed: mapGetters(["userInfo"]), computed: mapGetters(["userInfo"]),
@@ -290,7 +305,14 @@ export default {
giftNotice().then(res => { giftNotice().then(res => {
this.giftNotice = res.data this.giftNotice = res.data
}) })
this.getGiftCardSendList() this.getGiftCardSendList(true)
},
onReachBottom() {
if (this.cateIndex === 0) {
this.getGiftCardSendList()
return
}
this.getGiftCardReceiveList()
}, },
onShareAppMessage() { onShareAppMessage() {
uni.updateShareMenu({ uni.updateShareMenu({
@@ -318,7 +340,7 @@ export default {
id: item.id id: item.id
}).then(qRes => { }).then(qRes => {
if (qRes.success) { if (qRes.success) {
this.getGiftCardSendList() this.getGiftCardSendList(true)
} }
}).finally(() => { }).finally(() => {
uni.hideLoading() uni.hideLoading()
@@ -338,7 +360,7 @@ export default {
//网络请求 //网络请求
yuePayOrderHandle(this.orderInfo.orderId, "yue", this.from, payPwd).then(res => { yuePayOrderHandle(this.orderInfo.orderId, "yue", this.from, payPwd).then(res => {
console.log(res); console.log(res);
this.getGiftCardSendList() this.getGiftCardSendList(true)
this.payPassword = ""; this.payPassword = "";
}) })
}, },
@@ -348,7 +370,7 @@ export default {
wechatPay(type) { wechatPay(type) {
payOrderHandle(this.orderInfo.orderId, type, this.from).then(res => { payOrderHandle(this.orderInfo.orderId, type, this.from).then(res => {
console.log(res); console.log(res);
this.getGiftCardSendList() this.getGiftCardSendList(true)
}) })
}, },
goBuy(order) { goBuy(order) {
@@ -370,43 +392,102 @@ export default {
cateItemClickHanlde(item, index) { cateItemClickHanlde(item, index) {
if (this.cateIndex === index || !this.isLoad) return if (this.cateIndex === index || !this.isLoad) return
this.cateIndex = index this.cateIndex = index
if (this.cateIndex === 0) { if (this.cateIndex === 0 && !this.sendInited) {
this.getGiftCardSendList() this.getGiftCardSendList(true)
} }
if (this.cateIndex === 1) { if (this.cateIndex === 1 && !this.receiveInited) {
this.getGiftCardReceiveList() this.getGiftCardReceiveList(true)
} }
}, },
getGiftCardReceiveList() { getListResult(data, page) {
this.isLoad = false const list = Array.isArray(data)
? data
: (data && (data.records || data.list || data.data)) || []
const pageCount = Number(
data && (data.pages || data.totalPage || data.last_page || data.pageCount || 0)
)
const total = Number(
data && (data.total || data.totalCount || data.count || 0)
)
let hasMore = false
if (pageCount > 0) {
hasMore = page < pageCount
} else if (total > 0) {
hasMore = page * this.pageSize < total
} else {
hasMore = list.length >= this.pageSize
}
return {
list,
hasMore
}
},
getGiftCardReceiveList(reset = false) {
if (this.receiveLoading) return
if (!reset && !this.receiveHasMore) return
const page = reset ? 1 : this.receivePage
if (reset) {
this.receivePage = 1
this.receiveHasMore = true
this.receiveList = []
}
if (page === 1 && this.cateIndex === 1) {
this.isLoad = false
}
this.receiveLoading = true
giftCardReceiveList({ giftCardReceiveList({
page: 1, page,
limit: 999 limit: this.pageSize
}).then(res => { }).then(res => {
const { success, data } = res const { success, data } = res
if (success) { if (success) {
this.receiveList = data || [] const { list, hasMore } = this.getListResult(data, page)
this.receiveList = page === 1 ? list : this.receiveList.concat(list)
this.receiveHasMore = hasMore
this.receivePage = page + 1
this.receiveInited = true
} }
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
}).finally(() => { }).finally(() => {
this.isLoad = true this.receiveLoading = false
if (this.cateIndex === 1) {
this.isLoad = true
}
}) })
}, },
getGiftCardSendList() { getGiftCardSendList(reset = false) {
this.isLoad = false if (this.sendLoading) return
if (!reset && !this.sendHasMore) return
const page = reset ? 1 : this.sendPage
if (reset) {
this.sendPage = 1
this.sendHasMore = true
this.sendList = []
}
if (page === 1 && this.cateIndex === 0) {
this.isLoad = false
}
this.sendLoading = true
giftCardSendList({ giftCardSendList({
page: 1, page,
limit: 999 limit: this.pageSize
}).then(res => { }).then(res => {
const { success, data } = res const { success, data } = res
if (success) { if (success) {
this.sendList = data || [] const { list, hasMore } = this.getListResult(data, page)
this.sendList = page === 1 ? list : this.sendList.concat(list)
this.sendHasMore = hasMore
this.sendPage = page + 1
this.sendInited = true
} }
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
}).finally(() => { }).finally(() => {
this.isLoad = true this.sendLoading = false
if (this.cateIndex === 0) {
this.isLoad = true
}
}) })
}, },
getStatus(order) { getStatus(order) {
@@ -655,4 +736,10 @@ export default {
line-height: 40rpx; line-height: 40rpx;
font-size: 26rpx; font-size: 26rpx;
} }
</style> .load-more {
padding: 0 0 24rpx;
text-align: center;
font-size: 24rpx;
color: #999;
}
</style>