Browse Source
- 新增经销商申请页面和相关组件- 更新用户中心页面,增加经销商状态显示和申请入口 - 修改登录逻辑,支持获取用户手机号- 优化用户钩子,增加获取用户ID和判断超级管理员权限的功能dev
11 changed files with 376 additions and 46 deletions
@ -0,0 +1,4 @@ |
|||
export default definePageConfig({ |
|||
navigationBarTitleText: '注册成为经销商', |
|||
navigationBarTextStyle: 'black' |
|||
}) |
@ -0,0 +1,187 @@ |
|||
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"; |
|||
|
|||
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]); |
|||
} else { |
|||
setFormData({}) |
|||
setIsEditMode(false); |
|||
setExistingApply(null); |
|||
} |
|||
} catch (error) { |
|||
console.error('查询申请记录失败:', error); |
|||
setIsEditMode(false); |
|||
setExistingApply(null); |
|||
setFormData({}) |
|||
} |
|||
} |
|||
|
|||
// 提交表单
|
|||
const submitSucceed = async (values: any) => { |
|||
try { |
|||
// 准备提交的数据
|
|||
const submitData = { |
|||
...values, |
|||
realName: values.realName || user?.nickname, |
|||
mobile: user?.phone, |
|||
refereeId: values.refereeId, |
|||
applyStatus: 10, |
|||
auditTime: undefined |
|||
}; |
|||
|
|||
// 如果是编辑模式,添加现有申请的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: `${isEditMode ? '更新' : '保存'}失败`, |
|||
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; |
@ -0,0 +1,121 @@ |
|||
import {Cell} from '@nutui/nutui-react-taro' |
|||
import navTo from "@/utils/common"; |
|||
import Taro from '@tarojs/taro' |
|||
import {View, Text} from '@tarojs/components' |
|||
import {ArrowRight, Reward, Setting} from '@nutui/icons-react-taro' |
|||
import {useUser} from '@/hooks/useUser' |
|||
import {useEffect, useState} from "react"; |
|||
import {pageShopDealerUser} from "@/api/shop/shopDealerUser"; |
|||
|
|||
const UserCell = () => { |
|||
const {isSuperAdmin} = useUser(); |
|||
const [isDealer, setIsDealer] = useState<boolean>(false) |
|||
|
|||
const reload = async () => { |
|||
const userId = Taro.getStorageSync('UserId') |
|||
|
|||
console.log('当前用户ID:', userId) |
|||
|
|||
const params = { |
|||
userId: Number(userId), |
|||
page: 1, |
|||
limit: 1 |
|||
} |
|||
|
|||
console.log('查询分销商参数:', params) |
|||
|
|||
try { |
|||
const res = await pageShopDealerUser(params) |
|||
console.log('分销商查询结果:', res) |
|||
if (res?.count && res?.count > 0) { |
|||
setIsDealer(true) |
|||
} else { |
|||
setIsDealer(false) |
|||
} |
|||
} catch (error) { |
|||
console.error('查询分销商信息失败:', error) |
|||
setIsDealer(false) |
|||
} |
|||
} |
|||
|
|||
useEffect(() => { |
|||
reload().then() |
|||
}, []) |
|||
|
|||
/** |
|||
* 管理中心 |
|||
*/ |
|||
if (isSuperAdmin()) { |
|||
return ( |
|||
<> |
|||
<View className={'px-4'}> |
|||
<Cell |
|||
className="nutui-cell-clickable" |
|||
style={{ |
|||
backgroundImage: 'linear-gradient(to right bottom, #e53e3e, #c53030)', |
|||
}} |
|||
title={ |
|||
<View style={{display: 'inline-flex', alignItems: 'center'}} onClick={() => navTo('/admin/index', true)}> |
|||
<Setting className={'text-white '} size={16}/> |
|||
<Text style={{fontSize: '16px'}} className={'pl-3 text-white font-medium'}>管理中心</Text> |
|||
</View> |
|||
} |
|||
extra={<ArrowRight color="#ffffff" size={18}/>} |
|||
/> |
|||
</View> |
|||
</> |
|||
) |
|||
} |
|||
|
|||
/** |
|||
* 分销中心 |
|||
*/ |
|||
if (isDealer) { |
|||
return ( |
|||
<> |
|||
<View className={'px-4'}> |
|||
<Cell |
|||
className="nutui-cell-clickable" |
|||
style={{ |
|||
backgroundImage: 'linear-gradient(to right bottom, #54a799, #177b73)', |
|||
}} |
|||
title={ |
|||
<View style={{display: 'inline-flex', alignItems: 'center'}} onClick={() => navTo('/dealer/index', true)}> |
|||
<Reward className={'text-orange-100 '} size={16}/> |
|||
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>分销中心</Text> |
|||
<Text className={'text-white opacity-80 pl-3'}>门店核销</Text> |
|||
</View> |
|||
} |
|||
extra={<ArrowRight color="#cccccc" size={18}/>} |
|||
/> |
|||
</View> |
|||
</> |
|||
) |
|||
} |
|||
|
|||
/** |
|||
* 分销中心 |
|||
*/ |
|||
return ( |
|||
<> |
|||
<View className={'px-4'}> |
|||
<Cell |
|||
className="nutui-cell-clickable" |
|||
style={{ |
|||
backgroundImage: 'linear-gradient(to right bottom, #54a799, #177b73)', |
|||
}} |
|||
title={ |
|||
<View style={{display: 'inline-flex', alignItems: 'center'}}> |
|||
<Reward className={'text-orange-100 '} size={16}/> |
|||
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>成为经销商</Text> |
|||
<Text className={'text-white opacity-80 pl-3'}>享优惠</Text> |
|||
</View> |
|||
} |
|||
extra={<ArrowRight color="#cccccc" size={18}/>} |
|||
onClick={() => navTo('/dealer/apply/add', true)} |
|||
/> |
|||
</View> |
|||
</> |
|||
) |
|||
} |
|||
export default UserCell |
Loading…
Reference in new issue