fix(订单中心):首页统计优化,优惠券创建逻辑完善
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",
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Sp
|
||||
import React, { useState, useEffect } from 'react';
|
||||
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,
|
||||
@@ -262,6 +263,37 @@ const Welcome: React.FC = () => {
|
||||
return statusMap[status] || '未知状态';
|
||||
};
|
||||
|
||||
// 时间快捷选择处理函数
|
||||
const handleQuickTimeSelect = (type: 'today' | 'week' | 'month') => {
|
||||
const now = new Date();
|
||||
let startDate: Date;
|
||||
let endDate: Date;
|
||||
|
||||
switch (type) {
|
||||
case 'today':
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
|
||||
break;
|
||||
case 'week':
|
||||
const dayOfWeek = now.getDay();
|
||||
const daysToSubtract = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 周一到周日
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysToSubtract);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + (6 - dayOfWeek), 23, 59, 59);
|
||||
break;
|
||||
case 'month':
|
||||
startDate = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeRange([
|
||||
startDate.toISOString().slice(0, 19).replace('T', ' '),
|
||||
endDate.toISOString().slice(0, 19).replace('T', ' ')
|
||||
]);
|
||||
};
|
||||
|
||||
// 动态分账金额计算(基于净收入和分账比例)
|
||||
const platformAmount = Math.round(netIncome * platformRate);
|
||||
const tourismAmount = netIncome - platformAmount;
|
||||
@@ -304,42 +336,87 @@ const Welcome: React.FC = () => {
|
||||
},
|
||||
};
|
||||
|
||||
// 二维码订单数量配置 - 横向柱状图
|
||||
// 二维码订单数量配置 - 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 = {
|
||||
data: chartStats.qrcodeOrderCount || [],
|
||||
xField: 'orderCount',
|
||||
yField: 'qrcodeName',
|
||||
seriesField: 'qrcodeName',
|
||||
bar: {
|
||||
style: {
|
||||
fill: '#1890ff',
|
||||
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}%`;
|
||||
}
|
||||
},
|
||||
label: {
|
||||
position: 'right' as const,
|
||||
style: {
|
||||
fill: '#666',
|
||||
fontSize: 12,
|
||||
},
|
||||
grid: {
|
||||
left: '15%',
|
||||
right: '15%',
|
||||
bottom: '3%',
|
||||
top: '3%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
title: {
|
||||
text: '订单数量',
|
||||
type: 'value',
|
||||
name: '订单数量',
|
||||
axisLabel: {
|
||||
formatter: '{value}单',
|
||||
fontSize: 12
|
||||
},
|
||||
nameTextStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
title: {
|
||||
text: '二维码',
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
formatter: (datum: any) => {
|
||||
return {
|
||||
name: '订单数量',
|
||||
value: datum.orderCount,
|
||||
};
|
||||
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%'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -393,18 +470,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>
|
||||
@@ -450,17 +531,10 @@ const Welcome: React.FC = () => {
|
||||
<ShoppingCartOutlined className={styles.iconOrders} />
|
||||
<span>订单总览</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '16px' }}>
|
||||
<div className="subStats___2WPW1">
|
||||
<Statistic
|
||||
title={getOrderTitle()}
|
||||
value={orderStats.totalOrders || 0}
|
||||
suffix={
|
||||
!hasTimeRange && (
|
||||
<span className={styles.trend}>
|
||||
<RiseOutlined /> {orderStats.orderGrowth || 0}%
|
||||
</span>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Statistic
|
||||
title="总收款数量"
|
||||
@@ -554,13 +628,17 @@ const Welcome: React.FC = () => {
|
||||
</Col>
|
||||
<Col xs={24} lg={8}>
|
||||
<Card title="二维码订单数量" loading={loading}>
|
||||
<Column {...qrcodeOrderConfig} height={300} />
|
||||
<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}>
|
||||
<div style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
||||
|
||||
Reference in New Issue
Block a user