feat(dealer): 添加客户保护期逻辑并优化相关功能
- 在客户列表和添加页面增加保护期相关功能 - 优化客户数据获取和展示,添加保护天数计算 - 调整添加客户的逻辑,增加对保护期的判断 - 更新环境配置,使用本地API地址
This commit is contained in:
@@ -16,9 +16,10 @@ import FixedButton from "@/components/FixedButton";
|
||||
import navTo from "@/utils/common";
|
||||
import {pageShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply";
|
||||
|
||||
// 扩展User类型,添加客户状态
|
||||
// 扩展User类型,添加客户状态和保护天数
|
||||
interface CustomerUser extends UserType {
|
||||
customerStatus?: CustomerStatus;
|
||||
protectDays?: number; // 剩余保护天数
|
||||
}
|
||||
|
||||
const CustomerIndex = () => {
|
||||
@@ -32,6 +33,43 @@ const CustomerIndex = () => {
|
||||
// Tab配置
|
||||
const tabList = getStatusOptions();
|
||||
|
||||
// 计算剩余保护天数
|
||||
const calculateProtectDays = (applyTime: string): number => {
|
||||
if (!applyTime) return 0;
|
||||
|
||||
try {
|
||||
// 确保日期格式正确解析
|
||||
const applyDate = new Date(applyTime.replace(/-/g, '/'));
|
||||
const currentDate = new Date();
|
||||
const protectionPeriod = 7; // 保护期7天
|
||||
|
||||
// 调试信息
|
||||
console.log('申请时间:', applyTime);
|
||||
console.log('解析后的申请日期:', applyDate);
|
||||
console.log('当前日期:', currentDate);
|
||||
|
||||
// 计算保护期结束时间
|
||||
const protectionEndDate = new Date(applyDate);
|
||||
protectionEndDate.setDate(protectionEndDate.getDate() + protectionPeriod);
|
||||
|
||||
console.log('保护期结束时间:', protectionEndDate);
|
||||
|
||||
// 计算剩余毫秒数
|
||||
const remainingMs = protectionEndDate.getTime() - currentDate.getTime();
|
||||
|
||||
// 转换为天数,向上取整
|
||||
const remainingDays = Math.ceil(remainingMs / (1000 * 60 * 60 * 24));
|
||||
|
||||
console.log('剩余天数:', remainingDays);
|
||||
|
||||
// 如果剩余天数小于0,返回0
|
||||
return Math.max(0, remainingDays);
|
||||
} catch (error) {
|
||||
console.error('日期计算错误:', error);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 获取客户数据
|
||||
const fetchCustomerData = useCallback(async (statusFilter?: CustomerStatus, resetPage = false, targetPage?: number) => {
|
||||
@@ -52,10 +90,11 @@ const CustomerIndex = () => {
|
||||
const res = await pageShopDealerApply(params);
|
||||
|
||||
if (res?.list && res.list.length > 0) {
|
||||
// 正确映射状态
|
||||
// 正确映射状态并计算保护天数
|
||||
const mappedList = res.list.map(customer => ({
|
||||
...customer,
|
||||
customerStatus: mapApplyStatusToCustomerStatus(customer.applyStatus || 10)
|
||||
customerStatus: mapApplyStatusToCustomerStatus(customer.applyStatus || 10),
|
||||
protectDays: calculateProtectDays(customer.applyTime || customer.createTime || '')
|
||||
}));
|
||||
|
||||
// 如果是重置页面或第一页,直接设置新数据;否则追加数据
|
||||
@@ -214,11 +253,32 @@ const CustomerIndex = () => {
|
||||
<Text className="text-xs text-gray-500">
|
||||
添加时间:{customer.createTime}
|
||||
</Text>
|
||||
{/* 保护天数显示 */}
|
||||
{customer.applyStatus === 10 && (
|
||||
<View className="flex items-center mt-1">
|
||||
<Text className="text-xs text-gray-500 mr-2">保护期:</Text>
|
||||
{customer.protectDays && customer.protectDays > 0 ? (
|
||||
<Text className={`text-xs px-2 py-1 rounded ${
|
||||
customer.protectDays <= 2
|
||||
? 'bg-red-100 text-red-600'
|
||||
: customer.protectDays <= 4
|
||||
? 'bg-orange-100 text-orange-600'
|
||||
: 'bg-green-100 text-green-600'
|
||||
}`}>
|
||||
剩余{customer.protectDays}天
|
||||
</Text>
|
||||
) : (
|
||||
<Text className="text-xs px-2 py-1 rounded bg-gray-100 text-gray-500">
|
||||
已过期
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 跟进中状态显示操作按钮 */}
|
||||
{customer.applyStatus === 10 && (
|
||||
{(customer.applyStatus === 10 && customer.userId == Taro.getStorageSync('UserId')) && (
|
||||
<Space className="flex justify-end">
|
||||
<Button
|
||||
size="small"
|
||||
|
||||
Reference in New Issue
Block a user