Compare commits

...

2 Commits

Author SHA1 Message Date
c58060fbd7 Merge remote-tracking branch 'origin/main' 2026-06-01 10:57:43 +08:00
2d4d73d0d1 refactor(customer): 优化客户数据查询和表单字段校验
- 移除新增客户页面对手机号的必填和格式校验
- 修改手机号字段标签为“手机号/微信号”,取消必填和长度限制
- 新增判断当前用户是否为超级管理员逻辑
- 抽取并统一构建客户查询参数方法,根据权限动态设置筛选条件
- 优化客户列表数据获取逻辑,支持超级管理员查看全部客户
- 调整依赖项,更新使用了新构建的查询参数函数
- 增强状态统计接口参数构建,统一调用参数生成函数
- 优化副作用 Hook 依赖,保证数据加载时机正确
2026-06-01 10:57:24 +08:00
2 changed files with 29 additions and 40 deletions

View File

@@ -359,25 +359,6 @@ const AddShopDealerApply = () => {
return;
}
// 验证必填字段
if (!values.mobile || values.mobile.trim() === '') {
Taro.showToast({
title: '请填写联系方式',
icon: 'error'
});
return;
}
// 验证手机号格式
const phoneRegex = /^1[3-9]\d{9}$/;
if (!phoneRegex.test(values.mobile)) {
Taro.showToast({
title: '请填写正确的手机号',
icon: 'error'
});
return;
}
// 规范化报备人:留空=自己报备(当前登录用户)
const rawUserId = normalizeText(values.userId);
const submitUserId = rawUserId
@@ -644,8 +625,8 @@ const AddShopDealerApply = () => {
<Form.Item name="realName" label="姓名" initialValue={FormData?.realName} required>
<Input placeholder="张三" disabled={isEditMode}/>
</Form.Item>
<Form.Item name="mobile" label="手机号" initialValue={FormData?.mobile} required>
<Input placeholder="手机号" disabled={isEditMode} maxLength={11}/>
<Form.Item name="mobile" label="手机号/微信号" initialValue={FormData?.mobile}>
<Input placeholder="手机号/微信号" disabled={isEditMode}/>
</Form.Item>
<Form.Item name="comments" label="备注" initialValue={FormData?.comments}>
<Input placeholder="请输入备注信息" />

View File

@@ -37,10 +37,29 @@ const CustomerIndex = () => {
const {user, loading: userLoading} = useUser()
const roleCheckFinished = !userLoading
const isLoggedIn = roleCheckFinished && user !== null
const isSuperAdmin = user?.isSuperAdmin === true
// Tab配置
const tabList = getStatusOptions();
const buildCustomerQueryParams = useCallback((currentPage?: number) => {
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
const params: any = {
type: 4
};
if (currentPage !== undefined) {
params.page = currentPage;
}
if (!isSuperAdmin) {
params.userId = currentUserId;
params.receptionistId = currentUserId;
}
return params;
}, [isSuperAdmin, user?.userId]);
// 复制手机号
const copyPhone = (phone: string) => {
Taro.setClipboardData({
@@ -183,17 +202,11 @@ const CustomerIndex = () => {
const fetchCustomerData = useCallback(async (statusFilter?: CustomerStatus, resetPage = false, targetPage?: number) => {
setLoading(true);
try {
const currentPage = resetPage ? 1 : (targetPage || page);
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
const currentPage = resetPage ? 1 : (targetPage || 1);
// 构建API参数根据状态筛选
// 查看自己提交的(userId)或分配给自己的(receptionistId)的客户
const params: any = {
type: 4,
page: currentPage,
userId: currentUserId,
receptionistId: currentUserId
};
// 非超管查看自己提交的(userId)或分配给自己的(receptionistId)的客户;超管查询全部
const params = buildCustomerQueryParams(currentPage);
const applyStatus = mapCustomerStatusToApplyStatus(statusFilter || activeTab);
if (applyStatus !== undefined) {
params.applyStatus = applyStatus;
@@ -236,7 +249,7 @@ const CustomerIndex = () => {
} finally {
setLoading(false);
}
}, [activeTab, page, user?.userId]);
}, [activeTab, buildCustomerQueryParams]);
const reloadMore = async () => {
if (loading || !hasMore) return; // 防止重复加载
@@ -284,12 +297,7 @@ const CustomerIndex = () => {
// 获取所有状态的统计数量
const fetchStatusCounts = useCallback(async () => {
try {
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
const baseParams: any = {
type: 4,
userId: currentUserId,
receptionistId: currentUserId
};
const baseParams = buildCustomerQueryParams();
// 并行获取各状态的数量
const [allRes, pendingRes, signedRes, cancelledRes] = await Promise.all([
@@ -308,7 +316,7 @@ const CustomerIndex = () => {
} catch (error) {
console.error('获取状态统计失败:', error);
}
}, [user?.userId]);
}, [buildCustomerQueryParams]);
const getStatusCounts = () => statusCounts;
@@ -351,7 +359,7 @@ const CustomerIndex = () => {
useEffect(() => {
if (!isLoggedIn) return;
fetchStatusCounts().then();
}, [isLoggedIn]);
}, [fetchStatusCounts, isLoggedIn]);
// 当activeTab变化时重新获取数据
useEffect(() => {
@@ -360,7 +368,7 @@ const CustomerIndex = () => {
setPage(1); // 重置页码
setHasMore(true); // 重置加载状态
fetchCustomerData(activeTab, true);
}, [activeTab, isLoggedIn]);
}, [activeTab, fetchCustomerData, isLoggedIn]);
// 监听页面显示,当从其他页面返回时刷新数据
useDidShow(() => {