修改升级版本、缴费记录分页显示金额问题

This commit is contained in:
zhouyanli
2026-09-23 16:51:45 +08:00
parent cf8e8263b7
commit 6022b19160
5 changed files with 78 additions and 25 deletions

View File

@@ -58,6 +58,8 @@
</view>
</view>
</view>
<view v-if="loading" class="list-tip">加载中...</view>
<view v-else-if="noMore && monthGroups.length > 0" class="list-tip">没有更多了</view>
</view>
</scroll-view>
</view>
@@ -93,6 +95,12 @@
const barMaxHeight = ref(300)
const billList = ref([])
// 各月缴费合计,来自接口 monthlyStats,key 形如 "2026-09"
const monthStatsMap = ref({})
// 加载中,防止 scrolltolower 连续触发导致 pageNum 连跳
const loading = ref(false)
// 没有更多数据了
const noMore = ref(false)
// 费用名称映射
// topup(水电表充值):type 1=电费, 2=水费
@@ -119,11 +127,15 @@
// 获取缴费记录(loadMore=true 时分页追加)
const getRecords = async (loadMore = false) => {
if (loading.value) return
if (loadMore && noMore.value) return
loading.value = true
// 成功后才推进页码,避免请求失败时丢掉一页
const nextPage = loadMore ? pageNum.value + 1 : 1
try {
if (!loadMore) pageNum.value = 1
const res = await getTopupRecordWithStat({
residentUserId: uni.getStorageSync('userId'),
pageNum: pageNum.value,
pageNum: nextPage,
pageSize: pageSize.value
})
if (res.code === 200) {
@@ -139,11 +151,14 @@
month: parts[1] ? parseInt(parts[1], 10) : 1,
name,
account: item.deviceCode || '',
amount: Number(item.amount) || 0,
amount: Number(item.paidAmount) || 0,
recordType: item.recordType || '',
icon: iconMap[name] || iconMap['账单']
}
})
pageNum.value = nextPage
// 返回条数不足一页,说明没有更多了
noMore.value = mappedList.length < pageSize.value
billList.value = loadMore ? [...billList.value, ...mappedList] : mappedList
// 累计缴费金额
totalAmount.value = res.data.totalAmount || '0.00'
@@ -152,12 +167,13 @@
}
} catch (err) {
console.error('获取缴费记录失败', err)
} finally {
loading.value = false
}
}
// 加载更多(触底分页)
const loadMore = () => {
pageNum.value++
getRecords(true)
}
@@ -169,13 +185,15 @@
const priceMatch = value.match(/([\d.]+)元/)
if (priceMatch && key.includes('-')) {
const [y, m] = key.split('-')
statsMap[key] = {
// 统一成补零格式(2026-09),方便和分组 key 对齐
statsMap[`${parseInt(y, 10)}-${String(parseInt(m, 10)).padStart(2, '0')}`] = {
year: parseInt(y, 10),
month: parseInt(m, 10),
price: parseFloat(priceMatch[1]) || 0
}
}
})
monthStatsMap.value = statsMap
// 取最近6个月(当前月往前)
const now = new Date()
@@ -215,6 +233,7 @@
const key = `${bill.year}-${String(bill.month).padStart(2, '0')}`
if (!map[key]) {
map[key] = {
key,
month: bill.month,
year: bill.year,
total: 0,
@@ -224,8 +243,15 @@
map[key].list.push(bill)
map[key].total += bill.amount
})
// 分组合计优先用接口返回的月度统计:列表是分页加载的,
// 只累加已加载的记录会少算,滚动翻页时数字还会一直往上跳
const groups = Object.values(map)
groups.forEach(group => {
const stat = monthStatsMap.value[group.key]
if (stat) group.total = stat.price
})
// 按年月降序排列
return Object.values(map).sort((a, b) => {
return groups.sort((a, b) => {
if (a.year !== b.year) return b.year - a.year
return b.month - a.month
})
@@ -298,6 +324,13 @@
margin-bottom: 10rpx;
}
.list-tip {
text-align: center;
font-size: 26rpx;
color: #999;
padding: 20rpx 0 40rpx;
}
.top-box {
display: flex;
justify-content: space-between;