修复bug

This commit is contained in:
zhouyanli
2026-08-28 17:25:55 +08:00
parent ea1acf1bbc
commit 0661687bc5
11 changed files with 93 additions and 48 deletions

View File

@@ -94,6 +94,7 @@ const searchText = ref('')
const selectedItem = ref(null)
const scrollIntoViewId = ref('')
const currentVillageIdFromHome = ref('') // 首页传入的当前选中小区ID
const sourcePage = ref('') // 来源页面payment 为缴费页独立切换,其他走首页切换
// 分页相关
const currentPage = ref(1)
@@ -187,7 +188,8 @@ const getCommunityList = async (pageNum = 1, keyword = '') => {
// 页面加载时初始化
onLoad((options) => {
// 接收首页传来得选择的小区id
// 接收来源页面及选中小区id
sourcePage.value = options?.source || ''
currentVillageIdFromHome.value = options?.villageId || ''
getCommunityList(1)
})
@@ -248,42 +250,58 @@ const handleConfirm = async () => {
})
return
}
// 缴费页为独立切换:不调用后端切换小区接口
const isPayment = sourcePage.value === 'payment'
try {
uni.showLoading({
title: '切换小区中...',
title: isPayment ? '加载中...' : '切换小区中...',
mask: true
})
const params = {
villageId: selectedItem.value.villageId,
}
const res = await getVillageSwitch(params)
uni.hideLoading()
if (res.code === 200) {
if (!isPayment) {
const res = await getVillageSwitch({
villageId: selectedItem.value.villageId,
})
uni.hideLoading()
if (res.code !== 200) {
uni.showToast({
title: res.msg || '切换小区失败',
icon: 'none',
duration: 2000
})
return
}
if (res.data?.villageId) {
selectedItem.value.villageId = res.data.villageId
}
uni.showToast({
title: '选择成功',
icon: 'success',
duration: 1500
} else {
uni.hideLoading()
}
uni.showToast({
title: '选择成功',
icon: 'success',
duration: 1500
})
if (isPayment) {
// 缴费页独立缓存 + 独立事件,通知缴费页刷新(按账号隔离)
const userId = uni.getStorageSync('userId') || ''
uni.setStorageSync('paymentVillageId_' + userId, selectedItem.value.villageId)
uni.setStorageSync('paymentVillageName_' + userId, selectedItem.value.villageName)
uni.$emit('confirmPayment', {
name: selectedItem.value.villageName,
villageId: selectedItem.value.villageId
})
} else {
// 更新缓存并通知首页
uni.setStorageSync('currentVillageId', selectedItem.value.villageId)
uni.$emit('confirm', {
name: selectedItem.value.villageName,
villageId: selectedItem.value.villageId
})
setTimeout(() => {
uni.navigateBack()
}, 1000)
} else {
uni.showToast({
title: res.msg || '切换小区失败',
icon: 'error',
duration: 2000
})
}
setTimeout(() => {
uni.navigateBack()
}, 1000)
} catch (err) {
uni.hideLoading()
uni.showToast({