From 8b20d6c7c213318b7ea04ca3ee184edbbc5ad264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Fri, 12 Sep 2025 13:43:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(dealer):=20=E6=B7=BB=E5=8A=A0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E4=BF=9D=E6=8A=A4=E6=9C=9F=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在客户列表和添加页面增加保护期相关功能 - 优化客户数据获取和展示,添加保护天数计算 - 调整添加客户的逻辑,增加对保护期的判断 - 更新环境配置,使用本地API地址 --- config/env.ts | 2 +- src/dealer/customer/add.tsx | 251 ++++++++++++++++++++-------------- src/dealer/customer/index.tsx | 68 ++++++++- 3 files changed, 212 insertions(+), 109 deletions(-) diff --git a/config/env.ts b/config/env.ts index de8e281..c3f95e2 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,7 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'https://cms-api.websoft.top/api', + API_BASE_URL: 'http://127.0.0.1:9200/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/dealer/customer/add.tsx b/src/dealer/customer/add.tsx index f9b9ba7..fa6ee92 100644 --- a/src/dealer/customer/add.tsx +++ b/src/dealer/customer/add.tsx @@ -1,9 +1,9 @@ import {useEffect, useState, useRef} from "react"; 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 {useRouter} from '@tarojs/taro' -import {View} from '@tarojs/components' +import {View, Text} from '@tarojs/components' import FixedButton from "@/components/FixedButton"; import {useUser} from "@/hooks/useUser"; import {ShopDealerApply} from "@/api/shop/shopDealerApply/model"; @@ -13,7 +13,7 @@ import { } from "@/api/shop/shopDealerApply"; import { formatDateForDatabase, - extractDateForCalendar + extractDateForCalendar, formatDateForDisplay } from "@/utils/dateUtils"; const AddShopDealerApply = () => { @@ -45,6 +45,7 @@ const AddShopDealerApply = () => { } } + console.log(getApplyStatusText) // 处理签约时间选择 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) { - 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) : '') - }; + if (res && res.count > 0) { + const existingCustomer = res.list[0]; - // 如果是编辑模式,添加现有申请的id - if (isEditMode && existingApply?.applyId) { - submitData.applyId = existingApply.applyId; - } + // 检查是否在7天保护期内 + if (existingCustomer.applyTime) { + // 将申请时间字符串转换为时间戳进行比较 + const applyTimeStamp = new Date(existingCustomer.applyTime).getTime(); + const currentTimeStamp = new Date().getTime(); + const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; // 7天的毫秒数 - // 执行新增或更新操作 - if (isEditMode) { - updateShopDealerApply(submitData); + // 如果在7天保护期内,不允许重复添加 + if (!isEditMode && currentTimeStamp - applyTimeStamp < sevenDaysInMs) { + 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((resolve) => { + Taro.showModal({ + title: '提示', + content: '该客户已超过7天保护期,是否重新添加跟进?', + showCancel: true, + cancelText: '取消', + confirmText: '确定', + success: (modalRes) => { + resolve(modalRes.confirm); + }, + fail: () => { + resolve(false); + } + }); + }); + + if (!modalResult) { + return false; // 用户取消,不继续执行 + } + // 用户确认后继续执行添加逻辑 + } } 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 = () => { - {/**/} - {/* */} - {/**/} - {/**/} - {/* !isEditMode && setShowApplyTimePicker(true)}*/} - {/* style={{*/} - {/* cursor: isEditMode ? 'not-allowed' : 'pointer',*/} - {/* opacity: isEditMode ? 0.6 : 1*/} - {/* }}*/} - {/* >*/} - {/* */} - {/* */} - {/* */} - {/* {applyTime ? formatDateForDisplay(applyTime) : '请选择签约时间'}*/} - {/* */} - {/* */} - {/* */} - {/**/} - {/**/} - {/* !isEditMode && setShowContractTimePicker(true)}*/} - {/* style={{*/} - {/* cursor: isEditMode ? 'not-allowed' : 'pointer',*/} - {/* opacity: isEditMode ? 0.6 : 1*/} - {/* }}*/} - {/* >*/} - {/* */} - {/* */} - {/* */} - {/* {contractTime ? formatDateForDisplay(contractTime) : '请选择合同生效起止时间'}*/} - {/* */} - {/* */} - {/* */} - {/**/} - {/**/} - {/* */} - {/**/} + {isEditMode && ( + <> + + + + + setShowApplyTimePicker(true)} + > + + + + {applyTime ? formatDateForDisplay(applyTime) : '请选择签约时间'} + + + + + + setShowContractTimePicker(true)} + > + + + + {contractTime ? formatDateForDisplay(contractTime) : '请选择合同生效起止时间'} + + + + + {/**/} + {/* */} + {/**/} + + )} @@ -272,17 +316,17 @@ const AddShopDealerApply = () => { {/* 审核状态显示(仅在编辑模式下显示) */} {isEditMode && ( - - {getApplyStatusText(FormData?.applyStatus)} - - } - /> + {/**/} + {/* {getApplyStatusText(FormData?.applyStatus)}*/} + {/* */} + {/* }*/} + {/*/>*/} {FormData?.applyStatus === 20 && ( )} @@ -297,8 +341,7 @@ const AddShopDealerApply = () => { {(!isEditMode || FormData?.applyStatus === 10) && ( } - text={isEditMode ? '保存修改' : '确定签约'} - disabled={FormData?.applyStatus === 10} + text={'确定签约'} onClick={handleFixedButtonClick} /> )} diff --git a/src/dealer/customer/index.tsx b/src/dealer/customer/index.tsx index 31075b9..fd446da 100644 --- a/src/dealer/customer/index.tsx +++ b/src/dealer/customer/index.tsx @@ -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 = () => { 添加时间:{customer.createTime} + {/* 保护天数显示 */} + {customer.applyStatus === 10 && ( + + 保护期: + {customer.protectDays && customer.protectDays > 0 ? ( + + 剩余{customer.protectDays}天 + + ) : ( + + 已过期 + + )} + + )} {/* 跟进中状态显示操作按钮 */} - {customer.applyStatus === 10 && ( + {(customer.applyStatus === 10 && customer.userId == Taro.getStorageSync('UserId')) && (