fix(dealer/customer): 修复报备成功后客户列表未自动刷新的问题

- 在客户列表页面添加 useDidShow 钩子监听页面显示事件
- 实现页面显示时自动刷新数据的逻辑
- 优化用户体验,确保报备成功后立即看到最新数据
This commit is contained in:
2025-09-06 10:47:06 +08:00
parent bef845620c
commit d26208ee39
3 changed files with 191 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
import {useState, useEffect, useCallback} from 'react'
import {View, Text} from '@tarojs/components'
import Taro from '@tarojs/taro'
import Taro, {useDidShow} from '@tarojs/taro'
import {Loading, InfiniteLoading, Empty, Space, Tabs, TabPane, Tag, Button} from '@nutui/nutui-react-taro'
import {Phone} from '@nutui/icons-react-taro'
import type {ShopDealerApply, ShopDealerApply as UserType} from "@/api/shop/shopDealerApply/model";
@@ -50,7 +50,6 @@ const CustomerIndex = () => {
}
const res = await pageShopDealerApply(params);
let newList: CustomerUser[];
if (res?.list && res.list.length > 0) {
// 正确映射状态
@@ -60,17 +59,22 @@ const CustomerIndex = () => {
}));
// 如果是重置页面或第一页,直接设置新数据;否则追加数据
newList = resetPage ? mappedList : list.concat(mappedList);
if (resetPage || currentPage === 1) {
setList(mappedList);
} else {
setList(prevList => prevList.concat(mappedList));
}
// 正确判断是否还有更多数据
const hasMoreData = res.list.length >= 10; // 假设每页10条数据
setHasMore(hasMoreData);
} else {
newList = resetPage ? [] : list;
if (resetPage || currentPage === 1) {
setList([]);
}
setHasMore(false);
}
setList(newList);
setPage(currentPage);
} catch (error) {
console.error('获取客户数据失败:', error);
@@ -81,7 +85,7 @@ const CustomerIndex = () => {
} finally {
setLoading(false);
}
}, [activeTab]);
}, [activeTab, page]);
const reloadMore = async () => {
if (loading || !hasMore) return; // 防止重复加载
@@ -174,6 +178,16 @@ const CustomerIndex = () => {
fetchCustomerData(activeTab, true);
}, [activeTab]);
// 监听页面显示,当从其他页面返回时刷新数据
useDidShow(() => {
// 刷新当前tab的数据和统计信息
setList([]);
setPage(1);
setHasMore(true);
fetchCustomerData(activeTab, true);
fetchStatusCounts();
});
// 渲染客户项
const renderCustomerItem = (customer: CustomerUser) => (
<View key={customer.userId} className="bg-white rounded-lg p-4 mb-3 shadow-sm">