refactor(user): 优化用户订单相关功能
- 移除 coupon API 中的 SERVER_API_URL,直接使用相对路径 - 优化 order 页面的搜索和重置逻辑- 更新 OrderList 组件,支持空订单时显示 Empty 组件- 调整 UserCard 中的用户统计数据加载逻辑 - 修改 UserOrder 组件中的订单状态文本和链接
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {useState, useCallback, useRef} from "react";
|
||||
import Taro, {useDidShow} from '@tarojs/taro'
|
||||
import {useState, useCallback, useRef, useEffect} from "react";
|
||||
import Taro from '@tarojs/taro'
|
||||
import {Space, NavBar, Button, Input} from '@nutui/nutui-react-taro'
|
||||
import {Search, Filter, ArrowLeft} from '@nutui/icons-react-taro'
|
||||
import {View} from '@tarojs/components';
|
||||
@@ -32,26 +32,27 @@ function Order() {
|
||||
searchTimeoutRef.current = setTimeout(() => {
|
||||
if (keyword.trim()) {
|
||||
handleSearch({keywords: keyword.trim()});
|
||||
} else {
|
||||
// 如果搜索关键词为空,清除keywords参数
|
||||
const newSearchParams = { ...searchParams };
|
||||
delete newSearchParams.keywords;
|
||||
setSearchParams(newSearchParams);
|
||||
reload(newSearchParams).then();
|
||||
}
|
||||
}, 500); // 500ms防抖延迟
|
||||
}, []);
|
||||
}, [searchParams]);
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = (where: ShopOrderParam) => {
|
||||
setSearchParams(where)
|
||||
reload(where).then()
|
||||
// 合并搜索参数,保留当前的statusFilter
|
||||
const newSearchParams = {
|
||||
...searchParams, // 保留当前的所有参数(包括statusFilter)
|
||||
...where // 应用新的搜索条件
|
||||
};
|
||||
setSearchParams(newSearchParams)
|
||||
reload(newSearchParams).then()
|
||||
}
|
||||
|
||||
// 重置搜索
|
||||
const handleResetSearch = () => {
|
||||
setSearchKeyword(''); // 清空搜索关键词
|
||||
setSearchParams({
|
||||
statusFilter: params.statusFilter != undefined && params.statusFilter != '' ? parseInt(params.statusFilter) : -1
|
||||
}); // 重置搜索参数,但保留初始状态筛选
|
||||
reload().then()
|
||||
}
|
||||
|
||||
useDidShow(() => {
|
||||
useEffect(() => {
|
||||
// 获取状态栏高度
|
||||
Taro.getSystemInfo({
|
||||
success: (res) => {
|
||||
@@ -69,7 +70,7 @@ function Order() {
|
||||
});
|
||||
|
||||
reload().then()
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View className="bg-gray-50 min-h-screen">
|
||||
@@ -142,38 +143,11 @@ function Order() {
|
||||
>
|
||||
搜索
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setSearchKeyword('');
|
||||
handleResetSearch();
|
||||
}}
|
||||
>
|
||||
重置
|
||||
</Button>
|
||||
</Space>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
{/*暂无订单*/}
|
||||
{/*{list.length == 0 && (*/}
|
||||
{/* <ConfigProvider>*/}
|
||||
{/* <div className={'h-full flex flex-col justify-center items-center'} style={{*/}
|
||||
{/* height: showSearch ? 'calc(100vh - 200px)' : 'calc(100vh - 150px)',*/}
|
||||
{/* marginTop: showSearch ? '60px' : '0'*/}
|
||||
{/* }}>*/}
|
||||
{/* <Empty*/}
|
||||
{/* style={{*/}
|
||||
{/* backgroundColor: 'transparent'*/}
|
||||
{/* }}*/}
|
||||
{/* description="您还没有订单哦"*/}
|
||||
{/* />*/}
|
||||
{/* <Space>*/}
|
||||
{/* <Button type="success" fill="dashed"*/}
|
||||
{/* onClick={() => Taro.switchTab({url: '/pages/index/index'})}>去挑选商品</Button>*/}
|
||||
{/* </Space>*/}
|
||||
{/* </div>*/}
|
||||
{/* </ConfigProvider>*/}
|
||||
{/*)}*/}
|
||||
|
||||
{/*订单列表*/}
|
||||
<OrderList
|
||||
onReload={() => reload(searchParams)}
|
||||
|
||||
Reference in New Issue
Block a user