feat(customer): 优化客户状态筛选和统计功能
- 新增状态映射函数,实现数字状态和字符串状态的互相转换 - 在 API 层面实现状态筛选,提高数据处理效率 - 重构客户数据获取逻辑,支持按状态筛选 - 优化状态统计功能,使用异步请求并行获取各状态数量 - 调整前端渲染逻辑,适应新的数据处理方式
This commit is contained in:
@@ -48,4 +48,5 @@ export interface ShopDealerApplyParam extends PageParam {
|
|||||||
mobile?: string;
|
mobile?: string;
|
||||||
userId?: number;
|
userId?: number;
|
||||||
keywords?: string;
|
keywords?: string;
|
||||||
|
applyStatus?: number; // 申请状态筛选 (10待审核 20审核通过 30驳回)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import {
|
|||||||
CustomerStatus,
|
CustomerStatus,
|
||||||
getStatusText,
|
getStatusText,
|
||||||
getStatusTagType,
|
getStatusTagType,
|
||||||
getStatusOptions
|
getStatusOptions,
|
||||||
|
mapApplyStatusToCustomerStatus,
|
||||||
|
mapCustomerStatusToApplyStatus
|
||||||
} from '@/utils/customerStatus';
|
} from '@/utils/customerStatus';
|
||||||
import FixedButton from "@/components/FixedButton";
|
import FixedButton from "@/components/FixedButton";
|
||||||
import navTo from "@/utils/common";
|
import navTo from "@/utils/common";
|
||||||
@@ -28,52 +30,39 @@ const CustomerIndex = () => {
|
|||||||
// Tab配置
|
// Tab配置
|
||||||
const tabList = getStatusOptions();
|
const tabList = getStatusOptions();
|
||||||
|
|
||||||
|
|
||||||
// 获取客户数据
|
// 获取客户数据
|
||||||
const fetchCustomerData = useCallback(async () => {
|
const fetchCustomerData = useCallback(async (statusFilter?: CustomerStatus) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
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) {
|
if (res?.list) {
|
||||||
list.map(d => {
|
// 正确映射状态
|
||||||
if(d.applyStatus == 10){
|
const mappedList = res.list.map(customer => ({
|
||||||
d.customerStatus = 'pending'
|
...customer,
|
||||||
}
|
customerStatus: mapApplyStatusToCustomerStatus(customer.applyStatus || 10)
|
||||||
if(d.applyStatus == 20){
|
}));
|
||||||
d.customerStatus = 'signed'
|
setList(mappedList);
|
||||||
}
|
|
||||||
if(d.applyStatus == 30){
|
|
||||||
d.customerStatus = 'cancelled'
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...d,
|
|
||||||
customerStatus: d.applyStatus == 10 ? 'pending' : 'signed'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
setList(res.list);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取客户数据失败:', error);
|
console.error('获取客户数据失败:', error);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [activeTab]);
|
||||||
|
|
||||||
|
|
||||||
// 根据当前Tab和搜索条件筛选数据
|
// 根据搜索条件筛选数据(状态筛选已在API层面处理)
|
||||||
const getFilteredList = () => {
|
const getFilteredList = () => {
|
||||||
console.log('TABS',activeTab)
|
|
||||||
let filteredList = list;
|
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()) {
|
if (searchValue.trim()) {
|
||||||
const keyword = searchValue.trim().toLowerCase();
|
const keyword = searchValue.trim().toLowerCase();
|
||||||
@@ -90,22 +79,36 @@ const CustomerIndex = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 获取各状态的统计数量
|
// 获取各状态的统计数量
|
||||||
const getStatusCounts = () => {
|
const [statusCounts, setStatusCounts] = useState({
|
||||||
const counts = {
|
all: 0,
|
||||||
all: list.length,
|
pending: 0,
|
||||||
pending: 0,
|
signed: 0,
|
||||||
signed: 0,
|
cancelled: 0
|
||||||
cancelled: 0
|
});
|
||||||
};
|
|
||||||
|
|
||||||
list.forEach(customer => {
|
// 获取所有状态的统计数量
|
||||||
if (customer.customerStatus && counts.hasOwnProperty(customer.customerStatus)) {
|
const fetchStatusCounts = useCallback(async () => {
|
||||||
counts[customer.customerStatus]++;
|
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) => {
|
const handleCancel = (customer: ShopDealerApply) => {
|
||||||
@@ -120,7 +123,13 @@ const CustomerIndex = () => {
|
|||||||
// 初始化数据
|
// 初始化数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchCustomerData();
|
fetchCustomerData();
|
||||||
}, [fetchCustomerData]);
|
fetchStatusCounts();
|
||||||
|
}, [fetchCustomerData, fetchStatusCounts]);
|
||||||
|
|
||||||
|
// 当activeTab变化时重新获取数据
|
||||||
|
useEffect(() => {
|
||||||
|
fetchCustomerData(activeTab);
|
||||||
|
}, [activeTab]);
|
||||||
|
|
||||||
// 渲染客户项
|
// 渲染客户项
|
||||||
const renderCustomerItem = (customer: CustomerUser) => (
|
const renderCustomerItem = (customer: CustomerUser) => (
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 临时函数:生成随机状态(实际项目中应该删除,从数据库获取真实状态)
|
* 临时函数:生成随机状态(实际项目中应该删除,从数据库获取真实状态)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user