diff --git a/src/api/shop/shopDealerApply/model/index.ts b/src/api/shop/shopDealerApply/model/index.ts index f308596..2860c66 100644 --- a/src/api/shop/shopDealerApply/model/index.ts +++ b/src/api/shop/shopDealerApply/model/index.ts @@ -48,4 +48,5 @@ export interface ShopDealerApplyParam extends PageParam { mobile?: string; userId?: number; keywords?: string; + applyStatus?: number; // 申请状态筛选 (10待审核 20审核通过 30驳回) } diff --git a/src/dealer/customer/index.tsx b/src/dealer/customer/index.tsx index edd14b8..6b994d3 100644 --- a/src/dealer/customer/index.tsx +++ b/src/dealer/customer/index.tsx @@ -8,7 +8,9 @@ import { CustomerStatus, getStatusText, getStatusTagType, - getStatusOptions + getStatusOptions, + mapApplyStatusToCustomerStatus, + mapCustomerStatusToApplyStatus } from '@/utils/customerStatus'; import FixedButton from "@/components/FixedButton"; import navTo from "@/utils/common"; @@ -28,52 +30,39 @@ const CustomerIndex = () => { // Tab配置 const tabList = getStatusOptions(); + // 获取客户数据 - const fetchCustomerData = useCallback(async () => { + const fetchCustomerData = useCallback(async (statusFilter?: CustomerStatus) => { setLoading(true); try { - const res = await pageShopDealerApply({}); + // 构建API参数,根据状态筛选 + const params: any = {}; + const applyStatus = mapCustomerStatusToApplyStatus(statusFilter || activeTab); + if (applyStatus !== undefined) { + params.applyStatus = applyStatus; + } + + const res = await pageShopDealerApply(params); if (res?.list) { - list.map(d => { - if(d.applyStatus == 10){ - d.customerStatus = 'pending' - } - if(d.applyStatus == 20){ - d.customerStatus = 'signed' - } - if(d.applyStatus == 30){ - d.customerStatus = 'cancelled' - } - return { - ...d, - customerStatus: d.applyStatus == 10 ? 'pending' : 'signed' - } - }) - setList(res.list); + // 正确映射状态 + const mappedList = res.list.map(customer => ({ + ...customer, + customerStatus: mapApplyStatusToCustomerStatus(customer.applyStatus || 10) + })); + setList(mappedList); } } catch (error) { console.error('获取客户数据失败:', error); } finally { setLoading(false); } - }, []); + }, [activeTab]); - // 根据当前Tab和搜索条件筛选数据 + // 根据搜索条件筛选数据(状态筛选已在API层面处理) const getFilteredList = () => { - console.log('TABS',activeTab) let filteredList = list; - // 按状态筛选 - if (activeTab !== 'all') { - console.log(filteredList,'customerStatus') - filteredList.map(d => { - console.log(d.applyStatus) - }) - - filteredList = filteredList.filter(customer => customer.customerStatus === activeTab); - } - // 按搜索关键词筛选 if (searchValue.trim()) { const keyword = searchValue.trim().toLowerCase(); @@ -90,22 +79,36 @@ const CustomerIndex = () => { }; // 获取各状态的统计数量 - const getStatusCounts = () => { - const counts = { - all: list.length, - pending: 0, - signed: 0, - cancelled: 0 - }; + const [statusCounts, setStatusCounts] = useState({ + all: 0, + pending: 0, + signed: 0, + cancelled: 0 + }); - list.forEach(customer => { - if (customer.customerStatus && counts.hasOwnProperty(customer.customerStatus)) { - counts[customer.customerStatus]++; - } - }); + // 获取所有状态的统计数量 + const fetchStatusCounts = useCallback(async () => { + try { + // 并行获取各状态的数量 + const [allRes, pendingRes, signedRes, cancelledRes] = await Promise.all([ + pageShopDealerApply({}), // 全部 + pageShopDealerApply({applyStatus: 10}), // 跟进中 + pageShopDealerApply({applyStatus: 20}), // 已签约 + pageShopDealerApply({applyStatus: 30}) // 已取消 + ]); - return counts; - }; + setStatusCounts({ + all: allRes?.count || 0, + pending: pendingRes?.count || 0, + signed: signedRes?.count || 0, + cancelled: cancelledRes?.count || 0 + }); + } catch (error) { + console.error('获取状态统计失败:', error); + } + }, []); + + const getStatusCounts = () => statusCounts; // 取消操作 const handleCancel = (customer: ShopDealerApply) => { @@ -120,7 +123,13 @@ const CustomerIndex = () => { // 初始化数据 useEffect(() => { fetchCustomerData(); - }, [fetchCustomerData]); + fetchStatusCounts(); + }, [fetchCustomerData, fetchStatusCounts]); + + // 当activeTab变化时重新获取数据 + useEffect(() => { + fetchCustomerData(activeTab); + }, [activeTab]); // 渲染客户项 const renderCustomerItem = (customer: CustomerUser) => ( diff --git a/src/utils/customerStatus.ts b/src/utils/customerStatus.ts index 1d174a5..d77f63b 100644 --- a/src/utils/customerStatus.ts +++ b/src/utils/customerStatus.ts @@ -60,6 +60,40 @@ export const getStatusOptions = () => { })); }; +/** + * 将数字状态映射为字符串状态 + */ +export const mapApplyStatusToCustomerStatus = (applyStatus: number): CustomerStatus => { + switch (applyStatus) { + case 10: + return 'pending'; // 跟进中 + case 20: + return 'signed'; // 已签约 + case 30: + return 'cancelled'; // 已取消 + default: + return 'pending'; // 默认为跟进中 + } +}; + +/** + * 将字符串状态映射为数字状态 + */ +export const mapCustomerStatusToApplyStatus = (customerStatus: CustomerStatus): number | undefined => { + switch (customerStatus) { + case 'pending': + return 10; // 跟进中 + case 'signed': + return 20; // 已签约 + case 'cancelled': + return 30; // 已取消 + case 'all': + return undefined; // 全部,不筛选 + default: + return undefined; + } +}; + /** * 临时函数:生成随机状态(实际项目中应该删除,从数据库获取真实状态) */