Compare commits

...

3 Commits

Author SHA1 Message Date
赵毅
36776f2fc9 优化我的红包页面数据展示为分页展示 2025-12-18 17:39:45 +08:00
赵毅
ee3eded5a2 修改我的红包页面店铺红包不显示店铺信息的bug 2025-12-18 10:00:09 +08:00
赵毅
b227737750 修改我的红包数据展示异常问题 2025-12-18 09:59:31 +08:00
2 changed files with 88 additions and 8 deletions

View File

@ -124,16 +124,34 @@ export default {
changeIndex: 0,
redPacketNum: 0,
redPacketMoney: 0.00,
page_num: 1,
page_size: 20,
loading: false,
hasMore: true,
}
},
methods: {
async getMyRedPacket(changeIndex) {
async getMyRedPacket(changeIndex, isLoadMore = false) {
if (this.loading) return;
this.loading = true;
const params = {
user_id: uni.getStorageSync('userId'),
belong_role: changeIndex == 0 ? '' : changeIndex,
page_num: this.page_num,
page_size: this.page_size,
}
const res = await request(apiArr.redPackageMyred, 'POST', params);
let processedList = res.rows.map(item => {
if (!res || !res.rows) {
this.loading = false;
this.hasMore = false;
return;
}
let processedList = res.rows
.filter(item => item.status !== 3)
.map(item => {
const newItem = { ...item };
if (newItem?.agent_info?.ad?.ad_name) {
@ -158,7 +176,26 @@ export default {
grouped[adName].packets.push(item);
}
});
this.redPacketList = Object.values(grouped);
if (isLoadMore) {
//
const existingGroups = { ...this.redPacketList.reduce((acc, group) => {
acc[group.ad_name] = group;
return acc;
}, {}) };
Object.keys(grouped).forEach(adName => {
if (existingGroups[adName]) {
existingGroups[adName].packets = [...existingGroups[adName].packets, ...grouped[adName].packets];
} else {
existingGroups[adName] = grouped[adName];
}
});
this.redPacketList = Object.values(existingGroups);
} else {
this.redPacketList = Object.values(grouped);
}
} else if (this.currentTab == 3) {
// merchant_name
const grouped = {};
@ -174,14 +211,42 @@ export default {
grouped[merchantName].packets.push(item);
}
});
this.redPacketList = Object.values(grouped);
if (isLoadMore) {
//
const existingGroups = { ...this.redPacketList.reduce((acc, group) => {
acc[group.merchant_name] = group;
return acc;
}, {}) };
Object.keys(grouped).forEach(merchantName => {
if (existingGroups[merchantName]) {
existingGroups[merchantName].packets = [...existingGroups[merchantName].packets, ...grouped[merchantName].packets];
} else {
existingGroups[merchantName] = grouped[merchantName];
}
});
this.redPacketList = Object.values(existingGroups);
} else {
this.redPacketList = Object.values(grouped);
}
} else {
this.redPacketList = processedList;
if (isLoadMore) {
this.redPacketList = [...this.redPacketList, ...processedList];
} else {
this.redPacketList = processedList;
}
}
this.redPacketNum = res.rows.filter(item => item.red_package_config).length;
this.redPacketMoney = res.rows.reduce((total, item) =>
this.redPacketNum = processedList.filter(item => item.red_package_config).length;
this.redPacketMoney = processedList.reduce((total, item) =>
item.red_package_config ? total + item.red_package_config.money : total, 0.00
).toFixed(2);
//
this.hasMore = processedList.length === this.page_size;
this.loading = false;
},
useRedPacket(item) {
console.log('使用红包:', item);
@ -206,13 +271,28 @@ export default {
} else if (index == 3) {
this.changeIndex = 1;
}
//
this.page_num = 1;
this.loading = false;
this.hasMore = true;
this.redPacketList = [];
this.getMyRedPacket(this.changeIndex);
if (this.tabList[index] == '历史记录') {
NavgateTo('/packages/user/history/index');
}
},
onReachBottom() {
if (this.loading || !this.hasMore) return;
this.page_num++;
this.getMyRedPacket(this.changeIndex, true);
}
},
onShow() {
//
this.page_num = 1;
this.loading = false;
this.hasMore = true;
this.redPacketList = [];
this.switchTab(0);
this.getMyRedPacket(0);
}

View File

@ -78,7 +78,7 @@ export default {
const params = {
user_id: uni.getStorageSync('userId'),
red_package_config_id: item.id,
mch_id: item.belong_role == 1 ? item.merchant_id : ''
mch_id: item.belong_role == 1 ? item.mch_id : ''
}
request(apiArr.redPackageClaim, 'POST', params).then(res => {
this.currentItem = item;