forked from gxwebsoft/mp-10550
feat(invite): 重构邀请关系建立流程并优化相关功能
- 新增 bindRefereeRelation 接口替换原有的 createInviteRelation 接口 - 优化邀请参数解析逻辑,支持 uid_xxx 格式的邀请码 - 重构 handleInviteRelation 函数,使用新的绑定推荐关系接口 - 新增 checkAndHandleInviteRelation 和 manualHandleInviteRelation 函数 - 优化首页和订单列表的相关逻辑,以支持新的邀请关系建立流程 - 更新文档中的相关描述,如将"下级成员"改为"团队成员"
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Avatar, Cell, Space, Empty, Tabs, Button, TabPane, Image} from '@nutui/nutui-react-taro'
|
||||
import {useEffect, useState, CSSProperties} from "react";
|
||||
import {Avatar, Cell, Space, Empty, Tabs, Button, TabPane, Image, Dialog} from '@nutui/nutui-react-taro'
|
||||
import {useEffect, useState, useCallback, CSSProperties} from "react";
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro';
|
||||
import {InfiniteLoading} from '@nutui/nutui-react-taro'
|
||||
@@ -86,6 +86,7 @@ interface OrderListProps {
|
||||
onReload?: () => void;
|
||||
searchParams?: ShopOrderParam;
|
||||
showSearch?: boolean;
|
||||
onSearchParamsChange?: (params: ShopOrderParam) => void; // 新增:通知父组件参数变化
|
||||
}
|
||||
|
||||
function OrderList(props: OrderListProps) {
|
||||
@@ -100,13 +101,17 @@ function OrderList(props: OrderListProps) {
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
const [tapIndex, setTapIndex] = useState<string | number>(() => {
|
||||
const [tapIndex, setTapIndex] = useState<number>(() => {
|
||||
const initialIndex = getInitialTabIndex();
|
||||
console.log('初始化tapIndex:', initialIndex, '对应statusFilter:', props.searchParams?.statusFilter);
|
||||
return initialIndex;
|
||||
})
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [cancelDialogVisible, setCancelDialogVisible] = useState(false)
|
||||
const [orderToCancel, setOrderToCancel] = useState<ShopOrder | null>(null)
|
||||
const [confirmReceiveDialogVisible, setConfirmReceiveDialogVisible] = useState(false)
|
||||
const [orderToConfirmReceive, setOrderToConfirmReceive] = useState<ShopOrder | null>(null)
|
||||
|
||||
// 获取订单状态文本
|
||||
const getOrderStatusText = (order: ShopOrder) => {
|
||||
@@ -174,7 +179,7 @@ function OrderList(props: OrderListProps) {
|
||||
return params;
|
||||
};
|
||||
|
||||
const reload = async (resetPage = false, targetPage?: number) => {
|
||||
const reload = useCallback(async (resetPage = false, targetPage?: number) => {
|
||||
setLoading(true);
|
||||
setError(null); // 清除之前的错误
|
||||
const currentPage = resetPage ? 1 : (targetPage || page);
|
||||
@@ -228,18 +233,20 @@ function OrderList(props: OrderListProps) {
|
||||
ordersWithGoods.push(...batchResults);
|
||||
}
|
||||
|
||||
// 合并数据
|
||||
newList = resetPage ? ordersWithGoods : list?.concat(ordersWithGoods);
|
||||
// 使用函数式更新避免依赖 list
|
||||
setList(prevList => {
|
||||
const newList = resetPage ? ordersWithGoods : (prevList || []).concat(ordersWithGoods);
|
||||
return newList;
|
||||
});
|
||||
|
||||
// 正确判断是否还有更多数据
|
||||
const hasMoreData = res.list.length >= 10; // 假设每页10条数据
|
||||
setHasMore(hasMoreData);
|
||||
} else {
|
||||
newList = resetPage ? [] : list;
|
||||
setList(prevList => resetPage ? [] : prevList);
|
||||
setHasMore(false);
|
||||
}
|
||||
|
||||
setList(newList || []);
|
||||
setPage(currentPage);
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
@@ -252,51 +259,77 @@ function OrderList(props: OrderListProps) {
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
};
|
||||
}, [tapIndex, page, props.searchParams]); // 移除 list 依赖
|
||||
|
||||
const reloadMore = async () => {
|
||||
const reloadMore = useCallback(async () => {
|
||||
if (loading || !hasMore) return; // 防止重复加载
|
||||
const nextPage = page + 1;
|
||||
setPage(nextPage);
|
||||
await reload(false, nextPage);
|
||||
}, [loading, hasMore, page, reload]);
|
||||
|
||||
// 确认收货 - 显示确认对话框
|
||||
const confirmReceive = (order: ShopOrder) => {
|
||||
setOrderToConfirmReceive(order);
|
||||
setConfirmReceiveDialogVisible(true);
|
||||
};
|
||||
|
||||
// 确认收货
|
||||
const confirmReceive = async (order: ShopOrder) => {
|
||||
// 确认收货 - 执行收货操作
|
||||
const handleConfirmReceive = async () => {
|
||||
if (!orderToConfirmReceive) return;
|
||||
|
||||
try {
|
||||
setConfirmReceiveDialogVisible(false);
|
||||
|
||||
await updateShopOrder({
|
||||
...order,
|
||||
...orderToConfirmReceive,
|
||||
deliveryStatus: 30, // 已收货
|
||||
orderStatus: 1 // 已完成
|
||||
});
|
||||
|
||||
Taro.showToast({
|
||||
title: '确认收货成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
await reload(true); // 重新加载列表
|
||||
props.onReload?.(); // 通知父组件刷新
|
||||
|
||||
// 清空状态
|
||||
setOrderToConfirmReceive(null);
|
||||
} catch (error) {
|
||||
console.error('确认收货失败:', error);
|
||||
Taro.showToast({
|
||||
title: '确认收货失败',
|
||||
icon: 'none'
|
||||
});
|
||||
// 重新显示对话框
|
||||
setConfirmReceiveDialogVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
// 取消订单
|
||||
const cancelOrder = async (order: ShopOrder) => {
|
||||
try {
|
||||
// 显示确认对话框
|
||||
const result = await Taro.showModal({
|
||||
title: '确认取消',
|
||||
content: '确定要取消这个订单吗?',
|
||||
confirmText: '确认取消',
|
||||
cancelText: '我再想想'
|
||||
});
|
||||
// 取消确认收货对话框
|
||||
const handleCancelReceiveDialog = () => {
|
||||
setConfirmReceiveDialogVisible(false);
|
||||
setOrderToConfirmReceive(null);
|
||||
};
|
||||
|
||||
if (!result.confirm) return;
|
||||
// 取消订单
|
||||
const cancelOrder = (order: ShopOrder) => {
|
||||
setOrderToCancel(order);
|
||||
setCancelDialogVisible(true);
|
||||
};
|
||||
|
||||
// 确认取消订单
|
||||
const handleConfirmCancel = async () => {
|
||||
if (!orderToCancel) return;
|
||||
|
||||
try {
|
||||
setCancelDialogVisible(false);
|
||||
|
||||
// 更新订单状态为已取消,而不是删除订单
|
||||
await updateShopOrder({
|
||||
...order,
|
||||
...orderToCancel,
|
||||
orderStatus: 2 // 已取消
|
||||
});
|
||||
|
||||
@@ -312,9 +345,17 @@ function OrderList(props: OrderListProps) {
|
||||
title: '取消订单失败',
|
||||
icon: 'error'
|
||||
});
|
||||
} finally {
|
||||
setOrderToCancel(null);
|
||||
}
|
||||
};
|
||||
|
||||
// 取消对话框的取消操作
|
||||
const handleCancelDialog = () => {
|
||||
setCancelDialogVisible(false);
|
||||
setOrderToCancel(null);
|
||||
};
|
||||
|
||||
// 立即支付
|
||||
const payOrder = async (order: ShopOrder) => {
|
||||
try {
|
||||
@@ -389,7 +430,7 @@ function OrderList(props: OrderListProps) {
|
||||
timeStamp: result.timeStamp,
|
||||
nonceStr: result.nonceStr,
|
||||
package: result.package,
|
||||
signType: result.signType as any,
|
||||
signType: (result.signType || 'MD5') as 'MD5' | 'HMAC-SHA256',
|
||||
paySign: result.paySign,
|
||||
});
|
||||
|
||||
@@ -435,7 +476,7 @@ function OrderList(props: OrderListProps) {
|
||||
|
||||
useEffect(() => {
|
||||
void reload(true); // 首次加载或tab切换时重置页码
|
||||
}, [tapIndex]); // 监听tapIndex变化
|
||||
}, [tapIndex]); // 只监听tapIndex变化,避免reload依赖循环
|
||||
|
||||
// 监听外部statusFilter变化,同步更新tab索引
|
||||
useEffect(() => {
|
||||
@@ -459,7 +500,7 @@ function OrderList(props: OrderListProps) {
|
||||
setTapIndex(targetTabIndex);
|
||||
// 不需要调用reload,因为tapIndex变化会触发reload
|
||||
}
|
||||
}, [props.searchParams?.statusFilter]); // 监听statusFilter变化
|
||||
}, [props.searchParams?.statusFilter, tapIndex]); // 监听statusFilter变化
|
||||
|
||||
|
||||
return (
|
||||
@@ -477,7 +518,20 @@ function OrderList(props: OrderListProps) {
|
||||
}}
|
||||
value={tapIndex}
|
||||
onChange={(paneKey) => {
|
||||
setTapIndex(paneKey)
|
||||
console.log('Tab切换:', paneKey, '类型:', typeof paneKey);
|
||||
const newTapIndex = Number(paneKey);
|
||||
setTapIndex(newTapIndex);
|
||||
|
||||
// 通知父组件更新 searchParams.statusFilter
|
||||
const currentTab = tabs.find(tab => tab.index === newTapIndex);
|
||||
if (currentTab && props.onSearchParamsChange) {
|
||||
const newSearchParams = {
|
||||
...props.searchParams,
|
||||
statusFilter: currentTab.statusFilter
|
||||
};
|
||||
console.log('通知父组件更新searchParams:', newSearchParams);
|
||||
props.onSearchParamsChange(newSearchParams);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{
|
||||
@@ -533,8 +587,8 @@ function OrderList(props: OrderListProps) {
|
||||
{/* 订单列表 */}
|
||||
{list.length > 0 && list
|
||||
?.filter((item) => {
|
||||
// 如果是待付款标签页(tapIndex === 0),过滤掉支付已过期的订单
|
||||
if (tapIndex === 0 && !item.payStatus && item.orderStatus !== 2 && item.createTime) {
|
||||
// 如果是待付款标签页(tapIndex === 1),过滤掉支付已过期的订单
|
||||
if (tapIndex === 1 && !item.payStatus && item.orderStatus !== 2 && item.createTime) {
|
||||
return !isPaymentExpired(item.createTime);
|
||||
}
|
||||
return true;
|
||||
@@ -626,7 +680,7 @@ function OrderList(props: OrderListProps) {
|
||||
{item.deliveryStatus === 20 && (
|
||||
<Button size={'small'} type="primary" onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
void confirmReceive(item);
|
||||
confirmReceive(item);
|
||||
}}>确认收货</Button>
|
||||
)}
|
||||
{/* 已完成状态:显示申请退款 */}
|
||||
@@ -645,6 +699,30 @@ function OrderList(props: OrderListProps) {
|
||||
</InfiniteLoading>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* 取消订单确认对话框 */}
|
||||
<Dialog
|
||||
title="确认取消"
|
||||
visible={cancelDialogVisible}
|
||||
confirmText="确认取消"
|
||||
cancelText="我再想想"
|
||||
onConfirm={handleConfirmCancel}
|
||||
onCancel={handleCancelDialog}
|
||||
>
|
||||
确定要取消这个订单吗?
|
||||
</Dialog>
|
||||
|
||||
{/* 确认收货确认对话框 */}
|
||||
<Dialog
|
||||
title="确认收货"
|
||||
visible={confirmReceiveDialogVisible}
|
||||
confirmText="确认收货"
|
||||
cancelText="我再想想"
|
||||
onConfirm={handleConfirmReceive}
|
||||
onCancel={handleCancelReceiveDialog}
|
||||
>
|
||||
确定已经收到商品了吗?确认收货后订单将完成。
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user