diff --git a/config/env.ts b/config/env.ts index c3f95e2..de8e281 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,7 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'http://127.0.0.1:9200/api', + API_BASE_URL: 'https://cms-api.websoft.top/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/api/shop/shopDealerApply/model/index.ts b/src/api/shop/shopDealerApply/model/index.ts index 1d7c0d4..8a5c2a5 100644 --- a/src/api/shop/shopDealerApply/model/index.ts +++ b/src/api/shop/shopDealerApply/model/index.ts @@ -40,6 +40,8 @@ export interface ShopDealerApply { createTime?: string; // 修改时间 updateTime?: string; + // 过期时间 + expirationTime?: string; } /** diff --git a/src/dealer/customer/add.tsx b/src/dealer/customer/add.tsx index fa6ee92..0f55327 100644 --- a/src/dealer/customer/add.tsx +++ b/src/dealer/customer/add.tsx @@ -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) => { 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) { const existingCustomer = res.list[0]; // 检查是否在7天保护期内 - if (existingCustomer.applyTime) { + 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 (!isEditMode && currentTimeStamp - applyTimeStamp < sevenDaysInMs) { + if (currentTimeStamp - applyTimeStamp < sevenDaysInMs) { const remainingDays = Math.ceil((sevenDaysInMs - (currentTimeStamp - applyTimeStamp)) / (24 * 60 * 60 * 1000)); Taro.showToast({ @@ -156,17 +173,13 @@ const AddShopDealerApply = () => { } // 用户确认后继续执行添加逻辑 } - } else { - // 没有申请时间,按已存在处理 - Taro.showToast({ - title: '该客户已存在', - icon: 'none' - }); - return false; } } + // 计算过期时间 + const expirationTime = isEditMode ? existingApply?.expirationTime : calculateExpirationTime(); + // 准备提交的数据 const submitData = { ...values, @@ -174,13 +187,22 @@ const AddShopDealerApply = () => { realName: values.realName || user?.nickname, mobile: user?.phone, refereeId: 33534, - applyStatus: 10, + applyStatus: isEditMode ? 20 : 10, auditTime: undefined, + // 设置保护期过期时间(7天后) + expirationTime: expirationTime, // 确保日期数据正确提交(使用数据库格式) applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''), contractTime: values.contractTime || (contractTime ? formatDateForDatabase(contractTime) : '') }; + // 调试信息 + console.log('=== 提交数据调试 ==='); + console.log('是否编辑模式:', isEditMode); + console.log('计算的过期时间:', expirationTime); + console.log('提交的数据:', submitData); + console.log('=================='); + // 如果是编辑模式,添加现有申请的id if (isEditMode && existingApply?.applyId) { submitData.applyId = existingApply.applyId; diff --git a/src/dealer/customer/index.tsx b/src/dealer/customer/index.tsx index fd446da..2cf34d7 100644 --- a/src/dealer/customer/index.tsx +++ b/src/dealer/customer/index.tsx @@ -14,7 +14,7 @@ import { } from '@/utils/customerStatus'; import FixedButton from "@/components/FixedButton"; import navTo from "@/utils/common"; -import {pageShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply"; +import {pageShopDealerApply, removeShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply"; // 扩展User类型,添加客户状态和保护天数 interface CustomerUser extends UserType { @@ -33,36 +33,62 @@ const CustomerIndex = () => { // Tab配置 const tabList = getStatusOptions(); - // 计算剩余保护天数 - const calculateProtectDays = (applyTime: string): number => { - if (!applyTime) return 0; - + // 计算剩余保护天数(基于过期时间) + const calculateProtectDays = (expirationTime?: string, applyTime?: string): number => { try { - // 确保日期格式正确解析 - const applyDate = new Date(applyTime.replace(/-/g, '/')); - const currentDate = new Date(); + // 优先使用过期时间字段 + if (expirationTime) { + const expDate = new Date(expirationTime.replace(' ', 'T')); + const now = new Date(); + + // 计算剩余毫秒数 + const remainingMs = expDate.getTime() - now.getTime(); + + // 转换为天数,向上取整 + const remainingDays = Math.ceil(remainingMs / (1000 * 60 * 60 * 24)); + + console.log('=== 基于过期时间计算 ==='); + console.log('过期时间:', expirationTime); + console.log('当前时间:', now.toLocaleString()); + 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('解析后的申请日期:', applyDate); - console.log('当前日期:', currentDate); + console.log('已过去天数:', daysPassed); + console.log('剩余保护天数:', remainingDays); + console.log('======================'); - // 计算保护期结束时间 - 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); @@ -94,7 +120,7 @@ const CustomerIndex = () => { const mappedList = res.list.map(customer => ({ ...customer, 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(() => { fetchCustomerData(activeTab, true).then(); @@ -235,7 +277,7 @@ const CustomerIndex = () => { - {customer.realName || customer.dealerName || customer.dealerCode} + {customer.dealerName} {customer.customerStatus && ( @@ -296,6 +338,17 @@ const CustomerIndex = () => { )} + {(customer.applyStatus === 30 && customer.userId == Taro.getStorageSync('UserId')) && ( + + + + )} );