feat(dealer): 添加客户保护期逻辑并优化相关功能
- 在客户列表和添加页面增加保护期相关功能 - 优化客户数据获取和展示,添加保护天数计算 - 调整添加客户的逻辑,增加对保护期的判断 - 更新环境配置,使用本地API地址
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {useEffect, useState, useRef} from "react";
|
import {useEffect, useState, useRef} from "react";
|
||||||
import {Loading, CellGroup, Cell, Input, Form, Calendar} from '@nutui/nutui-react-taro'
|
import {Loading, CellGroup, Cell, Input, Form, Calendar} from '@nutui/nutui-react-taro'
|
||||||
import {Edit} from '@nutui/icons-react-taro'
|
import {Edit, Calendar as CalendarIcon} from '@nutui/icons-react-taro'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import {useRouter} from '@tarojs/taro'
|
import {useRouter} from '@tarojs/taro'
|
||||||
import {View} from '@tarojs/components'
|
import {View, Text} from '@tarojs/components'
|
||||||
import FixedButton from "@/components/FixedButton";
|
import FixedButton from "@/components/FixedButton";
|
||||||
import {useUser} from "@/hooks/useUser";
|
import {useUser} from "@/hooks/useUser";
|
||||||
import {ShopDealerApply} from "@/api/shop/shopDealerApply/model";
|
import {ShopDealerApply} from "@/api/shop/shopDealerApply/model";
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "@/api/shop/shopDealerApply";
|
} from "@/api/shop/shopDealerApply";
|
||||||
import {
|
import {
|
||||||
formatDateForDatabase,
|
formatDateForDatabase,
|
||||||
extractDateForCalendar
|
extractDateForCalendar, formatDateForDisplay
|
||||||
} from "@/utils/dateUtils";
|
} from "@/utils/dateUtils";
|
||||||
|
|
||||||
const AddShopDealerApply = () => {
|
const AddShopDealerApply = () => {
|
||||||
@@ -45,6 +45,7 @@ const AddShopDealerApply = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(getApplyStatusText)
|
||||||
|
|
||||||
// 处理签约时间选择
|
// 处理签约时间选择
|
||||||
const handleApplyTimeConfirm = (param: string) => {
|
const handleApplyTimeConfirm = (param: string) => {
|
||||||
@@ -107,60 +108,107 @@ const AddShopDealerApply = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const submitSucceed = (values: any) => {
|
const submitSucceed = async (values: any) => {
|
||||||
|
try {
|
||||||
|
// 检查客户是否已存在
|
||||||
|
const res = await pageShopDealerApply({dealerName: values.dealerName, type: 4});
|
||||||
|
|
||||||
pageShopDealerApply({dealerName: values.dealerName, type: 4}).then((res) => {
|
if (res && res.count > 0) {
|
||||||
if (res && res?.count > 0) {
|
const existingCustomer = res.list[0];
|
||||||
Taro.showToast({
|
|
||||||
title: '该客户已存在',
|
|
||||||
icon: 'error'
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// 准备提交的数据
|
|
||||||
const submitData = {
|
|
||||||
...values,
|
|
||||||
type: 4,
|
|
||||||
realName: values.realName || user?.nickname,
|
|
||||||
mobile: user?.phone,
|
|
||||||
refereeId: 33534,
|
|
||||||
applyStatus: 10,
|
|
||||||
auditTime: undefined,
|
|
||||||
// 确保日期数据正确提交(使用数据库格式)
|
|
||||||
applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''),
|
|
||||||
contractTime: values.contractTime || (contractTime ? formatDateForDatabase(contractTime) : '')
|
|
||||||
};
|
|
||||||
|
|
||||||
// 如果是编辑模式,添加现有申请的id
|
// 检查是否在7天保护期内
|
||||||
if (isEditMode && existingApply?.applyId) {
|
if (existingCustomer.applyTime) {
|
||||||
submitData.applyId = existingApply.applyId;
|
// 将申请时间字符串转换为时间戳进行比较
|
||||||
}
|
const applyTimeStamp = new Date(existingCustomer.applyTime).getTime();
|
||||||
|
const currentTimeStamp = new Date().getTime();
|
||||||
|
const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; // 7天的毫秒数
|
||||||
|
|
||||||
// 执行新增或更新操作
|
// 如果在7天保护期内,不允许重复添加
|
||||||
if (isEditMode) {
|
if (!isEditMode && currentTimeStamp - applyTimeStamp < sevenDaysInMs) {
|
||||||
updateShopDealerApply(submitData);
|
const remainingDays = Math.ceil((sevenDaysInMs - (currentTimeStamp - applyTimeStamp)) / (24 * 60 * 60 * 1000));
|
||||||
|
|
||||||
|
Taro.showToast({
|
||||||
|
title: `该客户还在保护期,还需等待${remainingDays}天后才能重新添加`,
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
// 超过7天保护期,可以重新添加,显示确认对话框
|
||||||
|
const modalResult = await new Promise<boolean>((resolve) => {
|
||||||
|
Taro.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '该客户已超过7天保护期,是否重新添加跟进?',
|
||||||
|
showCancel: true,
|
||||||
|
cancelText: '取消',
|
||||||
|
confirmText: '确定',
|
||||||
|
success: (modalRes) => {
|
||||||
|
resolve(modalRes.confirm);
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!modalResult) {
|
||||||
|
return false; // 用户取消,不继续执行
|
||||||
|
}
|
||||||
|
// 用户确认后继续执行添加逻辑
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addShopDealerApply(submitData);
|
// 没有申请时间,按已存在处理
|
||||||
|
Taro.showToast({
|
||||||
|
title: '该客户已存在',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Taro.showToast({
|
|
||||||
title: `${isEditMode ? '提交' : '提交'}成功`,
|
|
||||||
icon: 'success'
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
Taro.navigateBack();
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('验证邀请人失败:', error);
|
|
||||||
return Taro.showToast({
|
|
||||||
title: '邀请人ID不存在',
|
|
||||||
icon: 'error'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
// 准备提交的数据
|
||||||
|
const submitData = {
|
||||||
|
...values,
|
||||||
|
type: 4,
|
||||||
|
realName: values.realName || user?.nickname,
|
||||||
|
mobile: user?.phone,
|
||||||
|
refereeId: 33534,
|
||||||
|
applyStatus: 10,
|
||||||
|
auditTime: undefined,
|
||||||
|
// 确保日期数据正确提交(使用数据库格式)
|
||||||
|
applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''),
|
||||||
|
contractTime: values.contractTime || (contractTime ? formatDateForDatabase(contractTime) : '')
|
||||||
|
};
|
||||||
|
|
||||||
|
// 如果是编辑模式,添加现有申请的id
|
||||||
|
if (isEditMode && existingApply?.applyId) {
|
||||||
|
submitData.applyId = existingApply.applyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行新增或更新操作
|
||||||
|
if (isEditMode) {
|
||||||
|
await updateShopDealerApply(submitData);
|
||||||
|
} else {
|
||||||
|
await addShopDealerApply(submitData);
|
||||||
|
}
|
||||||
|
|
||||||
|
Taro.showToast({
|
||||||
|
title: `${isEditMode ? '更新' : '提交'}成功`,
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
Taro.navigateBack();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('提交失败:', error);
|
||||||
|
Taro.showToast({
|
||||||
|
title: '提交失败,请重试',
|
||||||
|
icon: 'error'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理固定按钮点击事件
|
// 处理固定按钮点击事件
|
||||||
@@ -210,46 +258,42 @@ const AddShopDealerApply = () => {
|
|||||||
<Form.Item name="dealerCode" label="户号" initialValue={FormData?.dealerCode} required>
|
<Form.Item name="dealerCode" label="户号" initialValue={FormData?.dealerCode} required>
|
||||||
<Input placeholder="请填写户号" disabled={isEditMode}/>
|
<Input placeholder="请填写户号" disabled={isEditMode}/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{/*<Form.Item name="money" label="签约价格" initialValue={FormData?.money} required>*/}
|
{isEditMode && (
|
||||||
{/* <Input placeholder="(元/兆瓦时)" disabled={false}/>*/}
|
<>
|
||||||
{/*</Form.Item>*/}
|
<Form.Item name="money" label="签约价格" initialValue={FormData?.money} required>
|
||||||
{/*<Form.Item name="applyTime" label="签约时间" initialValue={FormData?.applyTime} required>*/}
|
<Input placeholder="(元/兆瓦时)" disabled={false}/>
|
||||||
{/* <View*/}
|
</Form.Item>
|
||||||
{/* className="flex items-center justify-between py-2"*/}
|
<Form.Item name="applyTime" label="签约时间" initialValue={FormData?.applyTime}>
|
||||||
{/* onClick={() => !isEditMode && setShowApplyTimePicker(true)}*/}
|
<View
|
||||||
{/* style={{*/}
|
className="flex items-center justify-between py-2"
|
||||||
{/* cursor: isEditMode ? 'not-allowed' : 'pointer',*/}
|
onClick={() => setShowApplyTimePicker(true)}
|
||||||
{/* opacity: isEditMode ? 0.6 : 1*/}
|
>
|
||||||
{/* }}*/}
|
<View className="flex items-center">
|
||||||
{/* >*/}
|
<CalendarIcon size={16} color="#999" className="mr-2"/>
|
||||||
{/* <View className="flex items-center">*/}
|
<Text style={{color: applyTime ? '#333' : '#999'}}>
|
||||||
{/* <CalendarIcon size={16} color="#999" className="mr-2" />*/}
|
{applyTime ? formatDateForDisplay(applyTime) : '请选择签约时间'}
|
||||||
{/* <Text style={{ color: applyTime ? '#333' : '#999' }}>*/}
|
</Text>
|
||||||
{/* {applyTime ? formatDateForDisplay(applyTime) : '请选择签约时间'}*/}
|
</View>
|
||||||
{/* </Text>*/}
|
</View>
|
||||||
{/* </View>*/}
|
</Form.Item>
|
||||||
{/* </View>*/}
|
<Form.Item name="contractTime" label="合同日期" initialValue={FormData?.contractTime}>
|
||||||
{/*</Form.Item>*/}
|
<View
|
||||||
{/*<Form.Item name="contractTime" label="合同日期" initialValue={FormData?.contractTime} required>*/}
|
className="flex items-center justify-between py-2"
|
||||||
{/* <View*/}
|
onClick={() => setShowContractTimePicker(true)}
|
||||||
{/* className="flex items-center justify-between py-2"*/}
|
>
|
||||||
{/* onClick={() => !isEditMode && setShowContractTimePicker(true)}*/}
|
<View className="flex items-center">
|
||||||
{/* style={{*/}
|
<CalendarIcon size={16} color="#999" className="mr-2"/>
|
||||||
{/* cursor: isEditMode ? 'not-allowed' : 'pointer',*/}
|
<Text style={{color: contractTime ? '#333' : '#999'}}>
|
||||||
{/* opacity: isEditMode ? 0.6 : 1*/}
|
{contractTime ? formatDateForDisplay(contractTime) : '请选择合同生效起止时间'}
|
||||||
{/* }}*/}
|
</Text>
|
||||||
{/* >*/}
|
</View>
|
||||||
{/* <View className="flex items-center">*/}
|
</View>
|
||||||
{/* <CalendarIcon size={16} color="#999" className="mr-2" />*/}
|
</Form.Item>
|
||||||
{/* <Text style={{ color: contractTime ? '#333' : '#999' }}>*/}
|
{/*<Form.Item name="refereeId" label="邀请人ID" initialValue={FormData?.refereeId} required>*/}
|
||||||
{/* {contractTime ? formatDateForDisplay(contractTime) : '请选择合同生效起止时间'}*/}
|
{/* <Input placeholder="邀请人ID"/>*/}
|
||||||
{/* </Text>*/}
|
{/*</Form.Item>*/}
|
||||||
{/* </View>*/}
|
</>
|
||||||
{/* </View>*/}
|
)}
|
||||||
{/*</Form.Item>*/}
|
|
||||||
{/*<Form.Item name="refereeId" label="邀请人ID" initialValue={FormData?.refereeId} required>*/}
|
|
||||||
{/* <Input placeholder="邀请人ID"/>*/}
|
|
||||||
{/*</Form.Item>*/}
|
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
@@ -272,17 +316,17 @@ const AddShopDealerApply = () => {
|
|||||||
{/* 审核状态显示(仅在编辑模式下显示) */}
|
{/* 审核状态显示(仅在编辑模式下显示) */}
|
||||||
{isEditMode && (
|
{isEditMode && (
|
||||||
<CellGroup>
|
<CellGroup>
|
||||||
<Cell
|
{/*<Cell*/}
|
||||||
title={'审核状态'}
|
{/* title={'审核状态'}*/}
|
||||||
extra={
|
{/* extra={*/}
|
||||||
<span style={{
|
{/* <span style={{*/}
|
||||||
color: FormData?.applyStatus === 20 ? '#52c41a' :
|
{/* color: FormData?.applyStatus === 20 ? '#52c41a' :*/}
|
||||||
FormData?.applyStatus === 30 ? '#ff4d4f' : '#faad14'
|
{/* FormData?.applyStatus === 30 ? '#ff4d4f' : '#faad14'*/}
|
||||||
}}>
|
{/* }}>*/}
|
||||||
{getApplyStatusText(FormData?.applyStatus)}
|
{/* {getApplyStatusText(FormData?.applyStatus)}*/}
|
||||||
</span>
|
{/* </span>*/}
|
||||||
}
|
{/* }*/}
|
||||||
/>
|
{/*/>*/}
|
||||||
{FormData?.applyStatus === 20 && (
|
{FormData?.applyStatus === 20 && (
|
||||||
<Cell title={'签约时间'} extra={FormData?.auditTime || '无'}/>
|
<Cell title={'签约时间'} extra={FormData?.auditTime || '无'}/>
|
||||||
)}
|
)}
|
||||||
@@ -297,8 +341,7 @@ const AddShopDealerApply = () => {
|
|||||||
{(!isEditMode || FormData?.applyStatus === 10) && (
|
{(!isEditMode || FormData?.applyStatus === 10) && (
|
||||||
<FixedButton
|
<FixedButton
|
||||||
icon={<Edit/>}
|
icon={<Edit/>}
|
||||||
text={isEditMode ? '保存修改' : '确定签约'}
|
text={'确定签约'}
|
||||||
disabled={FormData?.applyStatus === 10}
|
|
||||||
onClick={handleFixedButtonClick}
|
onClick={handleFixedButtonClick}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ import FixedButton from "@/components/FixedButton";
|
|||||||
import navTo from "@/utils/common";
|
import navTo from "@/utils/common";
|
||||||
import {pageShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply";
|
import {pageShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply";
|
||||||
|
|
||||||
// 扩展User类型,添加客户状态
|
// 扩展User类型,添加客户状态和保护天数
|
||||||
interface CustomerUser extends UserType {
|
interface CustomerUser extends UserType {
|
||||||
customerStatus?: CustomerStatus;
|
customerStatus?: CustomerStatus;
|
||||||
|
protectDays?: number; // 剩余保护天数
|
||||||
}
|
}
|
||||||
|
|
||||||
const CustomerIndex = () => {
|
const CustomerIndex = () => {
|
||||||
@@ -32,6 +33,43 @@ const CustomerIndex = () => {
|
|||||||
// Tab配置
|
// Tab配置
|
||||||
const tabList = getStatusOptions();
|
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) => {
|
const fetchCustomerData = useCallback(async (statusFilter?: CustomerStatus, resetPage = false, targetPage?: number) => {
|
||||||
@@ -52,10 +90,11 @@ const CustomerIndex = () => {
|
|||||||
const res = await pageShopDealerApply(params);
|
const res = await pageShopDealerApply(params);
|
||||||
|
|
||||||
if (res?.list && res.list.length > 0) {
|
if (res?.list && res.list.length > 0) {
|
||||||
// 正确映射状态
|
// 正确映射状态并计算保护天数
|
||||||
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 || '')
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 如果是重置页面或第一页,直接设置新数据;否则追加数据
|
// 如果是重置页面或第一页,直接设置新数据;否则追加数据
|
||||||
@@ -214,11 +253,32 @@ const CustomerIndex = () => {
|
|||||||
<Text className="text-xs text-gray-500">
|
<Text className="text-xs text-gray-500">
|
||||||
添加时间:{customer.createTime}
|
添加时间:{customer.createTime}
|
||||||
</Text>
|
</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>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 跟进中状态显示操作按钮 */}
|
{/* 跟进中状态显示操作按钮 */}
|
||||||
{customer.applyStatus === 10 && (
|
{(customer.applyStatus === 10 && customer.userId == Taro.getStorageSync('UserId')) && (
|
||||||
<Space className="flex justify-end">
|
<Space className="flex justify-end">
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
|
|||||||
Reference in New Issue
Block a user