feat(customer): 优化报备人管理和权限控制
- 移除页面分页查询,仅保留精确查询接口调用 - 添加当前登录用户ID获取和报备人规范化处理逻辑 - 实现管理员可查看全部客户,普通分销商仅查看自己的权限控制 - 集成用户角色显示功能,在用户卡片组件中展示角色标签 - 修复角色名称获取逻辑,支持多种数据
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
extractDateForCalendar, formatDateForDisplay
|
||||
} from "@/utils/dateUtils";
|
||||
import {ShopDealerUser} from "@/api/shop/shopDealerUser/model";
|
||||
import {getShopDealerUser, pageShopDealerUser} from "@/api/shop/shopDealerUser";
|
||||
import {getShopDealerUser} from "@/api/shop/shopDealerUser";
|
||||
|
||||
const AddShopDealerApply = () => {
|
||||
const {params} = useRouter();
|
||||
@@ -286,6 +286,8 @@ const AddShopDealerApply = () => {
|
||||
const submitSucceed = async (values: any) => {
|
||||
|
||||
try {
|
||||
const currentUserId = Number(Taro.getStorageSync('UserId')) || 0;
|
||||
|
||||
// 房号相关必填校验
|
||||
if (!values.address || values.address.trim() === '') {
|
||||
Taro.showToast({title: '请选择/填写小区', icon: 'error'});
|
||||
@@ -323,18 +325,34 @@ const AddShopDealerApply = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证报备人是否存在
|
||||
if (values.userId > 0) {
|
||||
const isExist = await pageShopDealerUser({userId: Number(values.userId)});
|
||||
if(isExist && isExist.count == 0){
|
||||
Taro.showToast({
|
||||
title: '报备人不存在',
|
||||
icon: 'error'
|
||||
});
|
||||
// 规范化报备人:留空=自己报备(当前登录用户)
|
||||
const rawUserId = normalizeText(values.userId);
|
||||
const submitUserId = rawUserId
|
||||
? Number(rawUserId)
|
||||
: (isEditMode ? (existingApply?.userId || currentUserId) : currentUserId);
|
||||
if (!Number.isFinite(submitUserId) || submitUserId <= 0) {
|
||||
Taro.showToast({title: '请填写正确的报备人ID', icon: 'error'});
|
||||
return;
|
||||
}
|
||||
|
||||
// 报备人存在性校验 + 获取该报备人的推荐人(用于后端展示链路)
|
||||
let reporterDealerUser: ShopDealerUser | undefined = undefined;
|
||||
if (submitUserId === currentUserId) {
|
||||
reporterDealerUser = referee;
|
||||
} else {
|
||||
try {
|
||||
reporterDealerUser = await getShopDealerUser(submitUserId);
|
||||
} catch {
|
||||
Taro.showToast({title: '报备人不存在', icon: 'error'});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 后端常用 0 表示“无推荐人”,避免传空值触发“推荐人不存在”
|
||||
const submitRefereeId = (reporterDealerUser?.refereeId && reporterDealerUser.refereeId > 0)
|
||||
? reporterDealerUser.refereeId
|
||||
: undefined;
|
||||
|
||||
const houseKeyRaw = buildHouseKey(values.address, values.buildingNo, values.unitNo, values.roomNo);
|
||||
const houseKeyNormalized = buildHouseKeyNormalized(values.address, values.buildingNo, values.unitNo, values.roomNo);
|
||||
const houseKey = houseKeyNormalized || houseKeyRaw;
|
||||
@@ -416,7 +434,10 @@ const AddShopDealerApply = () => {
|
||||
// 客户姓名/手机号
|
||||
realName: values.realName,
|
||||
mobile: values.mobile,
|
||||
refereeId: referee?.refereeId,
|
||||
// 报备人(留空时用当前登录用户)
|
||||
// userId: submitUserId,
|
||||
// 推荐人(报备人的上级;无则传 0)
|
||||
refereeId: submitRefereeId,
|
||||
applyStatus: isEditMode ? 20 : 10,
|
||||
auditTime: undefined,
|
||||
// 设置保护期过期时间(15天后)
|
||||
@@ -496,8 +517,7 @@ const AddShopDealerApply = () => {
|
||||
unitNo: parsed.unitNo,
|
||||
roomNo: parsed.roomNo,
|
||||
realName: FormData.realName,
|
||||
mobile: FormData.mobile,
|
||||
userId: FormData.userId
|
||||
mobile: FormData.mobile
|
||||
});
|
||||
}, [FormData]);
|
||||
|
||||
@@ -571,13 +591,13 @@ const AddShopDealerApply = () => {
|
||||
{/*</Form.Item>*/}
|
||||
</>
|
||||
)}
|
||||
<Form.Item name="userId" label="报备人(ID)" initialValue={FormData?.userId}>
|
||||
<Input
|
||||
placeholder="自己报备请留空"
|
||||
disabled={isEditMode}
|
||||
type="number"
|
||||
/>
|
||||
</Form.Item>
|
||||
{/*<Form.Item name="userId" label="报备人(ID)" initialValue={FormData?.userId}>*/}
|
||||
{/* <Input*/}
|
||||
{/* placeholder="自己报备请留空"*/}
|
||||
{/* disabled={isEditMode}*/}
|
||||
{/* type="number"*/}
|
||||
{/* />*/}
|
||||
{/*</Form.Item>*/}
|
||||
</CellGroup>
|
||||
</Form>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user