From 8d67732c7a63a4b7f4b518f32b5f5122c4f7e976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Wed, 21 Jan 2026 17:42:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(dealer):=20=E8=B0=83=E6=95=B4=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E6=8A=A5=E5=A4=87=E5=8A=9F=E8=83=BD=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=88=BF=E5=8F=B7=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 useUser hook 的使用,不再依赖用户信息 - 新增房号信息处理函数:buildHouseKey、buildHouseDisplay 和 parseHouseKey - 添加房号相关必填字段校验(小区、楼栋号、房号、姓名) - 修改报备逻辑:使用房号作为唯一键进行重复检查 - 优化报备保护期逻辑:区分已签约/已取消和跟进中的状态 - 调整表单字段:将公司信息改为小区楼栋房号信息 - 更新数据提交格式:dealerName 存储展示文案,dealerCode 存储唯一键 - 添加编辑模式下房号信息的回填功能 - 移除对用户ID的依赖,简化报备流程 --- src/api/shop/shopDealerApply/model/index.ts | 1 + src/dealer/customer/add.tsx | 167 ++++++++++++++------ 2 files changed, 124 insertions(+), 44 deletions(-) diff --git a/src/api/shop/shopDealerApply/model/index.ts b/src/api/shop/shopDealerApply/model/index.ts index 3187633..05353c6 100644 --- a/src/api/shop/shopDealerApply/model/index.ts +++ b/src/api/shop/shopDealerApply/model/index.ts @@ -57,6 +57,7 @@ export interface ShopDealerApplyParam extends PageParam { applyId?: number; type?: number; dealerName?: string; + dealerCode?: string; mobile?: string; userId?: number; keywords?: string; diff --git a/src/dealer/customer/add.tsx b/src/dealer/customer/add.tsx index b6f5563..746337f 100644 --- a/src/dealer/customer/add.tsx +++ b/src/dealer/customer/add.tsx @@ -5,7 +5,6 @@ import Taro from '@tarojs/taro' import {useRouter} from '@tarojs/taro' import {View, Text} from '@tarojs/components' import FixedButton from "@/components/FixedButton"; -import {useUser} from "@/hooks/useUser"; import {ShopDealerApply} from "@/api/shop/shopDealerApply/model"; import { addShopDealerApply, getShopDealerApply, pageShopDealerApply, @@ -19,7 +18,6 @@ import {ShopDealerUser} from "@/api/shop/shopDealerUser/model"; import {getShopDealerUser, pageShopDealerUser} from "@/api/shop/shopDealerUser"; const AddShopDealerApply = () => { - const {user} = useUser() const {params} = useRouter(); const [loading, setLoading] = useState(true) const [FormData, setFormData] = useState() @@ -28,6 +26,33 @@ const AddShopDealerApply = () => { const [existingApply, setExistingApply] = useState(null) const [referee, setReferee] = useState() + // 房号信息:用 dealerCode 存储唯一键,dealerName 存储展示文案 + const buildHouseKey = (community: string, buildingNo: string, unitNo: string | undefined, roomNo: string) => { + const c = (community || '').trim(); + const b = (buildingNo || '').trim(); + const u = (unitNo || '').trim(); + const r = (roomNo || '').trim(); + return [c, b, u, r].join('|'); + }; + + const buildHouseDisplay = (community: string, buildingNo: string, unitNo: string | undefined, roomNo: string) => { + const c = (community || '').trim(); + const b = (buildingNo || '').trim(); + const u = (unitNo || '').trim(); + const r = (roomNo || '').trim(); + return `${c}${b ? `${b}栋` : ''}${u ? `${u}单元` : ''}${r ? `${r}号` : ''}`; + }; + + const parseHouseKey = (key?: string) => { + const parts = (key || '').split('|'); + return { + community: parts[0] || '', + buildingNo: parts[1] || '', + unitNo: parts[2] || '', + roomNo: parts[3] || '', + }; + }; + // 日期选择器状态 const [showApplyTimePicker, setShowApplyTimePicker] = useState(false) const [showContractTimePicker, setShowContractTimePicker] = useState(false) @@ -136,6 +161,24 @@ const AddShopDealerApply = () => { const submitSucceed = async (values: any) => { try { + // 房号相关必填校验 + if (!values.address || values.address.trim() === '') { + Taro.showToast({title: '请选择/填写小区', icon: 'error'}); + return; + } + if (!values.buildingNo || values.buildingNo.trim() === '') { + Taro.showToast({title: '请填写楼栋号', icon: 'error'}); + return; + } + if (!values.roomNo || values.roomNo.trim() === '') { + Taro.showToast({title: '请填写房号', icon: 'error'}); + return; + } + if (!values.realName || values.realName.trim() === '') { + Taro.showToast({title: '请填写姓名', icon: 'error'}); + return; + } + // 验证必填字段 if (!values.mobile || values.mobile.trim() === '') { Taro.showToast({ @@ -167,51 +210,63 @@ const AddShopDealerApply = () => { } } - // 检查客户是否已存在 - const res = await pageShopDealerApply({dealerName: values.dealerName, type: 4, applyStatus: 10}); + const houseKey = buildHouseKey(values.address, values.buildingNo, values.unitNo, values.roomNo); + const houseDisplay = buildHouseDisplay(values.address, values.buildingNo, values.unitNo, values.roomNo); + + // 检查房号是否已报备 + const res = await pageShopDealerApply({dealerCode: houseKey, type: 4}); if (res && res.count > 0) { const existingCustomer = res.list[0]; - // 检查是否在7天保护期内 - if (!isEditMode && existingCustomer.applyTime) { - // 将申请时间字符串转换为时间戳进行比较 - const applyTimeStamp = new Date(existingCustomer.applyTime).getTime(); - const currentTimeStamp = new Date().getTime(); - const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; // 7天的毫秒数 - - // 如果在7天保护期内,不允许重复添加 - if (currentTimeStamp - applyTimeStamp < sevenDaysInMs) { - const remainingDays = Math.ceil((sevenDaysInMs - (currentTimeStamp - applyTimeStamp)) / (24 * 60 * 60 * 1000)); - + if (!isEditMode) { + // 已签约/已取消:直接提示已报备 + if (existingCustomer.applyStatus && existingCustomer.applyStatus !== 10) { Taro.showToast({ - title: `该客户还在保护期,还需等待${remainingDays}天后才能重新添加`, + title: `该房号信息已报备(${getApplyStatusText(existingCustomer.applyStatus)})`, icon: 'none', - duration: 3000 + duration: 2500 }); return false; - } else { - // 超过7天保护期,可以重新添加,显示确认对话框 + } + + // 跟进中:保留 7 天保护期逻辑 + if (existingCustomer.applyTime) { + const applyTimeStamp = new Date(existingCustomer.applyTime).getTime(); + const currentTimeStamp = new Date().getTime(); + const sevenDaysInMs = 7 * 24 * 60 * 60 * 1000; + + if (currentTimeStamp - applyTimeStamp < sevenDaysInMs) { + const remainingDays = Math.ceil((sevenDaysInMs - (currentTimeStamp - applyTimeStamp)) / (24 * 60 * 60 * 1000)); + Taro.showToast({ + title: `该房号信息已报备,保护期剩余${remainingDays}天`, + icon: 'none', + duration: 3000 + }); + return false; + } + + // 超过保护期:询问是否重新报备 const modalResult = await new Promise((resolve) => { Taro.showModal({ title: '提示', - content: '该客户已超过7天保护期,是否重新添加跟进?', + content: '该房号已超过7天保护期,是否重新报备跟进?', showCancel: true, cancelText: '取消', confirmText: '确定', - success: (modalRes) => { - resolve(modalRes.confirm); - }, - fail: () => { - resolve(false); - } + success: (modalRes) => resolve(modalRes.confirm), + fail: () => resolve(false) }); }); - if (!modalResult) { - return false; // 用户取消,不继续执行 - } - // 用户确认后继续执行添加逻辑 + if (!modalResult) return false; + } else { + Taro.showToast({ + title: '该房号信息已报备', + icon: 'none', + duration: 2500 + }); + return false; } } } @@ -221,10 +276,17 @@ const AddShopDealerApply = () => { const expirationTime = isEditMode ? existingApply?.expirationTime : calculateExpirationTime(); // 准备提交的数据 + // 避免把表单里的楼栋/单元/房号等临时字段原样提交给后端 + const {buildingNo, unitNo, roomNo, ...restValues} = values; const submitData = { - ...values, + ...restValues, type: 4, - realName: values.realName || user?.nickname, + // 展示用:小区+楼栋+单元+房号 + dealerName: houseDisplay, + // 唯一键:用于后续重复报备提示 + dealerCode: houseKey, + // 客户姓名/手机号 + realName: values.realName, mobile: values.mobile, refereeId: referee?.refereeId, applyStatus: isEditMode ? 20 : 10, @@ -296,6 +358,21 @@ const AddShopDealerApply = () => { }) }, []); // 依赖用户ID,当用户变化时重新加载 + // 编辑模式下,从 dealerCode 反解出楼栋/单元/房号,回填表单(只读展示) + useEffect(() => { + if (!formRef.current || !FormData) return; + const parsed = parseHouseKey(FormData.dealerCode); + formRef.current.setFieldsValue({ + address: parsed.community || FormData.address, + buildingNo: parsed.buildingNo, + unitNo: parsed.unitNo, + roomNo: parsed.roomNo, + realName: FormData.realName, + mobile: FormData.mobile, + userId: FormData.userId + }); + }, [FormData]); + if (loading) { return 加载中 } @@ -312,21 +389,24 @@ const AddShopDealerApply = () => { > - - + + - - + + - + + + + + + + + + + - - - - - - {isEditMode && ( <> @@ -368,7 +448,6 @@ const AddShopDealerApply = () => { placeholder="自己报备请留空" disabled={isEditMode} type="number" - value={(FormData?.userId)?.toString() || ''} />