From 3600c1dfba24368ea9f7f003457078967d212cee 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, 3 Sep 2025 11:57:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(dealer):=20=E5=AE=9E=E7=8E=B0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E6=8A=A5=E5=A4=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增客户报备页面,包括表单提交和审核状态显示 - 修改客户列表页面,增加签约和取消操作- 更新客户状态标签样式 - 调整API基础URL --- config/env.ts | 2 +- src/api/shop/shopDealerApply/model/index.ts | 10 +- src/app.config.ts | 1 + src/dealer/customer/add.config.ts | 4 + src/dealer/customer/add.tsx | 209 ++++++++++++++++++++ src/dealer/customer/index.tsx | 108 +++++++--- src/utils/customerStatus.ts | 4 +- 7 files changed, 305 insertions(+), 33 deletions(-) create mode 100644 src/dealer/customer/add.config.ts create mode 100644 src/dealer/customer/add.tsx 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/api/shop/shopDealerApply/model/index.ts b/src/api/shop/shopDealerApply/model/index.ts index 8ea27cc..f308596 100644 --- a/src/api/shop/shopDealerApply/model/index.ts +++ b/src/api/shop/shopDealerApply/model/index.ts @@ -1,4 +1,4 @@ -import type { PageParam } from '@/api/index'; +import type { PageParam } from '@/api'; /** * 分销商申请记录表 @@ -10,6 +10,14 @@ export interface ShopDealerApply { userId?: number; // 姓名 realName?: string; + // 分销商名称 + dealerName?: string; + // 分销商编号 + dealerCode?: string; + // 详细地址 + address?: string; + // 金额 + money?: number; // 手机号 mobile?: string; // 推荐人用户ID diff --git a/src/app.config.ts b/src/app.config.ts index c6706aa..c53c9c9 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -64,6 +64,7 @@ export default defineAppConfig({ "invite-stats/index", "info", "customer/index", + "customer/add" ] }, // { diff --git a/src/dealer/customer/add.config.ts b/src/dealer/customer/add.config.ts new file mode 100644 index 0000000..fb7c4ce --- /dev/null +++ b/src/dealer/customer/add.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '客户报备', + navigationBarTextStyle: 'black' +}) diff --git a/src/dealer/customer/add.tsx b/src/dealer/customer/add.tsx new file mode 100644 index 0000000..63f5dd6 --- /dev/null +++ b/src/dealer/customer/add.tsx @@ -0,0 +1,209 @@ +import {useEffect, useState, useRef} from "react"; +import {Loading, CellGroup, Cell, Input, Form} from '@nutui/nutui-react-taro' +import {Edit} from '@nutui/icons-react-taro' +import Taro from '@tarojs/taro' +import {View} from '@tarojs/components' +import FixedButton from "@/components/FixedButton"; +import {useUser} from "@/hooks/useUser"; +import {ShopDealerApply} from "@/api/shop/shopDealerApply/model"; +import { + addShopDealerApply, + pageShopDealerApply, + updateShopDealerApply +} from "@/api/shop/shopDealerApply"; +import {getShopDealerUser} from "@/api/shop/shopDealerUser"; + +const AddUserAddress = () => { + const {user} = useUser() + const [loading, setLoading] = useState(true) + const [FormData, setFormData] = useState() + const formRef = useRef(null) + const [isEditMode, setIsEditMode] = useState(false) + const [existingApply, setExistingApply] = useState(null) + + // 获取审核状态文字 + const getApplyStatusText = (status?: number) => { + switch (status) { + case 10: + return '待审核' + case 20: + return '审核通过' + case 30: + return '驳回' + default: + return '未知状态' + } + } + + const reload = async () => { + // 判断用户是否登录 + if (!user?.userId) { + return false; + } + // 查询当前用户ID是否已有申请记录 + try { + const res = await pageShopDealerApply({}); + if (res && res.count > 0) { + setIsEditMode(true); + setExistingApply(res.list[0]); + // 如果有记录,填充表单数据 + setFormData(res.list[0]); + setLoading(false) + } else { + setIsEditMode(false); + setExistingApply(null); + setLoading(false) + } + } catch (error) { + setLoading(true) + console.error('查询申请记录失败:', error); + setIsEditMode(false); + setExistingApply(null); + } + } + + // 提交表单 + const submitSucceed = async (values: any) => { + try { + + // 准备提交的数据 + const submitData = { + ...values, + realName: values.realName || user?.nickname, + mobile: user?.phone, + refereeId: values.refereeId || FormData?.refereeId, + applyStatus: 10, + auditTime: undefined + }; + await getShopDealerUser(submitData.refereeId); + + // 如果是编辑模式,添加现有申请的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); + return Taro.showToast({ + title: '邀请人ID不存在', + icon: 'error' + }); + } + } + + // 处理固定按钮点击事件 + const handleFixedButtonClick = () => { + // 触发表单提交 + formRef.current?.submit(); + }; + + const submitFailed = (error: any) => { + console.log(error, 'err...') + } + + useEffect(() => { + reload().then(() => { + setLoading(false) + }) + }, [user?.userId]); // 依赖用户ID,当用户变化时重新加载 + + if (loading) { + return 加载中 + } + + return ( + <> +
submitSucceed(values)} + onFinishFailed={(errors) => submitFailed(errors)} + > + + + + + + + + + + + + + + + + + + + + + + + + + + + {/**/} + {/* */} + {/**/} + +
+ {/* 审核状态显示(仅在编辑模式下显示) */} + {isEditMode && ( + + + {getApplyStatusText(FormData?.applyStatus)} + + } + /> + {FormData?.applyStatus === 20 && ( + + )} + {FormData?.applyStatus === 30 && ( + + )} + + )} + + + {/* 底部浮动按钮 */} + {(!isEditMode || FormData?.applyStatus === 10 || FormData?.applyStatus === 30) && ( + } + text={isEditMode ? '保存修改' : '提交申请'} + disabled={FormData?.applyStatus === 10} + onClick={handleFixedButtonClick} + /> + )} + + + ); +}; + +export default AddUserAddress; diff --git a/src/dealer/customer/index.tsx b/src/dealer/customer/index.tsx index c6c885d..edd14b8 100644 --- a/src/dealer/customer/index.tsx +++ b/src/dealer/customer/index.tsx @@ -1,27 +1,29 @@ -import React, {useState, useEffect, useCallback} from 'react' +import {useState, useEffect, useCallback} from 'react' import {View, Text} from '@tarojs/components' -import {Loading, Tabs, TabPane, Tag} from '@nutui/nutui-react-taro' +import Taro from '@tarojs/taro' +import {Loading, Space, Tabs, TabPane, Tag, Button} from '@nutui/nutui-react-taro' import {Phone} from '@nutui/icons-react-taro' -import {pageUsers} from "@/api/system/user"; -import type {User as UserType} from "@/api/system/user/model"; +import type {ShopDealerApply, ShopDealerApply as UserType} from "@/api/shop/shopDealerApply/model"; import { CustomerStatus, getStatusText, getStatusTagType, - getRandomStatus, getStatusOptions } from '@/utils/customerStatus'; +import FixedButton from "@/components/FixedButton"; +import navTo from "@/utils/common"; +import {pageShopDealerApply, updateShopDealerApply} from "@/api/shop/shopDealerApply"; // 扩展User类型,添加客户状态 interface CustomerUser extends UserType { customerStatus?: CustomerStatus; } -const CustomerManagement: React.FC = () => { +const CustomerIndex = () => { const [list, setList] = useState([]) const [loading, setLoading] = useState(false) const [activeTab, setActiveTab] = useState('all') - const [searchValue, setSearchValue] = useState('') + const [searchValue, _] = useState('') // Tab配置 const tabList = getStatusOptions(); @@ -30,15 +32,24 @@ const CustomerManagement: React.FC = () => { const fetchCustomerData = useCallback(async () => { setLoading(true); try { - // 获取用户列表,status: 0 表示正常状态 - const res = await pageUsers({ status: 0 }); + const res = await pageShopDealerApply({}); if (res?.list) { - // 为每个用户添加随机的客户状态(实际项目中应该从后端获取真实状态) - const customersWithStatus: CustomerUser[] = res.list.map(user => ({ - ...user, - customerStatus: getRandomStatus() // 临时使用随机状态,实际应该从数据库获取 - })); - setList(customersWithStatus); + list.map(d => { + if(d.applyStatus == 10){ + d.customerStatus = 'pending' + } + if(d.applyStatus == 20){ + d.customerStatus = 'signed' + } + if(d.applyStatus == 30){ + d.customerStatus = 'cancelled' + } + return { + ...d, + customerStatus: d.applyStatus == 10 ? 'pending' : 'signed' + } + }) + setList(res.list); } } catch (error) { console.error('获取客户数据失败:', error); @@ -48,13 +59,18 @@ const CustomerManagement: React.FC = () => { }, []); - // 根据当前Tab和搜索条件筛选数据 const getFilteredList = () => { + console.log('TABS',activeTab) let filteredList = list; // 按状态筛选 if (activeTab !== 'all') { + console.log(filteredList,'customerStatus') + filteredList.map(d => { + console.log(d.applyStatus) + }) + filteredList = filteredList.filter(customer => customer.customerStatus === activeTab); } @@ -63,9 +79,9 @@ const CustomerManagement: React.FC = () => { const keyword = searchValue.trim().toLowerCase(); filteredList = filteredList.filter(customer => (customer.realName && customer.realName.toLowerCase().includes(keyword)) || - (customer.nickname && customer.nickname.toLowerCase().includes(keyword)) || - (customer.username && customer.username.toLowerCase().includes(keyword)) || - (customer.phone && customer.phone.includes(keyword)) || + (customer.dealerName && customer.dealerName.toLowerCase().includes(keyword)) || + (customer.dealerCode && customer.dealerCode.toLowerCase().includes(keyword)) || + (customer.mobile && customer.mobile.includes(keyword)) || (customer.userId && customer.userId.toString().includes(keyword)) ); } @@ -91,6 +107,16 @@ const CustomerManagement: React.FC = () => { return counts; }; + // 取消操作 + const handleCancel = (customer: ShopDealerApply) => { + updateShopDealerApply({ + ...customer, + applyStatus: 30 + }).then(r => { + console.log(r) + }) + }; + // 初始化数据 useEffect(() => { fetchCustomerData(); @@ -103,7 +129,7 @@ const CustomerManagement: React.FC = () => { - {customer.realName || customer.nickname || customer.username} + {customer.realName || customer.dealerName || customer.dealerCode} {customer.customerStatus && ( @@ -112,16 +138,37 @@ const CustomerManagement: React.FC = () => { )} - - - {customer.phone || '未填写'} - + + 联系人:{customer.realName} + 联系电话:{customer.mobile} + - 注册时间:{customer.createTime} + 添加时间:{customer.createTime} + + {/* 跟进中状态显示操作按钮 */} + {customer.applyStatus === 10 && ( + + + + + )} ); @@ -131,10 +178,10 @@ const CustomerManagement: React.FC = () => { if (loading) { return ( - - + + 加载中... - + ); } @@ -155,6 +202,7 @@ const CustomerManagement: React.FC = () => { return ( + {/* 顶部Tabs */} { {/* 客户列表 */} {renderCustomerList()} + + Taro.navigateTo({url: '/dealer/customer/add'})}/> ); }; -export default CustomerManagement; +export default CustomerIndex; diff --git a/src/utils/customerStatus.ts b/src/utils/customerStatus.ts index b35399c..1d174a5 100644 --- a/src/utils/customerStatus.ts +++ b/src/utils/customerStatus.ts @@ -24,8 +24,8 @@ export const CUSTOMER_STATUS_CONFIG = { }, cancelled: { label: '已取消', - color: '#ff4d4f', - tagType: 'danger' as const + color: '#999999', + tagType: 'default' as const } };