直播更新
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
height: calc(100vh - 162rpx);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 28rpx 20rpx;
|
||||
|
||||
}
|
||||
|
||||
/* ===== 汇总卡片 ===== */
|
||||
.summary-section {
|
||||
padding: 24rpx 24rpx 0;
|
||||
}
|
||||
// .summary-section {
|
||||
// padding: 24rpx 24rpx 0;
|
||||
// }
|
||||
|
||||
.summary-card {
|
||||
display: flex;
|
||||
@@ -23,7 +25,6 @@
|
||||
.total-card {
|
||||
background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%);
|
||||
margin-bottom: 16rpx;
|
||||
padding: 28rpx 20rpx;
|
||||
}
|
||||
|
||||
.total-card .card-label {
|
||||
@@ -72,7 +73,7 @@
|
||||
}
|
||||
|
||||
.tabs-wrap {
|
||||
margin: 16rpx;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
/* ===== 红包列表 ===== */
|
||||
@@ -94,7 +95,7 @@
|
||||
padding: 24rpx 30rpx;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #eee;
|
||||
margin: 0 24rpx;
|
||||
margin: 0;
|
||||
border-radius: 12rpx;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
@@ -86,25 +86,52 @@ Page({
|
||||
const { id, outrewardsid } = e.currentTarget.dataset;
|
||||
const params: Record<string, any> = {
|
||||
appId: appId,
|
||||
outRewardsId: outrewardsid,
|
||||
openId: wx.getStorageSync("openId"),
|
||||
};
|
||||
if (outrewardsid) params.outRewardsId = outrewardsid;
|
||||
if (id) params.redId = id;
|
||||
|
||||
try {
|
||||
await receiveRedPacket(
|
||||
params,
|
||||
'/app/general/receive-red',
|
||||
appId
|
||||
);
|
||||
// 领取成功,刷新当前列表
|
||||
this.fetchRecords(1, false, this.data.tabs[this.data.activeTab].type);
|
||||
|
||||
// 乐观更新:先立即更新本地数据,避免后端状态同步延迟导致展示不友好
|
||||
const { list, summary, activeTab, tabs } = this.data;
|
||||
const targetItem = list.find((item: any) => item.id === id);
|
||||
|
||||
if (targetItem) {
|
||||
const amount = targetItem.amount || 0;
|
||||
const amountYuan = amount / 100;
|
||||
|
||||
const updatedList = list.map((item: any) =>
|
||||
item.id === id
|
||||
? { ...item, state: 40, stateText: getStateText(40), canReceive: false, isRetry: false }
|
||||
: item
|
||||
);
|
||||
|
||||
const updatedSummary = {
|
||||
...summary,
|
||||
pendingAmount: Math.max(0, parseFloat(summary.pendingAmount) - amountYuan).toFixed(2),
|
||||
receivedAmount: (parseFloat(summary.receivedAmount) + amountYuan).toFixed(2),
|
||||
};
|
||||
|
||||
this.setData({ list: updatedList, summary: updatedSummary });
|
||||
}
|
||||
|
||||
// 确保后端有足够时间同步,直接刷新
|
||||
setTimeout(() => {
|
||||
this.fetchRecords(1, false, tabs[activeTab].type);
|
||||
}, 3000);
|
||||
} catch (err) {
|
||||
console.error('领取红包失败:', err);
|
||||
}
|
||||
},
|
||||
|
||||
async fetchRecords(page: number, append = false, type: number) {
|
||||
const app = getApp<IAppOption>();
|
||||
const openId = wx.getStorageSync("openId");
|
||||
|
||||
this.setData({
|
||||
|
||||
Reference in New Issue
Block a user