!23 fix(订单中心):首页统计优化
Merge pull request !23 from Iamasoldier/feature_lsl
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button } from 'antd';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { dashboard } from '@/services/orders/api';
|
||||
import { dashboard, getQrcodeOptions } from '@/services/orders/api';
|
||||
import { Area, Column, Pie } from '@ant-design/plots';
|
||||
import {
|
||||
ShoppingCartOutlined,
|
||||
@@ -15,6 +15,28 @@ import styles from './Welcome.less';
|
||||
const { Title } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
// 平台分账比例选项
|
||||
const PLATFORM_RATE_OPTIONS = [
|
||||
{ label: '90% (平台90%)', value: 0.9 },
|
||||
{ label: '85% (平台85%)', value: 0.85 },
|
||||
{ label: '80% (平台80%)', value: 0.8 },
|
||||
{ label: '75% (平台75%)', value: 0.75 },
|
||||
{ label: '70% (平台70%)', value: 0.7 },
|
||||
{ label: '65% (平台65%)', value: 0.65 },
|
||||
{ label: '60% (平台60%)', value: 0.6 },
|
||||
{ label: '55% (平台55%)', value: 0.55 },
|
||||
{ label: '50% (平台50%)', value: 0.5 },
|
||||
{ label: '45% (平台45%)', value: 0.45 },
|
||||
{ label: '40% (平台40%)', value: 0.4 },
|
||||
{ label: '35% (平台35%)', value: 0.35 },
|
||||
{ label: '30% (平台30%)', value: 0.3 },
|
||||
{ label: '25% (平台25%)', value: 0.25 },
|
||||
{ label: '20% (平台20%)', value: 0.2 },
|
||||
{ label: '15% (平台15%)', value: 0.15 },
|
||||
{ label: '10% (平台10%)', value: 0.1 },
|
||||
{ label: '5% (平台5%)', value: 0.05 },
|
||||
];
|
||||
|
||||
interface Statistics {
|
||||
orderStats: {
|
||||
totalOrders: number;
|
||||
@@ -57,18 +79,24 @@ const Welcome: React.FC = () => {
|
||||
const [statistics, setStatistics] = useState<any>({});
|
||||
// 只保留景区筛选
|
||||
const [selectedTourism, setSelectedTourism] = useState<number | undefined>();
|
||||
// 新增二维码筛选
|
||||
const [selectedQrcode, setSelectedQrcode] = useState<string | undefined>();
|
||||
// 新增平台分账比例,默认70%
|
||||
const [platformRate, setPlatformRate] = useState<number>(0.7);
|
||||
// 新增时间区间筛选
|
||||
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
|
||||
// 新增是否包含测试二维码筛选,默认不包含
|
||||
const [includeTestQrcodes, setIncludeTestQrcodes] = useState<boolean>(false);
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
};
|
||||
const result = await dashboard(params);
|
||||
if (result.resp_code === 0) {
|
||||
@@ -83,7 +111,47 @@ const Welcome: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [selectedTourism, timeRange]);
|
||||
}, [selectedTourism, selectedQrcode, timeRange, includeTestQrcodes]);
|
||||
|
||||
// 处理景区选择变化
|
||||
const handleTourismChange = (tourismId: number | undefined) => {
|
||||
setSelectedTourism(tourismId);
|
||||
// 当景区变化时,清空二维码选择
|
||||
setSelectedQrcode(undefined);
|
||||
// 重新获取二维码选项
|
||||
fetchQrcodeOptions(tourismId);
|
||||
};
|
||||
|
||||
// 获取当前景区下的二维码选项
|
||||
const getCurrentTourismQrcodes = () => {
|
||||
if (!selectedTourism) return [];
|
||||
// 从筛选选项中获取当前景区的二维码
|
||||
return filterOptions.qrcodeList || [];
|
||||
};
|
||||
|
||||
// 获取二维码列表
|
||||
const fetchQrcodeOptions = async (tourismId: number | undefined) => {
|
||||
if (!tourismId) return;
|
||||
try {
|
||||
const params = {
|
||||
tourismId: tourismId,
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
};
|
||||
const result = await getQrcodeOptions(params);
|
||||
if (result.resp_code === 0 && result.data?.qrcodeList) {
|
||||
// 更新二维码选项
|
||||
setStatistics((prev: any) => ({
|
||||
...prev,
|
||||
filterOptions: {
|
||||
...prev.filterOptions,
|
||||
qrcodeList: result.data.qrcodeList
|
||||
}
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取二维码列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 更新数据访问方式
|
||||
const orderStats = statistics.orderStats || {};
|
||||
@@ -153,20 +221,50 @@ const Welcome: React.FC = () => {
|
||||
allowClear
|
||||
options={filterOptions.tourismList || []}
|
||||
value={selectedTourism}
|
||||
onChange={setSelectedTourism}
|
||||
onChange={handleTourismChange}
|
||||
/>
|
||||
{/* 新增二维码选择器 */}
|
||||
<Select
|
||||
placeholder="选择二维码"
|
||||
style={{ width: 200 }}
|
||||
allowClear
|
||||
disabled={!selectedTourism}
|
||||
options={getCurrentTourismQrcodes()}
|
||||
value={selectedQrcode}
|
||||
onChange={setSelectedQrcode}
|
||||
/>
|
||||
{/* 新增平台分账比例选择 */}
|
||||
<span>平台分账比例:</span>
|
||||
<Select
|
||||
style={{ width: 120 }}
|
||||
style={{ width: 140 }}
|
||||
value={platformRate}
|
||||
onChange={setPlatformRate}
|
||||
options={[
|
||||
{ label: '70%', value: 0.7 },
|
||||
{ label: '60%', value: 0.6 },
|
||||
{ label: '50%', value: 0.5 },
|
||||
]}
|
||||
showSearch
|
||||
placeholder="选择分账比例"
|
||||
optionFilterProp="label"
|
||||
filterOption={(input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
options={PLATFORM_RATE_OPTIONS}
|
||||
/>
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>
|
||||
(当前:平台{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 => (
|
||||
<Button
|
||||
key={rate}
|
||||
size="small"
|
||||
type={platformRate === rate ? 'primary' : 'default'}
|
||||
onClick={() => setPlatformRate(rate)}
|
||||
style={{ fontSize: '11px', padding: '0 6px' }}
|
||||
>
|
||||
{Math.round(rate * 100)}%
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
{/* 新增时间区间筛选 */}
|
||||
<RangePicker
|
||||
placeholder={['开始时间', '结束时间']}
|
||||
@@ -190,6 +288,14 @@ const Welcome: React.FC = () => {
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
{/* 新增测试二维码筛选开关 */}
|
||||
<span>包含测试二维码:</span>
|
||||
<Switch
|
||||
checked={includeTestQrcodes}
|
||||
onChange={setIncludeTestQrcodes}
|
||||
checkedChildren="是"
|
||||
unCheckedChildren="否"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@ import {
|
||||
import { Form } from 'antd';
|
||||
import { ENABLE_PROFIT_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_VIDEO_EDIT_OPTIONS } from '../index';
|
||||
|
||||
// 添加测试二维码选项常量
|
||||
export const IS_TEST_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
];
|
||||
|
||||
interface CreateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
@@ -184,6 +190,15 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
||||
rules={[{ required: true, message: '请选择是否开启一键成片' }]}
|
||||
initialValue={0}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="isTest"
|
||||
label="是否为测试二维码"
|
||||
options={IS_TEST_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否为测试二维码' }]}
|
||||
initialValue={0}
|
||||
tooltip="测试二维码的数据不会计入正式统计"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -10,6 +10,12 @@ import { STATUS_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_PROFIT_OPTIONS, ENABLE_VIDEO
|
||||
import { Form, Space } from 'antd';
|
||||
import styles from './index.less';
|
||||
|
||||
// 添加测试二维码选项常量
|
||||
export const IS_TEST_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
];
|
||||
|
||||
interface UpdateFormProps {
|
||||
updateModalVisible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
@@ -184,6 +190,14 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
options={ENABLE_VIDEO_EDIT_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否开启一键成片' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="isTest"
|
||||
label="是否为测试二维码"
|
||||
options={IS_TEST_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否为测试二维码' }]}
|
||||
tooltip="测试二维码的数据不会计入正式统计"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -55,6 +55,12 @@ export const ENABLE_VIDEO_EDIT_OPTIONS = [
|
||||
{ label: '是', value: 1 },
|
||||
] as const;
|
||||
|
||||
// 添加测试二维码选项常量
|
||||
export const IS_TEST_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
] as const;
|
||||
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
@@ -91,7 +97,7 @@ const TableList: React.FC = () => {
|
||||
|
||||
// 将 renderStatus 函数移到组件内部
|
||||
const renderStatus = (status: number) => {
|
||||
const statusColorMap = {
|
||||
const statusColorMap: Record<number, { color: string; text: string }> = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
};
|
||||
@@ -100,12 +106,12 @@ const TableList: React.FC = () => {
|
||||
};
|
||||
|
||||
// 处理添加
|
||||
const handleAdd = async (fields: ORDERS.Qrcode) => {
|
||||
const handleAdd = async (fields: Partial<ORDERS.Qrcode>) => {
|
||||
const template = templateOptions.find(item => item.value === fields.templateId);
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
...fields,
|
||||
}),
|
||||
} as ORDERS.Qrcode),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
@@ -170,7 +176,7 @@ const TableList: React.FC = () => {
|
||||
});
|
||||
|
||||
if (result?.data) {
|
||||
const options = result.data.map(item => ({
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: item.tourismName || item.name,
|
||||
value: item.id,
|
||||
info: item
|
||||
@@ -205,7 +211,7 @@ const TableList: React.FC = () => {
|
||||
});
|
||||
|
||||
if (result?.data) {
|
||||
const options = result.data.map((item: DEVICE.Device) => ({
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: `${item.deviceName}(${item.deviceSn})`,
|
||||
value: item.deviceSn,
|
||||
info: item
|
||||
@@ -225,7 +231,7 @@ const TableList: React.FC = () => {
|
||||
status: 1, // 只获取启用的模板
|
||||
});
|
||||
if (result.data?.data) {
|
||||
const options = result.data.data.map(item => ({
|
||||
const options = result.data.data.map((item: any) => ({
|
||||
label: item.templateName,
|
||||
value: item.templateId,
|
||||
info: item,
|
||||
@@ -418,6 +424,20 @@ const TableList: React.FC = () => {
|
||||
1: { text: '是' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '是否为测试二维码',
|
||||
dataIndex: 'isTest',
|
||||
width: 140,
|
||||
render: (_, record) => {
|
||||
const status = record.isTest === 1 ? '是' : '否';
|
||||
const color = record.isTest === 1 ? 'blue' : 'default';
|
||||
return <Tag color={color}>{status}</Tag>;
|
||||
},
|
||||
valueEnum: {
|
||||
0: { text: '否' },
|
||||
1: { text: '是' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
@@ -480,6 +500,12 @@ const TableList: React.FC = () => {
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="isTest"
|
||||
label="是否为测试二维码"
|
||||
placeholder="请选择是否为测试二维码"
|
||||
options={IS_TEST_OPTIONS}
|
||||
/>
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
rowKey="id"
|
||||
|
||||
+38
@@ -4,6 +4,7 @@ import {
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
|
||||
@@ -30,6 +31,14 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
const formRules = {
|
||||
required: { required: true, message: '此项为必填项' },
|
||||
phone: { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' },
|
||||
longitude: {
|
||||
pattern: /^-?((1[0-7][0-9]|[1-9]?[0-9])\.\d{1,6}|180\.0{1,6})$/,
|
||||
message: '经度范围应在-180到180之间,最多6位小数'
|
||||
},
|
||||
latitude: {
|
||||
pattern: /^-?([1-8]?[0-9]\.\d{1,6}|90\.0{1,6})$/,
|
||||
message: '纬度范围应在-90到90之间,最多6位小数'
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -79,6 +88,35 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
name="longitude"
|
||||
label="经度"
|
||||
width="md"
|
||||
rules={[formRules.longitude]}
|
||||
placeholder="请输入经度(-180到180)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -180,
|
||||
max: 180,
|
||||
}}
|
||||
tooltip="经度范围:-180到180,用于附近景区查询功能"
|
||||
/>
|
||||
<ProFormDigit
|
||||
name="latitude"
|
||||
label="纬度"
|
||||
width="md"
|
||||
rules={[formRules.latitude]}
|
||||
placeholder="请输入纬度(-90到90)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -90,
|
||||
max: 90,
|
||||
}}
|
||||
tooltip="纬度范围:-90到90,用于附近景区查询功能"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="tenantId"
|
||||
|
||||
@@ -10,8 +10,9 @@ import {
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
ProTable,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm, Button, Space } from 'antd';
|
||||
import { Typography, message, Popconfirm, Button, Space, Tag } from 'antd';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
@@ -142,6 +143,22 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'tourismPhone',
|
||||
copyable: true,
|
||||
},
|
||||
{
|
||||
title: '经纬度',
|
||||
dataIndex: 'location',
|
||||
hideInSearch: true,
|
||||
render: (_, record) => {
|
||||
const hasLocation = record.longitude && record.latitude;
|
||||
return hasLocation ? (
|
||||
<Space direction="vertical" size="small">
|
||||
<Tag color="blue">经度: {record.longitude}</Tag>
|
||||
<Tag color="green">纬度: {record.latitude}</Tag>
|
||||
</Space>
|
||||
) : (
|
||||
<Tag color="red">未设置</Tag>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '租户ID',
|
||||
dataIndex: 'tenantId',
|
||||
@@ -192,6 +209,14 @@ const TableList: React.FC = () => {
|
||||
const formRules = {
|
||||
required: { required: true, message: '此项为必填项' },
|
||||
phone: { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' },
|
||||
longitude: {
|
||||
pattern: /^-?((1[0-7][0-9]|[1-9]?[0-9])\.\d{1,6}|180\.0{1,6})$/,
|
||||
message: '经度范围应在-180到180之间,最多6位小数'
|
||||
},
|
||||
latitude: {
|
||||
pattern: /^-?([1-8]?[0-9]\.\d{1,6}|90\.0{1,6})$/,
|
||||
message: '纬度范围应在-90到90之间,最多6位小数'
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -265,6 +290,35 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
name="longitude"
|
||||
label="经度"
|
||||
width="md"
|
||||
rules={[formRules.longitude]}
|
||||
placeholder="请输入经度(-180到180)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -180,
|
||||
max: 180,
|
||||
}}
|
||||
tooltip="经度范围:-180到180,用于附近景区查询功能"
|
||||
/>
|
||||
<ProFormDigit
|
||||
name="latitude"
|
||||
label="纬度"
|
||||
width="md"
|
||||
rules={[formRules.latitude]}
|
||||
placeholder="请输入纬度(-90到90)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -90,
|
||||
max: 90,
|
||||
}}
|
||||
tooltip="纬度范围:-90到90,用于附近景区查询功能"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="tenantId"
|
||||
|
||||
@@ -190,6 +190,7 @@ export async function dashboard(params?: {
|
||||
deviceSn?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
includeTestQrcodes?: boolean;
|
||||
}) {
|
||||
return request('/api-order/dashboard/statistics', {
|
||||
method: 'GET',
|
||||
@@ -197,6 +198,17 @@ export async function dashboard(params?: {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取二维码列表 GET /api-order/qrcode/options */
|
||||
export async function getQrcodeOptions(params?: {
|
||||
tourismId?: number;
|
||||
includeTestQrcodes?: boolean;
|
||||
}) {
|
||||
return request('/api-order/dashboard/qrcode/options', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 分页查询分账记录 */
|
||||
export async function profitSharingList(params: {
|
||||
page: number;
|
||||
|
||||
@@ -33,12 +33,20 @@ declare namespace ORDERS {
|
||||
tourismNo: string;
|
||||
tourismAddress: string;
|
||||
tourismPhone: string;
|
||||
longitude?: number; // 经度
|
||||
latitude?: number; // 纬度
|
||||
createTime?: string;
|
||||
status: number;
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
type TourismWithDistance = Tourism & {
|
||||
distance?: number; // 距离(公里)
|
||||
distanceDesc?: string; // 距离描述
|
||||
orderShowImageUrl?: string; // 景区订单展示图片URL
|
||||
}
|
||||
|
||||
type TourismFile = {
|
||||
id: number;
|
||||
tourismId: string;
|
||||
@@ -55,9 +63,11 @@ declare namespace ORDERS {
|
||||
type Qrcode = {
|
||||
id: number;
|
||||
codeId: string;
|
||||
name?: string;
|
||||
tourismId: string;
|
||||
path: string;
|
||||
fileId: string;
|
||||
viewUrl?: string;
|
||||
price: string;
|
||||
deviceSn: string;
|
||||
createTime?: string;
|
||||
@@ -71,6 +81,10 @@ declare namespace ORDERS {
|
||||
payeeFailReason?: string;
|
||||
templateId: string;
|
||||
materialCount?: number;
|
||||
isTest?: number; // 是否为测试二维码(0:否,1:是)
|
||||
enableProfit?: number; // 是否开启分润(0:否,1:是)
|
||||
enableVideoEdit?: number; // 是否开启一键成片(0:否,1:是)
|
||||
waylineId?: string; // 航线ID
|
||||
}
|
||||
|
||||
type HomeCarousel = {
|
||||
|
||||
Reference in New Issue
Block a user