feat(dealer): 优化客户保护期逻辑并添加删除功能
- 新增计算保护期过期时间的方法 - 修改提交逻辑,增加过期时间字段 - 优化保护天数计算逻辑,优先使用过期时间 - 添加客户删除功能 - 调整客户列表显示逻辑
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ export interface ShopDealerApply {
|
|||||||
createTime?: string;
|
createTime?: string;
|
||||||
// 修改时间
|
// 修改时间
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
|
// 过期时间
|
||||||
|
expirationTime?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -108,23 +108,40 @@ const AddShopDealerApply = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
|
// 计算保护期过期时间(7天后)
|
||||||
|
const calculateExpirationTime = (): string => {
|
||||||
|
const now = new Date();
|
||||||
|
const expirationDate = new Date(now);
|
||||||
|
expirationDate.setDate(now.getDate() + 7); // 7天后
|
||||||
|
|
||||||
|
// 格式化为数据库需要的格式:YYYY-MM-DD HH:mm:ss
|
||||||
|
const year = expirationDate.getFullYear();
|
||||||
|
const month = String(expirationDate.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(expirationDate.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(expirationDate.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(expirationDate.getMinutes()).padStart(2, '0');
|
||||||
|
const seconds = String(expirationDate.getSeconds()).padStart(2, '0');
|
||||||
|
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
|
};
|
||||||
|
|
||||||
const submitSucceed = async (values: any) => {
|
const submitSucceed = async (values: any) => {
|
||||||
try {
|
try {
|
||||||
// 检查客户是否已存在
|
// 检查客户是否已存在
|
||||||
const res = await pageShopDealerApply({dealerName: values.dealerName, type: 4});
|
const res = await pageShopDealerApply({dealerName: values.dealerName, type: 4, applyStatus: 10});
|
||||||
|
|
||||||
if (res && res.count > 0) {
|
if (res && res.count > 0) {
|
||||||
const existingCustomer = res.list[0];
|
const existingCustomer = res.list[0];
|
||||||
|
|
||||||
// 检查是否在7天保护期内
|
// 检查是否在7天保护期内
|
||||||
if (existingCustomer.applyTime) {
|
if (!isEditMode && existingCustomer.applyTime) {
|
||||||
// 将申请时间字符串转换为时间戳进行比较
|
// 将申请时间字符串转换为时间戳进行比较
|
||||||
const applyTimeStamp = new Date(existingCustomer.applyTime).getTime();
|
const applyTimeStamp = new Date(existingCustomer.applyTime).getTime();
|
||||||
const currentTimeStamp = new Date().getTime();
|
const currentTimeStamp = new Date().getTime();
|
||||||
const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; // 7天的毫秒数
|
const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; // 7天的毫秒数
|
||||||
|
|
||||||
// 如果在7天保护期内,不允许重复添加
|
// 如果在7天保护期内,不允许重复添加
|
||||||
if (!isEditMode && currentTimeStamp - applyTimeStamp < sevenDaysInMs) {
|
if (currentTimeStamp - applyTimeStamp < sevenDaysInMs) {
|
||||||
const remainingDays = Math.ceil((sevenDaysInMs - (currentTimeStamp - applyTimeStamp)) / (24 * 60 * 60 * 1000));
|
const remainingDays = Math.ceil((sevenDaysInMs - (currentTimeStamp - applyTimeStamp)) / (24 * 60 * 60 * 1000));
|
||||||
|
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
@@ -156,17 +173,13 @@ const AddShopDealerApply = () => {
|
|||||||
}
|
}
|
||||||
// 用户确认后继续执行添加逻辑
|
// 用户确认后继续执行添加逻辑
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 没有申请时间,按已存在处理
|
|
||||||
Taro.showToast({
|
|
||||||
title: '该客户已存在',
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 计算过期时间
|
||||||
|
const expirationTime = isEditMode ? existingApply?.expirationTime : calculateExpirationTime();
|
||||||
|
|
||||||
// 准备提交的数据
|
// 准备提交的数据
|
||||||
const submitData = {
|
const submitData = {
|
||||||
...values,
|
...values,
|
||||||
@@ -174,13 +187,22 @@ const AddShopDealerApply = () => {
|
|||||||
realName: values.realName || user?.nickname,
|
realName: values.realName || user?.nickname,
|
||||||
mobile: user?.phone,
|
mobile: user?.phone,
|
||||||
refereeId: 33534,
|
refereeId: 33534,
|
||||||
applyStatus: 10,
|
applyStatus: isEditMode ? 20 : 10,
|
||||||
auditTime: undefined,
|
auditTime: undefined,
|
||||||
|
// 设置保护期过期时间(7天后)
|
||||||
|
expirationTime: expirationTime,
|
||||||
// 确保日期数据正确提交(使用数据库格式)
|
// 确保日期数据正确提交(使用数据库格式)
|
||||||
applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''),
|
applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''),
|
||||||
contractTime: values.contractTime || (contractTime ? formatDateForDatabase(contractTime) : '')
|
contractTime: values.contractTime || (contractTime ? formatDateForDatabase(contractTime) : '')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 调试信息
|
||||||
|
console.log('=== 提交数据调试 ===');
|
||||||
|
console.log('是否编辑模式:', isEditMode);
|
||||||
|
console.log('计算的过期时间:', expirationTime);
|
||||||
|
console.log('提交的数据:', submitData);
|
||||||
|
console.log('==================');
|
||||||
|
|
||||||
// 如果是编辑模式,添加现有申请的id
|
// 如果是编辑模式,添加现有申请的id
|
||||||
if (isEditMode && existingApply?.applyId) {
|
if (isEditMode && existingApply?.applyId) {
|
||||||
submitData.applyId = existingApply.applyId;
|
submitData.applyId = existingApply.applyId;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
} 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";
|
||||||
import {pageShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply";
|
import {pageShopDealerApply, removeShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply";
|
||||||
|
|
||||||
// 扩展User类型,添加客户状态和保护天数
|
// 扩展User类型,添加客户状态和保护天数
|
||||||
interface CustomerUser extends UserType {
|
interface CustomerUser extends UserType {
|
||||||
@@ -33,36 +33,62 @@ const CustomerIndex = () => {
|
|||||||
// Tab配置
|
// Tab配置
|
||||||
const tabList = getStatusOptions();
|
const tabList = getStatusOptions();
|
||||||
|
|
||||||
// 计算剩余保护天数
|
// 计算剩余保护天数(基于过期时间)
|
||||||
const calculateProtectDays = (applyTime: string): number => {
|
const calculateProtectDays = (expirationTime?: string, applyTime?: string): number => {
|
||||||
if (!applyTime) return 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 确保日期格式正确解析
|
// 优先使用过期时间字段
|
||||||
const applyDate = new Date(applyTime.replace(/-/g, '/'));
|
if (expirationTime) {
|
||||||
const currentDate = new Date();
|
const expDate = new Date(expirationTime.replace(' ', 'T'));
|
||||||
const protectionPeriod = 7; // 保护期7天
|
const now = new Date();
|
||||||
|
|
||||||
// 调试信息
|
|
||||||
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 remainingMs = expDate.getTime() - now.getTime();
|
||||||
|
|
||||||
// 转换为天数,向上取整
|
// 转换为天数,向上取整
|
||||||
const remainingDays = Math.ceil(remainingMs / (1000 * 60 * 60 * 24));
|
const remainingDays = Math.ceil(remainingMs / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
console.log('=== 基于过期时间计算 ===');
|
||||||
|
console.log('过期时间:', expirationTime);
|
||||||
|
console.log('当前时间:', now.toLocaleString());
|
||||||
console.log('剩余天数:', remainingDays);
|
console.log('剩余天数:', remainingDays);
|
||||||
|
console.log('======================');
|
||||||
|
|
||||||
|
return Math.max(0, remainingDays);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有过期时间,回退到基于申请时间计算
|
||||||
|
if (!applyTime) return 0;
|
||||||
|
|
||||||
|
const protectionPeriod = 7; // 保护期7天
|
||||||
|
|
||||||
|
// 解析申请时间
|
||||||
|
let applyDate: Date;
|
||||||
|
if (applyTime.includes('T')) {
|
||||||
|
applyDate = new Date(applyTime);
|
||||||
|
} else {
|
||||||
|
applyDate = new Date(applyTime.replace(' ', 'T'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前时间
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
// 只比较日期部分,忽略时间
|
||||||
|
const applyDateOnly = new Date(applyDate.getFullYear(), applyDate.getMonth(), applyDate.getDate());
|
||||||
|
const currentDateOnly = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||||
|
|
||||||
|
// 计算已经过去的天数
|
||||||
|
const timeDiff = currentDateOnly.getTime() - applyDateOnly.getTime();
|
||||||
|
const daysPassed = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
// 计算剩余保护天数
|
||||||
|
const remainingDays = protectionPeriod - daysPassed;
|
||||||
|
|
||||||
|
console.log('=== 基于申请时间计算 ===');
|
||||||
|
console.log('申请时间:', applyTime);
|
||||||
|
console.log('已过去天数:', daysPassed);
|
||||||
|
console.log('剩余保护天数:', remainingDays);
|
||||||
|
console.log('======================');
|
||||||
|
|
||||||
// 如果剩余天数小于0,返回0
|
|
||||||
return Math.max(0, remainingDays);
|
return Math.max(0, remainingDays);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('日期计算错误:', error);
|
console.error('日期计算错误:', error);
|
||||||
@@ -94,7 +120,7 @@ const CustomerIndex = () => {
|
|||||||
const mappedList = res.list.map(customer => ({
|
const mappedList = res.list.map(customer => ({
|
||||||
...customer,
|
...customer,
|
||||||
customerStatus: mapApplyStatusToCustomerStatus(customer.applyStatus || 10),
|
customerStatus: mapApplyStatusToCustomerStatus(customer.applyStatus || 10),
|
||||||
protectDays: calculateProtectDays(customer.applyTime || customer.createTime || '')
|
protectDays: calculateProtectDays(customer.expirationTime, customer.applyTime || customer.createTime || '')
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 如果是重置页面或第一页,直接设置新数据;否则追加数据
|
// 如果是重置页面或第一页,直接设置新数据;否则追加数据
|
||||||
@@ -203,6 +229,22 @@ const CustomerIndex = () => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
const handleDelete = (customer: ShopDealerApply) => {
|
||||||
|
removeShopDealerApply(customer.applyId).then(() => {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '删除成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
// 刷新当前tab的数据
|
||||||
|
setList([]);
|
||||||
|
setPage(1);
|
||||||
|
setHasMore(true);
|
||||||
|
fetchCustomerData(activeTab, true).then();
|
||||||
|
fetchStatusCounts().then();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchCustomerData(activeTab, true).then();
|
fetchCustomerData(activeTab, true).then();
|
||||||
@@ -235,7 +277,7 @@ const CustomerIndex = () => {
|
|||||||
<View className="flex-1">
|
<View className="flex-1">
|
||||||
<View className="flex items-center justify-between mb-1">
|
<View className="flex items-center justify-between mb-1">
|
||||||
<Text className="font-semibold text-gray-800 mr-2">
|
<Text className="font-semibold text-gray-800 mr-2">
|
||||||
{customer.realName || customer.dealerName || customer.dealerCode}
|
{customer.dealerName}
|
||||||
</Text>
|
</Text>
|
||||||
{customer.customerStatus && (
|
{customer.customerStatus && (
|
||||||
<Tag type={getStatusTagType(customer.customerStatus)}>
|
<Tag type={getStatusTagType(customer.customerStatus)}>
|
||||||
@@ -296,6 +338,17 @@ const CustomerIndex = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
)}
|
)}
|
||||||
|
{(customer.applyStatus === 30 && customer.userId == Taro.getStorageSync('UserId')) && (
|
||||||
|
<Space className="flex justify-end">
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
onClick={() => handleDelete(customer)}
|
||||||
|
style={{backgroundColor: '#ff4d4f', color: 'white'}}
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user