|
|
@ -1,53 +1,60 @@ |
|
|
|
import {Avatar, Cell, Space, Tabs, Button, TabPane, Image} from '@nutui/nutui-react-taro' |
|
|
|
import {useEffect, useState, CSSProperties} from "react"; |
|
|
|
import {View} from '@tarojs/components' |
|
|
|
import Taro from '@tarojs/taro'; |
|
|
|
import {InfiniteLoading} from '@nutui/nutui-react-taro' |
|
|
|
import dayjs from "dayjs"; |
|
|
|
import {pageShopOrder, updateShopOrder} from "@/api/shop/shopOrder"; |
|
|
|
import {ShopOrder} from "@/api/shop/shopOrder/model"; |
|
|
|
import {pageShopOrder, removeShopOrder, updateShopOrder} from "@/api/shop/shopOrder"; |
|
|
|
import {ShopOrder, ShopOrderParam} from "@/api/shop/shopOrder/model"; |
|
|
|
import {listShopOrderGoods} from "@/api/shop/shopOrderGoods"; |
|
|
|
import {ShopOrderGoods} from "@/api/shop/shopOrderGoods/model"; |
|
|
|
import {copyText} from "@/utils/common"; |
|
|
|
|
|
|
|
const InfiniteUlStyle: CSSProperties = { |
|
|
|
marginTop: '44px', |
|
|
|
height: '82vh', |
|
|
|
const getInfiniteUlStyle = (showSearch: boolean = false): CSSProperties => ({ |
|
|
|
marginTop: showSearch ? '65px' : '44px', // 如果显示搜索框,增加更多的上边距
|
|
|
|
height: showSearch ? '75vh' : '82vh', // 相应调整高度
|
|
|
|
width: '100%', |
|
|
|
padding: '0', |
|
|
|
overflowY: 'auto', |
|
|
|
overflowX: 'hidden', |
|
|
|
boxShadow: '0 0 10px rgba(0, 0, 0, 0.1)', |
|
|
|
} |
|
|
|
}) |
|
|
|
const tabs = [ |
|
|
|
{ |
|
|
|
index: 0, |
|
|
|
key: '全部', |
|
|
|
title: '全部' |
|
|
|
title: '全部', |
|
|
|
description: '所有订单' |
|
|
|
}, |
|
|
|
{ |
|
|
|
index: 1, |
|
|
|
key: '待付款', |
|
|
|
title: '待付款' |
|
|
|
title: '待付款', |
|
|
|
description: '等待付款的订单' |
|
|
|
}, |
|
|
|
{ |
|
|
|
index: 2, |
|
|
|
key: '待发货', |
|
|
|
title: '待发货' |
|
|
|
title: '待发货', |
|
|
|
description: '已付款待发货的订单' |
|
|
|
}, |
|
|
|
{ |
|
|
|
index: 3, |
|
|
|
key: '待收货', |
|
|
|
title: '待收货' |
|
|
|
title: '待收货', |
|
|
|
description: '已发货待收货的订单' |
|
|
|
}, |
|
|
|
{ |
|
|
|
index: 4, |
|
|
|
key: '已收货', |
|
|
|
title: '已收货' |
|
|
|
key: '已完成', |
|
|
|
title: '已完成', |
|
|
|
description: '已完成的订单' |
|
|
|
}, |
|
|
|
{ |
|
|
|
index: 5, |
|
|
|
key: '已完成', |
|
|
|
title: '已完成' |
|
|
|
key: '已取消', |
|
|
|
title: '已取消', |
|
|
|
description: '已取消/退款的订单' |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
@ -59,13 +66,17 @@ interface OrderWithGoods extends ShopOrder { |
|
|
|
interface OrderListProps { |
|
|
|
data: ShopOrder[]; |
|
|
|
onReload?: () => void; |
|
|
|
searchParams?: ShopOrderParam; |
|
|
|
showSearch?: boolean; |
|
|
|
} |
|
|
|
|
|
|
|
function OrderList(props: OrderListProps) { |
|
|
|
const [list, setList] = useState<OrderWithGoods[]>([]) |
|
|
|
const [page, setPage] = useState(1) |
|
|
|
const [hasMore, setHasMore] = useState(true) |
|
|
|
const [tapIndex, setTapIndex] = useState<string | number>('0') |
|
|
|
const [tapIndex, setTapIndex] = useState<string | number>(0) |
|
|
|
const [loading, setLoading] = useState(false) |
|
|
|
const [totalCount, setTotalCount] = useState(0) |
|
|
|
|
|
|
|
// 获取订单状态文本
|
|
|
|
const getOrderStatusText = (order: ShopOrder) => { |
|
|
@ -79,7 +90,7 @@ function OrderList(props: OrderListProps) { |
|
|
|
if (order.orderStatus === 7) return '客户端申请退款'; |
|
|
|
|
|
|
|
// 检查支付状态 (payStatus为boolean类型,false/0表示未付款,true/1表示已付款)
|
|
|
|
if (!order.payStatus || order.payStatus === false) return '待付款'; |
|
|
|
if (!order.payStatus) return '待付款'; |
|
|
|
|
|
|
|
// 已付款后检查发货状态
|
|
|
|
if (order.deliveryStatus === 10) return '待发货'; |
|
|
@ -93,39 +104,92 @@ function OrderList(props: OrderListProps) { |
|
|
|
return '未知状态'; |
|
|
|
}; |
|
|
|
|
|
|
|
// 检查订单是否为已取消状态
|
|
|
|
const isCancelledOrder = (order: ShopOrder) => { |
|
|
|
// 已取消的订单状态:2已取消,3取消中,4退款申请中,6退款成功,7客户端申请退款
|
|
|
|
const cancelledStatuses = [2, 3, 4, 6, 7]; |
|
|
|
return cancelledStatuses.includes(order.orderStatus || 0); |
|
|
|
}; |
|
|
|
|
|
|
|
// 根据tab筛选订单,排除已取消的订单
|
|
|
|
const filterOrdersByTab = (orders: OrderWithGoods[], tabIndex: number) => { |
|
|
|
const indexStr = String(tabIndex); |
|
|
|
|
|
|
|
return orders.filter(order => { |
|
|
|
switch (indexStr) { |
|
|
|
case '1': // 待付款
|
|
|
|
// 未付款且未取消的订单
|
|
|
|
return !order.payStatus && !isCancelledOrder(order); |
|
|
|
case '2': // 待发货
|
|
|
|
// 已付款但未发货且未取消的订单
|
|
|
|
return order.payStatus && order.deliveryStatus === 10 && !isCancelledOrder(order); |
|
|
|
case '3': // 待收货
|
|
|
|
// 已发货且未取消的订单
|
|
|
|
return order.deliveryStatus === 20 && !isCancelledOrder(order); |
|
|
|
case '4': // 已完成
|
|
|
|
// 已完成的订单
|
|
|
|
return order.orderStatus === 1; |
|
|
|
case '5': // 已取消
|
|
|
|
// 只显示已取消的订单
|
|
|
|
return isCancelledOrder(order); |
|
|
|
case '0': // 全部
|
|
|
|
default: |
|
|
|
return true; // 显示所有订单,包括已取消的
|
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const getOrderStatusParams = (index: string | number) => { |
|
|
|
let params: { payStatus?: boolean | number; deliveryStatus?: number; orderStatus?: number; userId?: number } = {}; |
|
|
|
let params: ShopOrderParam = {}; |
|
|
|
// 添加用户ID过滤
|
|
|
|
params.userId = Taro.getStorageSync('UserId'); |
|
|
|
|
|
|
|
switch (index) { |
|
|
|
// 将数字索引转换为字符串进行匹配
|
|
|
|
const indexStr = String(index); |
|
|
|
|
|
|
|
switch (indexStr) { |
|
|
|
case '1': // 待付款
|
|
|
|
params.payStatus = false; // 或者 0,取决于后端接口期望的类型
|
|
|
|
params.payStatus = 0; // 0表示未付款
|
|
|
|
break; |
|
|
|
case '2': // 待发货
|
|
|
|
params.payStatus = true; // 或者 1
|
|
|
|
params.deliveryStatus = 10; |
|
|
|
params.payStatus = 1; // 1表示已付款
|
|
|
|
params.deliveryStatus = 10; // 10表示未发货
|
|
|
|
break; |
|
|
|
case '3': // 待收货
|
|
|
|
params.deliveryStatus = 20; |
|
|
|
params.deliveryStatus = 20; // 20表示已发货
|
|
|
|
break; |
|
|
|
case '4': // 已收货
|
|
|
|
params.deliveryStatus = 30; |
|
|
|
case '4': // 已完成
|
|
|
|
params.orderStatus = 1; // 1表示已完成
|
|
|
|
break; |
|
|
|
case '5': // 已完成
|
|
|
|
params.orderStatus = 1; |
|
|
|
case '5': // 已取消
|
|
|
|
// 对于已取消的订单,我们获取所有数据然后在前端筛选
|
|
|
|
// 因为取消状态有多种:2已取消,3取消中,4退款申请中,6退款成功,7客户端申请退款
|
|
|
|
break; |
|
|
|
case '0': // 全部
|
|
|
|
default: |
|
|
|
// 全部订单,不添加额外的筛选条件
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
console.log(`Tab ${indexStr} (${tabs[Number(index)]?.title}) 筛选参数:`, params); |
|
|
|
return params; |
|
|
|
}; |
|
|
|
|
|
|
|
const reload = async (resetPage = false) => { |
|
|
|
setLoading(true); |
|
|
|
const currentPage = resetPage ? 1 : page; |
|
|
|
const params = getOrderStatusParams(tapIndex); |
|
|
|
pageShopOrder({ page: currentPage, ...params }).then(async res => { |
|
|
|
const statusParams = getOrderStatusParams(tapIndex); |
|
|
|
const searchConditions = { |
|
|
|
page: currentPage, |
|
|
|
...statusParams, |
|
|
|
...props.searchParams |
|
|
|
}; |
|
|
|
console.log('订单筛选条件:', { |
|
|
|
tapIndex, |
|
|
|
statusParams, |
|
|
|
searchConditions |
|
|
|
}); |
|
|
|
pageShopOrder(searchConditions).then(async res => { |
|
|
|
let newList: OrderWithGoods[] | undefined = []; |
|
|
|
if (res?.list && res?.list.length > 0) { |
|
|
|
// 为每个订单获取商品信息
|
|
|
@ -147,7 +211,11 @@ function OrderList(props: OrderListProps) { |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
newList = resetPage ? ordersWithGoods : list?.concat(ordersWithGoods); |
|
|
|
// 合并数据
|
|
|
|
const combinedList = resetPage ? ordersWithGoods : list?.concat(ordersWithGoods); |
|
|
|
|
|
|
|
// 根据当前tab筛选订单,排除已取消的订单
|
|
|
|
newList = filterOrdersByTab(combinedList, Number(tapIndex)); |
|
|
|
setHasMore(true); |
|
|
|
} else { |
|
|
|
newList = []; |
|
|
@ -155,6 +223,11 @@ function OrderList(props: OrderListProps) { |
|
|
|
} |
|
|
|
setList(newList || []); |
|
|
|
setPage(currentPage); |
|
|
|
setTotalCount(res?.count || 0); |
|
|
|
setLoading(false); |
|
|
|
}).catch(error => { |
|
|
|
console.error('加载订单失败:', error); |
|
|
|
setLoading(false); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
@ -186,14 +259,11 @@ function OrderList(props: OrderListProps) { |
|
|
|
// 取消订单
|
|
|
|
const cancelOrder = async (order: ShopOrder) => { |
|
|
|
try { |
|
|
|
await updateShopOrder({ |
|
|
|
...order, |
|
|
|
orderStatus: 2 // 已取消
|
|
|
|
}); |
|
|
|
await removeShopOrder(order.orderId); |
|
|
|
Taro.showToast({ |
|
|
|
title: '订单已取消', |
|
|
|
title: '订单已删除', |
|
|
|
}); |
|
|
|
reload(true); // 重新加载列表
|
|
|
|
reload(true).then(); // 重新加载列表
|
|
|
|
props.onReload?.(); // 通知父组件刷新
|
|
|
|
} catch (error) { |
|
|
|
console.error('取消订单失败:', error); |
|
|
@ -207,25 +277,58 @@ function OrderList(props: OrderListProps) { |
|
|
|
reload(true); // 首次加载或tab切换时重置页码
|
|
|
|
}, [tapIndex]); // 监听tapIndex变化
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
reload(true); // 搜索参数变化时重置页码
|
|
|
|
}, [props.searchParams]); // 监听搜索参数变化
|
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<Tabs |
|
|
|
align={'left'} |
|
|
|
className={'fixed left-0'} |
|
|
|
style={{ top: '44px'}} |
|
|
|
tabStyle={{ backgroundColor: '#ffffff'}} |
|
|
|
style={{ |
|
|
|
top: '44px', |
|
|
|
zIndex: 998, |
|
|
|
borderBottom: '1px solid #e5e5e5' |
|
|
|
}} |
|
|
|
tabStyle={{ |
|
|
|
backgroundColor: '#ffffff', |
|
|
|
boxShadow: '0 2px 4px rgba(0,0,0,0.1)' |
|
|
|
}} |
|
|
|
value={tapIndex} |
|
|
|
onChange={(paneKey) => { |
|
|
|
console.log('Tab切换到:', paneKey, '对应状态:', tabs[paneKey]?.title); |
|
|
|
setTapIndex(paneKey) |
|
|
|
}} |
|
|
|
> |
|
|
|
{ |
|
|
|
tabs?.map((item, index) => { |
|
|
|
return <TabPane key={index} title={item.title}></TabPane> |
|
|
|
return ( |
|
|
|
<TabPane |
|
|
|
key={index} |
|
|
|
title={loading && tapIndex === index ? `${item.title}...` : item.title} |
|
|
|
></TabPane> |
|
|
|
) |
|
|
|
}) |
|
|
|
} |
|
|
|
</Tabs> |
|
|
|
<div style={InfiniteUlStyle} id="scroll"> |
|
|
|
<div style={getInfiniteUlStyle(props.showSearch)} id="scroll"> |
|
|
|
{/* 筛选状态提示 */} |
|
|
|
{tapIndex !== 0 && ( |
|
|
|
<View className="filter-tip" style={{ |
|
|
|
padding: '8px 16px', |
|
|
|
backgroundColor: '#f0f8ff', |
|
|
|
borderLeft: '3px solid #007bff', |
|
|
|
margin: '8px 16px', |
|
|
|
borderRadius: '4px', |
|
|
|
fontSize: '12px', |
|
|
|
color: '#666' |
|
|
|
}}> |
|
|
|
当前筛选: {tabs[Number(tapIndex)]?.title} |
|
|
|
{totalCount >= 0 && ` (${totalCount}条)`} |
|
|
|
</View> |
|
|
|
)} |
|
|
|
|
|
|
|
<InfiniteLoading |
|
|
|
target="scroll" |
|
|
|
hasMore={hasMore} |
|
|
@ -299,9 +402,9 @@ function OrderList(props: OrderListProps) { |
|
|
|
{/* 操作按钮 */} |
|
|
|
<Space className={'btn flex justify-end'}> |
|
|
|
{/* 待付款状态:显示取消订单和立即支付 */} |
|
|
|
{(!item.payStatus || item.payStatus === false) && item.orderStatus !== 2 && ( |
|
|
|
{(!item.payStatus) && item.orderStatus !== 2 && ( |
|
|
|
<Space> |
|
|
|
<Button size={'small'} onClick={(e) => {e.stopPropagation(); cancelOrder(item)}}>取消订单</Button> |
|
|
|
<Button size={'small'} onClick={(e) => {e.stopPropagation(); cancelOrder(item)}}>删除订单</Button> |
|
|
|
<Button size={'small'} type="primary" onClick={(e) => {e.stopPropagation(); console.log('立即支付')}}>立即支付</Button> |
|
|
|
</Space> |
|
|
|
)} |
|
|
|