- 在用户注册时支持从邀请参数中获取推荐人ID并绑定 - 修改管理员面板UI,添加统一扫码功能入口- 更新用户管理相关API地址,统一使用SERVER_API_URL - 调整优惠券卡片样式,移除小程序不支持的CSS属性 - 添加聊天会话和消息管理相关API模块 - 新增分销商银行卡管理API接口 - 修改系统用户模型,增加推荐人ID字段 - 更新广告位查询接口,支持根据code获取广告位 - 调整邀请绑定接口参数,将refereeId改为dealerId - 修改环境配置中的应用名称为"时里院子市集" - 移除分享到朋友圈的相关代码 - 添加管理员面板组件,提供统一扫码等管理功能 -修复用户管理API请求参数传递问题 - 添加聊天消息和会话管理的完整CRUD接口 - 更新系统用户相关接口URL,确保正确调用后端服务 - 添加分销商银行卡管理的完整API接口实现 - 修改邀请绑定接口,使用dealerId替代refereeId参数 - 修复扫码登录相关API的URL拼接问题 - 添加二维码内容解析功能,支持多种格式的token提取 - 更新用户信息模型,增加推荐人ID字段 -优化管理员面板样式和交互逻辑- 调整优惠券组件样式,兼容小程序环境限制- 修复用户管理模块的API调用问题 - 添加聊天相关数据模型和接口定义 - 更新环境配置中的应用名称 -修复邀请绑定相关的参数传递问题- 添加扫码登录状态枚举和相关数据结构定义- 优化管理员功能面板的UI展示和交互体验- 修复系统用户管理接口的请求参数问题 - 添加分销商银行卡管理相关接口实现- 调整聊天消息和会话管理接口的数据结构定义 -修复用户管理模块中的API调用路径问题 - 添加扫码登录相关工具函数,如设备信息获取等 - 更新邀请绑定接口的数据模型定义 -优化管理员面板组件的样式和功能实现 -修复系统用户管理接口中的参数传递问题 - 添加聊天相关模块的完整API接口实现 - 调整分销商银行卡管理模块的数据结构定义- 修复扫码登录相关接口的URL拼接问题- 更新用户管理模块中的API调用方式 - 添加聊天消息批量发送等相关接口实现- 修复邀请绑定接口中的参数名称问题- 优化管理员面板组件的功能和交互逻辑 - 调整系统用户管理接口的请求参数传递方式 - 添加分销商银行卡管理模块的完整接口实现 -修复聊天相关接口中的数据结构问题 - 更新扫码登录相关接口的数据模型定义 - 优化管理员功能面板的展示效果和用户体验
192 lines
5.5 KiB
TypeScript
192 lines
5.5 KiB
TypeScript
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<boolean>(true)
|
||
const [FormData, setFormData] = useState<ShopDealerApply>()
|
||
const formRef = useRef<any>(null)
|
||
const [isEditMode, setIsEditMode] = useState<boolean>(false)
|
||
const [existingApply, setExistingApply] = useState<ShopDealerApply | null>(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({userId: user?.userId});
|
||
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 <Loading className={'px-2'}>加载中</Loading>
|
||
}
|
||
|
||
return (
|
||
<>
|
||
<Form
|
||
ref={formRef}
|
||
divider
|
||
initialValues={FormData}
|
||
labelPosition="left"
|
||
onFinish={(values) => submitSucceed(values)}
|
||
onFinishFailed={(errors) => submitFailed(errors)}
|
||
>
|
||
<View className={'bg-gray-100 h-3'}></View>
|
||
<CellGroup style={{padding: '4px 0'}}>
|
||
<Form.Item name="realName" label="名称" initialValue={user?.nickname} required>
|
||
<Input placeholder="经销商名称" maxLength={10}/>
|
||
</Form.Item>
|
||
<Form.Item name="mobile" label="手机号" initialValue={user?.mobile} required>
|
||
<Input placeholder="请输入手机号" disabled={true} maxLength={11}/>
|
||
</Form.Item>
|
||
<Form.Item name="refereeId" label="邀请人ID" initialValue={FormData?.refereeId} required>
|
||
<Input placeholder="邀请人ID"/>
|
||
</Form.Item>
|
||
</CellGroup>
|
||
</Form>
|
||
{/* 审核状态显示(仅在编辑模式下显示) */}
|
||
{isEditMode && (
|
||
<CellGroup>
|
||
<Cell
|
||
title={'审核状态'}
|
||
extra={
|
||
<span style={{
|
||
color: FormData?.applyStatus === 20 ? '#52c41a' :
|
||
FormData?.applyStatus === 30 ? '#ff4d4f' : '#faad14'
|
||
}}>
|
||
{getApplyStatusText(FormData?.applyStatus)}
|
||
</span>
|
||
}
|
||
/>
|
||
{FormData?.applyStatus === 20 && (
|
||
<Cell title={'审核时间'} extra={FormData?.auditTime || '无'}/>
|
||
)}
|
||
{FormData?.applyStatus === 30 && (
|
||
<Cell title={'驳回原因'} extra={FormData?.rejectReason || '无'}/>
|
||
)}
|
||
</CellGroup>
|
||
)}
|
||
|
||
|
||
{/* 底部浮动按钮 */}
|
||
{(!isEditMode || FormData?.applyStatus === 10 || FormData?.applyStatus === 30) && (
|
||
<FixedButton
|
||
icon={<Edit/>}
|
||
text={isEditMode ? '保存修改' : '提交申请'}
|
||
disabled={FormData?.applyStatus === 10}
|
||
onClick={handleFixedButtonClick}
|
||
/>
|
||
)}
|
||
|
||
</>
|
||
);
|
||
};
|
||
|
||
export default AddUserAddress;
|