Merge branch 'develop' of https://gitee.com/L-Shilin/go-fly-platform-services into feature_dzc
# Conflicts: # zlt-doc/TOURISM_WITH_DISTANCE_FIX.md # zlt-doc/优惠券管理功能说明.md # zlt-doc/微信平台证书配置说明.md # zlt-doc/携程优惠券对接接口文档.md # zlt-doc/服务商模式配置说明.md
This commit is contained in:
@@ -55,6 +55,8 @@
|
||||
"@umijs/route-utils": "^2.0.0",
|
||||
"antd": "^4.20.0",
|
||||
"classnames": "^2.3.0",
|
||||
"echarts": "^5.6.0",
|
||||
"echarts-for-react": "^3.0.2",
|
||||
"file-saver": "^2.0.5",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.29.0",
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch } from 'antd';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch, Pagination } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { dashboard, getQrcodeOptions } from '@/services/orders/api';
|
||||
import { Area, Column, Pie } from '@ant-design/plots';
|
||||
import { dashboard, getQrcodeOptions, getDashboardOrders } from '@/services/orders/api';
|
||||
import { Line, Column, Pie } from '@ant-design/plots';
|
||||
import ReactECharts from 'echarts-for-react';
|
||||
import {
|
||||
ShoppingCartOutlined,
|
||||
PayCircleOutlined,
|
||||
@@ -43,6 +44,10 @@ interface Statistics {
|
||||
todayOrders: number;
|
||||
orderGrowth: number;
|
||||
completionRate: number;
|
||||
refundedOrders: number; // 退款订单数
|
||||
completedOrders: number; // 总完成订单数
|
||||
totalPaidOrders: number; // 总收款订单数
|
||||
todayPaidOrders: number; // 今日收款订单数
|
||||
// 对账相关字段
|
||||
totalAmount: number; // 订单总金额(分)
|
||||
refundAmount: number; // 退款金额(分)
|
||||
@@ -63,6 +68,11 @@ interface Statistics {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
qrcodeOrderCount: {
|
||||
qrcodeName: string;
|
||||
qrcodeId: string;
|
||||
orderCount: number;
|
||||
}[];
|
||||
};
|
||||
// 新增筛选维度数据
|
||||
filterOptions: {
|
||||
@@ -85,6 +95,13 @@ const Welcome: React.FC = () => {
|
||||
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
|
||||
// 新增是否包含测试二维码筛选,默认不包含
|
||||
const [includeTestQrcodes, setIncludeTestQrcodes] = useState<boolean>(false);
|
||||
// 订单列表数据
|
||||
const [orderList, setOrderList] = useState<any[]>([]);
|
||||
const [orderPagination, setOrderPagination] = useState({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
@@ -107,8 +124,34 @@ const Welcome: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const fetchOrderList = async (page = 1) => {
|
||||
try {
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
page: page,
|
||||
limit: orderPagination.pageSize,
|
||||
};
|
||||
const result = await getDashboardOrders(params);
|
||||
if (result.resp_code === 0) {
|
||||
setOrderList(result.data?.data || []);
|
||||
setOrderPagination(prev => ({
|
||||
...prev,
|
||||
current: page,
|
||||
total: result.data?.count || 0,
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取订单列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
fetchOrderList(1); // 重置到第一页
|
||||
}, [selectedTourism, selectedQrcode, timeRange, includeTestQrcodes]);
|
||||
|
||||
// 处理景区选择变化
|
||||
@@ -157,15 +200,150 @@ const Welcome: React.FC = () => {
|
||||
const filterOptions = statistics.filterOptions || {};
|
||||
|
||||
// 使用后端返回的基础数据
|
||||
// 订单总金额:orderStatus=3+orderStatus=8的总金额(包含逻辑删除记录)
|
||||
// 退款金额:orderStatus=8的总金额(包含逻辑删除记录)
|
||||
// 净收入:总金额 - 退款金额
|
||||
const totalAmount = orderStats.totalAmount || 0;
|
||||
const refundAmount = orderStats.refundAmount || 0;
|
||||
const netIncome = orderStats.netIncome || 0;
|
||||
|
||||
// 判断是否选择了时间区间
|
||||
const hasTimeRange = timeRange[0] && timeRange[1];
|
||||
|
||||
// 根据时间筛选状态动态显示标题
|
||||
const getOrderTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return '区间收款数量';
|
||||
}
|
||||
return '总收款数量';
|
||||
};
|
||||
|
||||
const getTodayTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return '区间总收款'; // 时间筛选时显示区间总收款
|
||||
}
|
||||
return '今日总收款'; // 无时间筛选时显示今日总收款
|
||||
};
|
||||
|
||||
const getTodayValue = () => {
|
||||
if (hasTimeRange) {
|
||||
return orderStats.totalOrders || 0; // 时间筛选时显示区间总订单数
|
||||
}
|
||||
return orderStats.todayOrders || 0; // 无时间筛选时显示今日订单数
|
||||
};
|
||||
|
||||
const getTodayRefundTitle = () => {
|
||||
return '今日退款订单';
|
||||
};
|
||||
|
||||
const getTodayRefundValue = () => {
|
||||
if (hasTimeRange) {
|
||||
return orderStats.refundedOrders || 0; // 时间筛选时显示区间退款订单数
|
||||
}
|
||||
return orderStats.todayRefundedOrders || 0; // 无时间筛选时显示今日退款订单数
|
||||
};
|
||||
|
||||
// 今日收款数量始终显示今日数据,不受时间范围影响
|
||||
const getTodayPaidValue = () => {
|
||||
if (hasTimeRange) {
|
||||
// 时间筛选时:区间收款订单数 = 区间总订单数 - 区间退款订单数
|
||||
const totalOrders = orderStats.totalOrders || 0;
|
||||
const refundedOrders = orderStats.refundedOrders || 0;
|
||||
return totalOrders - refundedOrders;
|
||||
}
|
||||
// 无时间筛选时:今日收款订单数 = 今日总订单数 - 今日退款订单数
|
||||
const todayOrders = orderStats.todayOrders || 0;
|
||||
const todayRefundedOrders = orderStats.todayRefundedOrders || 0;
|
||||
return todayOrders - todayRefundedOrders;
|
||||
};
|
||||
|
||||
// 获取今日收款数量标题
|
||||
const getTodayPaidTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return '区间净收款'; // 时间筛选时显示区间净收款
|
||||
}
|
||||
return '今日净收款'; // 无时间筛选时显示今日净收款
|
||||
};
|
||||
|
||||
// 获取订单状态文本
|
||||
const getOrderStatusText = (status: number) => {
|
||||
const statusMap: { [key: number]: string } = {
|
||||
0: '待支付',
|
||||
1: '已支付排队中',
|
||||
2: '已取消',
|
||||
3: '设备执行完成',
|
||||
4: '正在服务中',
|
||||
5: '素材上传中',
|
||||
6: '素材上传完成',
|
||||
7: '退款中',
|
||||
8: '已退款',
|
||||
9: '退款失败',
|
||||
};
|
||||
return statusMap[status] || '未知状态';
|
||||
};
|
||||
|
||||
// 时间快捷选择处理函数
|
||||
const handleQuickTimeSelect = (type: 'today' | 'week' | 'month') => {
|
||||
const now = new Date();
|
||||
let startDate: Date;
|
||||
let endDate: Date;
|
||||
|
||||
switch (type) {
|
||||
case 'today':
|
||||
// 自然日:当天 00:00:00 到 23:59:59
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
|
||||
console.log('今日筛选 - 当前时间:', now.toISOString());
|
||||
console.log('今日筛选 - 开始时间:', startDate.toISOString());
|
||||
console.log('今日筛选 - 结束时间:', endDate.toISOString());
|
||||
break;
|
||||
case 'week':
|
||||
// 自然周:本周一 00:00:00 到 本周日 23:59:59
|
||||
const dayOfWeek = now.getDay();
|
||||
const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 距离本周一的天数
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysToMonday);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + (6 - dayOfWeek), 23, 59, 59);
|
||||
console.log('本周筛选 - 当前时间:', now.toISOString());
|
||||
console.log('本周筛选 - 开始时间:', startDate.toISOString());
|
||||
console.log('本周筛选 - 结束时间:', endDate.toISOString());
|
||||
break;
|
||||
case 'month':
|
||||
// 自然月:本月1号 00:00:00 到 本月最后一天 23:59:59
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
|
||||
console.log('本月筛选 - 当前时间:', now.toISOString());
|
||||
console.log('本月筛选 - 开始时间:', startDate.toISOString());
|
||||
console.log('本月筛选 - 结束时间:', endDate.toISOString());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用本地时间格式化,避免时区问题
|
||||
const formatLocalDateTime = (date: Date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
};
|
||||
|
||||
const timeRangeStrings: [string, string] = [
|
||||
formatLocalDateTime(startDate),
|
||||
formatLocalDateTime(endDate)
|
||||
];
|
||||
|
||||
console.log('设置时间范围:', timeRangeStrings);
|
||||
setTimeRange(timeRangeStrings);
|
||||
};
|
||||
|
||||
// 动态分账金额计算(基于净收入和分账比例)
|
||||
const platformAmount = Math.round(netIncome * platformRate);
|
||||
const tourismAmount = netIncome - platformAmount;
|
||||
|
||||
// 订单趋势配置
|
||||
// 订单趋势配置 - 改为折线图
|
||||
const orderTrendConfig = {
|
||||
data: chartStats.orderTrend || [],
|
||||
xField: 'date',
|
||||
@@ -176,41 +354,118 @@ const Welcome: React.FC = () => {
|
||||
legend: {
|
||||
position: 'top' as const,
|
||||
},
|
||||
areaStyle: {
|
||||
fillOpacity: 0.6,
|
||||
// 移除面积图样式,改为折线图
|
||||
line: {
|
||||
size: 2,
|
||||
},
|
||||
};
|
||||
|
||||
// 订单分布配置
|
||||
const orderDistConfig = {
|
||||
data: chartStats.orderDistribution || [],
|
||||
angleField: 'value',
|
||||
colorField: 'type',
|
||||
radius: 0.8,
|
||||
label: {
|
||||
type: 'outer',
|
||||
content: '{name} {percentage}',
|
||||
point: {
|
||||
size: 4,
|
||||
shape: 'circle',
|
||||
},
|
||||
};
|
||||
|
||||
// 收入构成图表数据
|
||||
const incomeConfig = {
|
||||
data: [
|
||||
{ type: '平台分账', value: platformAmount / 100 },
|
||||
{ type: '景区分账', value: tourismAmount / 100 },
|
||||
{ type: '退款金额', value: refundAmount / 100 },
|
||||
],
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
label: {
|
||||
position: 'middle' as const,
|
||||
style: {
|
||||
fill: '#FFFFFF',
|
||||
opacity: 0.6,
|
||||
color: ['#1890ff', '#52c41a', '#faad14'],
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
tickCount: 7,
|
||||
},
|
||||
yAxis: {
|
||||
label: {
|
||||
formatter: (v: any) => `${v}单`,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
shared: true,
|
||||
showCrosshairs: true,
|
||||
crosshairs: {
|
||||
type: 'xy' as const,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 二维码订单数量配置 - ECharts 横向柱状图(按数量降序排列)
|
||||
const qrcodeOrderData = (chartStats.qrcodeOrderCount || []).sort((a: any, b: any) => b.orderCount - a.orderCount);
|
||||
|
||||
// 确保数据按订单数量从多到少排列,最多的显示在最上面
|
||||
const sortedData = [...qrcodeOrderData].sort((a: any, b: any) => b.orderCount - a.orderCount);
|
||||
|
||||
const qrcodeOrderConfig = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
axisPointer: {
|
||||
type: 'shadow'
|
||||
},
|
||||
formatter: function(params: any) {
|
||||
const data = params[0];
|
||||
const total = sortedData.reduce((sum: number, item: any) => sum + item.orderCount, 0);
|
||||
const percentage = ((data.value / total) * 100).toFixed(2);
|
||||
return `${data.name}<br/>订单数量: ${data.value}单<br/>占比: ${percentage}%`;
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: '15%',
|
||||
right: '15%',
|
||||
bottom: '3%',
|
||||
top: '3%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'value',
|
||||
name: '订单数量',
|
||||
axisLabel: {
|
||||
formatter: '{value}单',
|
||||
fontSize: 12
|
||||
},
|
||||
nameTextStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
type: 'category',
|
||||
name: '二维码',
|
||||
data: sortedData.map((item: any) => item.qrcodeName),
|
||||
axisLabel: {
|
||||
width: 120,
|
||||
overflow: 'truncate',
|
||||
fontSize: 12
|
||||
},
|
||||
nameTextStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '订单数量',
|
||||
type: 'bar',
|
||||
data: sortedData.map((item: any) => {
|
||||
const total = sortedData.reduce((sum: number, dataItem: any) => sum + dataItem.orderCount, 0);
|
||||
const percentage = ((item.orderCount / total) * 100).toFixed(2);
|
||||
return {
|
||||
value: item.orderCount,
|
||||
itemStyle: {
|
||||
color: '#52c41a' // 绿色,与图片中的颜色一致
|
||||
}
|
||||
};
|
||||
}),
|
||||
itemStyle: {
|
||||
color: '#52c41a'
|
||||
},
|
||||
label: {
|
||||
show: true,
|
||||
position: 'right',
|
||||
formatter: function(params: any) {
|
||||
const total = sortedData.reduce((sum: number, item: any) => sum + item.orderCount, 0);
|
||||
const percentage = ((params.value / total) * 100).toFixed(2);
|
||||
return `${params.value}单 (${percentage}%)`;
|
||||
},
|
||||
fontSize: 11,
|
||||
color: '#666'
|
||||
},
|
||||
barWidth: '60%'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<PageContainer className={styles.container}>
|
||||
|
||||
@@ -255,18 +510,22 @@ const Welcome: React.FC = () => {
|
||||
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
||||
</span>
|
||||
|
||||
{/* 快速选择常用分账比例 */}
|
||||
{/* 时间快捷选择 */}
|
||||
<Space size="small">
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>快速选择:</span>
|
||||
{[0.7, 0.6, 0.5, 0.4, 0.3].map(rate => (
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>时间快捷选择:</span>
|
||||
{[
|
||||
{ key: 'today', label: '今日' },
|
||||
{ key: 'week', label: '本周' },
|
||||
{ key: 'month', label: '本月' }
|
||||
].map(item => (
|
||||
<Button
|
||||
key={rate}
|
||||
key={item.key}
|
||||
size="small"
|
||||
type={platformRate === rate ? 'primary' : 'default'}
|
||||
onClick={() => setPlatformRate(rate)}
|
||||
type={timeRange[0] && timeRange[1] ? 'primary' : 'default'}
|
||||
onClick={() => handleQuickTimeSelect(item.key as 'today' | 'week' | 'month')}
|
||||
style={{ fontSize: '11px', padding: '0 6px' }}
|
||||
>
|
||||
{Math.round(rate * 100)}%
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
@@ -312,21 +571,29 @@ const Welcome: React.FC = () => {
|
||||
<ShoppingCartOutlined className={styles.iconOrders} />
|
||||
<span>订单总览</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="总订单数"
|
||||
value={orderStats.totalOrders || 0}
|
||||
suffix={
|
||||
<span className={styles.trend}>
|
||||
<RiseOutlined /> {orderStats.orderGrowth || 0}%
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic title="今日订单" value={orderStats.todayOrders || 0} />
|
||||
<div className="subStats___2WPW1">
|
||||
<Statistic
|
||||
title="完成率"
|
||||
value={orderStats.completionRate || 0}
|
||||
suffix="%"
|
||||
title={getOrderTitle()}
|
||||
value={orderStats.totalOrders || 0}
|
||||
/>
|
||||
<Statistic
|
||||
title={hasTimeRange ? "区间净收款数量" : "总净收款数量"}
|
||||
value={(orderStats.totalOrders || 0) - (orderStats.refundedOrders || 0)}
|
||||
/>
|
||||
<Statistic
|
||||
title={hasTimeRange ? "区间退款订单数" : "总退款订单数"}
|
||||
value={orderStats.refundedOrders || 0}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic title={getTodayTitle()} value={getTodayValue()} />
|
||||
<Statistic
|
||||
title={getTodayPaidTitle()}
|
||||
value={getTodayPaidValue()}
|
||||
/>
|
||||
<Statistic
|
||||
title={getTodayRefundTitle()}
|
||||
value={getTodayRefundValue()}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
@@ -339,14 +606,14 @@ const Welcome: React.FC = () => {
|
||||
<span>收入统计</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="订单总金额"
|
||||
title="订单总金额 (有效订单)"
|
||||
value={(orderStats.totalAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic
|
||||
title="景区净收入"
|
||||
title="净收入"
|
||||
value={netIncome / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
@@ -358,6 +625,7 @@ const Welcome: React.FC = () => {
|
||||
prefix="¥"
|
||||
/>
|
||||
</div>
|
||||
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
@@ -395,22 +663,82 @@ const Welcome: React.FC = () => {
|
||||
{/* 图表展示 */}
|
||||
<Row gutter={[16, 16]} className={styles.chartsRow}>
|
||||
<Col xs={24} lg={16}>
|
||||
<Card title="订单趋势" loading={loading}>
|
||||
<Area {...orderTrendConfig} height={300} />
|
||||
<Card title="订单趋势折线图(创建/完成/退款)" loading={loading}>
|
||||
<Line {...orderTrendConfig} height={300} />
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={8}>
|
||||
<Card title="订单状态分布" loading={loading}>
|
||||
<Pie {...orderDistConfig} height={300} />
|
||||
<Card title="二维码订单数量" loading={loading}>
|
||||
<ReactECharts
|
||||
option={qrcodeOrderConfig}
|
||||
style={{ height: '300px' }}
|
||||
notMerge={true}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 收入构成 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
{/* 订单列表 */}
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 24 }}>
|
||||
<Col xs={24}>
|
||||
<Card title="收入构成分析" loading={loading}>
|
||||
<Column {...incomeConfig} height={300} />
|
||||
<Card title="最新订单列表" loading={loading}>
|
||||
<div style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
||||
{orderList.length > 0 ? (
|
||||
<div>
|
||||
{orderList.map((order, index) => (
|
||||
<div
|
||||
key={order.id || index}
|
||||
style={{
|
||||
padding: '12px',
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 'bold', marginBottom: '4px' }}>
|
||||
订单号: {order.orderNo}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
创建时间: {order.createTime}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
状态: {getOrderStatusText(order.orderStatus)}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<div style={{ fontWeight: 'bold', color: '#1890ff' }}>
|
||||
¥{(order.orderAmount / 100).toFixed(2)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '40px', color: '#999' }}>
|
||||
暂无订单数据
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* 分页组件 */}
|
||||
{orderPagination.total > 0 && (
|
||||
<div style={{ textAlign: 'center', marginTop: '16px' }}>
|
||||
<Pagination
|
||||
current={orderPagination.current}
|
||||
pageSize={orderPagination.pageSize}
|
||||
total={orderPagination.total}
|
||||
showSizeChanger={false}
|
||||
showQuickJumper
|
||||
showTotal={(total, range) =>
|
||||
`第 ${range[0]}-${range[1]} 条,共 ${total} 条`
|
||||
}
|
||||
onChange={(page) => {
|
||||
fetchOrderList(page);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { order, updateOrder, getOrderDetail } from '@/services/orders/api';
|
||||
import { order, updateOrder, getOrderDetail, tourism } from '@/services/orders/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Space, Tag, message } from 'antd';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import { STATUS_CONFIG, STATUS_OPTIONS } from './constants';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import DetailModal from './components/DetailModal';
|
||||
@@ -23,10 +23,11 @@ const TableList: React.FC = () => {
|
||||
const [detailModalVisible, setDetailModalVisible] = useState<boolean>(false);
|
||||
const [detailData, setDetailData] = useState<API.OrderDetail>();
|
||||
const [detailLoading, setDetailLoading] = useState<boolean>(false);
|
||||
const [tourismOptions, setTourismOptions] = useState<{ label: string; value: number; }[]>([]);
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = useCallback((status: number) => {
|
||||
const statusInfo = STATUS_CONFIG[status] || { color: 'gray', text: '未知状态' };
|
||||
const statusInfo = STATUS_CONFIG[status as keyof typeof STATUS_CONFIG] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
}, []);
|
||||
|
||||
@@ -39,7 +40,7 @@ const TableList: React.FC = () => {
|
||||
const result = await updateOrder({
|
||||
id: currentRow.id,
|
||||
orderStatus: fields.orderStatus,
|
||||
});
|
||||
} as any);
|
||||
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
@@ -55,6 +56,32 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
}, [currentRow]);
|
||||
|
||||
// 获取景区选项
|
||||
const fetchTourismOptions = async () => {
|
||||
try {
|
||||
// 调用真实的景区列表API
|
||||
const result = await tourism({
|
||||
current: 1,
|
||||
pageSize: 1000, // 获取所有景区
|
||||
});
|
||||
|
||||
if (result.data && result.data.length > 0) {
|
||||
// 将景区数据转换为选项格式
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: item.tourismName || item.name || `景区${item.id}`,
|
||||
value: item.id,
|
||||
}));
|
||||
setTourismOptions(options);
|
||||
} else {
|
||||
setTourismOptions([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取景区选项失败:', error);
|
||||
message.error('获取景区列表失败');
|
||||
setTourismOptions([]);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取订单详情
|
||||
const handleViewDetail = async (orderNo: string) => {
|
||||
setDetailModalVisible(true);
|
||||
@@ -76,6 +103,11 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 组件加载时获取景区选项
|
||||
useEffect(() => {
|
||||
fetchTourismOptions();
|
||||
}, []);
|
||||
|
||||
const columns: ProColumns<ORDERS.Order>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
@@ -134,7 +166,10 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'orderStatus',
|
||||
render: (status) => renderStatus(status as number),
|
||||
width: 120,
|
||||
filters: STATUS_OPTIONS,
|
||||
filters: STATUS_OPTIONS.map(option => ({
|
||||
text: option.label,
|
||||
value: option.value,
|
||||
})),
|
||||
filterMultiple: false,
|
||||
},
|
||||
{
|
||||
@@ -178,20 +213,22 @@ const TableList: React.FC = () => {
|
||||
return (
|
||||
<PageContainer header={{ title: '订单管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={8}
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => {
|
||||
// 处理查询参数
|
||||
const params = {
|
||||
orderNo: values.orderNo?.trim(), // 去除空格
|
||||
orderStatus: values.orderStatus, // 状态
|
||||
tourismId: values.tourismId, // 景区ID
|
||||
};
|
||||
// 过滤掉空值
|
||||
const validParams = Object.fromEntries(
|
||||
Object.entries(params).filter(([_, value]) => value !== undefined && value !== '')
|
||||
);
|
||||
console.log('订单查询条件变化:', validParams);
|
||||
setParams(validParams);
|
||||
}}
|
||||
>
|
||||
@@ -207,6 +244,20 @@ const TableList: React.FC = () => {
|
||||
options={STATUS_OPTIONS}
|
||||
allowClear
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
allowClear
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toString().toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
</QueryFilter>
|
||||
|
||||
<ProTable<ORDERS.Order>
|
||||
@@ -214,13 +265,14 @@ const TableList: React.FC = () => {
|
||||
headerTitle="订单列表"
|
||||
request={async (params) => {
|
||||
// 处理表格请求参数
|
||||
const { current, pageSize, orderNo, orderStatus } = params;
|
||||
const { current, pageSize, orderNo, orderStatus, tourismId } = params;
|
||||
const result = await order({
|
||||
current,
|
||||
pageSize,
|
||||
orderNo,
|
||||
orderStatus: orderStatus ? Number(orderStatus) : undefined,
|
||||
});
|
||||
tourismId: tourismId ? Number(tourismId) : undefined,
|
||||
} as any);
|
||||
return result;
|
||||
}}
|
||||
actionRef={actionRef}
|
||||
@@ -230,8 +282,8 @@ const TableList: React.FC = () => {
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
defaultPageSize: 10,
|
||||
pageSizeOptions: ['10', '20', '50'],
|
||||
defaultPageSize: 20,
|
||||
pageSizeOptions: ['10', '20', '50', '100'],
|
||||
}}
|
||||
dateFormatter="string"
|
||||
toolbar={{
|
||||
|
||||
+11
-1
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
@@ -42,6 +42,16 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
const [form] = Form.useForm();
|
||||
const enableProfit = Form.useWatch('enableProfit', form);
|
||||
|
||||
// 监听values变化,重置表单数据
|
||||
useEffect(() => {
|
||||
if (updateModalVisible && values) {
|
||||
form.setFieldsValue({
|
||||
...values,
|
||||
enableProfit: values?.enableProfit ?? 0,
|
||||
});
|
||||
}
|
||||
}, [values, updateModalVisible, form]);
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改二维码"
|
||||
|
||||
@@ -96,6 +96,8 @@ const TableList: React.FC = () => {
|
||||
const [tenantOptions, setTenantOptions] = useState<any[]>([]);
|
||||
const formRef = useRef();
|
||||
|
||||
|
||||
|
||||
// 将 renderStatus 函数移到组件内部
|
||||
const renderStatus = (status: number) => {
|
||||
const statusColorMap: Record<number, { color: string; text: string }> = {
|
||||
@@ -503,7 +505,10 @@ const TableList: React.FC = () => {
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={setParams}
|
||||
onFinish={(values) => {
|
||||
console.log('查询条件变化:', values);
|
||||
setParams(values);
|
||||
}}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="tourismId"
|
||||
|
||||
@@ -198,6 +198,23 @@ export async function dashboard(params?: {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取首页订单列表 GET /api-order/dashboard/orders */
|
||||
export async function getDashboardOrders(params?: {
|
||||
tourismId?: number;
|
||||
qrcodeId?: string;
|
||||
deviceSn?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
includeTestQrcodes?: boolean;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}) {
|
||||
return request('/api-order/dashboard/orders', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取二维码列表 GET /api-order/qrcode/options */
|
||||
export async function getQrcodeOptions(params?: {
|
||||
tourismId?: number;
|
||||
|
||||
Reference in New Issue
Block a user