import React, { useRef, useState, useEffect } from 'react'; import { Button, Space, Select, Flex } from 'antd'; import { useTranslation } from 'react-i18next'; import type { ColumnsType } from 'antd/es/table'; import type { SelectProps } from 'antd/es/select' import dayjs from 'dayjs'; import Table, { type TableRef } from '@/components/Table' import StatusTag from '@/components/StatusTag' import { getOrderListUrl, getOrderStatus } from '@/api/order' import { formatDateTime } from '@/utils/format'; import type { Order, OrderDetailRef, Query } from './types' import OrderDetail from './components/OrderDetail' import SearchInput from '@/components/SearchInput' import { PRICE_LIST } from '@/views/Pricing' export const STATUS = { 100: { status: 'warning', key: 'PENDING' }, 150: { key: 'APPROVED', status: 'success' }, 500: { key: 'REJECTED', status: 'error' } } const OrderHistory: React.FC = () => { const { t } = useTranslation(); const orderDetailRef = useRef(null) const tableRef = useRef(null); const [query, setQuery] = useState({ status: null, product_type: null, start_time: null, end_time: null } as Query) const [statusOptions, setStatusOptions] = useState([]) const [timeType, setTimeType] = useState('all') const timeOptions = [ { label: t('pricing.allTime'), value: 'all' }, { label: t('pricing.today'), value: 'today' }, { label: t('pricing.week'), value: '7d' }, { label: t('pricing.month'), value: '1month' }, { label: t('pricing.threeMonth'), value: '3month' }, { label: t('pricing.year'), value: '1year' }, ] const productTypeOptions = [ { label: t('pricing.allType'), value: null }, { label: t('pricing.personal.type'), value: 'FREE' }, { label: t('pricing.team.type'), value: 'TEAM' }, { label: t('pricing.biz.type'), value: 'ENTERPRISE' }, { label: t('pricing.commerce.type'), value: 'OEM' }, ] const handleView = (order: Order) => { orderDetailRef.current?.handleOpen(order) } useEffect(() => { getStatus() }, []) const getStatus = () => { getOrderStatus() .then(res => { const response = res as Record setStatusOptions([ { label: t(`pricing.allStatus`), value: null }, ...Object.keys(response).map(key => ({ label: t(`pricing.${key}`), value: response[key].value })) ]) }) } const handleChangeStatus = (value: string) => { if (value !== query.status) { setQuery(prev => ({ ...prev, status: value })) } } const handleChangeType = (value: string) => { if (value !== query.product_type) { setQuery(prev => ({ ...prev, product_type: value })) } } const handleChangeTime = (value: string) => { setTimeType(value) let start_time = null; let end_time: number | null = dayjs().endOf('day').valueOf() switch(value) { case 'all': start_time = null; end_time = null break case 'today': start_time = dayjs().startOf('day').valueOf() break case '7d': start_time = dayjs().subtract(7, 'day').startOf('day').valueOf() break case '1month': start_time = dayjs().subtract(1, 'month').startOf('day').valueOf() break case '3month': start_time = dayjs().subtract(3, 'month').startOf('day').valueOf() break case '1year': start_time = dayjs().subtract(1, 'year').startOf('day').valueOf() break } setQuery(prev => ({ ...prev, start_time, end_time })) } const getProductType = (type: string) => { const typeMap: Record = { 'FREE': 'personal', 'TEAM': 'team', 'ENTERPRISE': 'biz', 'OEM': 'commerce' }; return typeMap[type] || 'ENTERPRISE'; }; // 表格列配置 const columns: ColumnsType = [ { title: t('pricing.order_no'), dataIndex: 'order_no', key: 'order_no', fixed: 'left', }, { title: t('pricing.product_type'), dataIndex: 'product_type', key: 'product_type', render: (type) => t(`pricing.${getProductType(type)}.type`) }, { title: t('pricing.payable_amount'), dataIndex: 'payable_amount', key: 'payable_amount', render: (amount: number) => `¥${amount}`, }, { title: t('pricing.status'), dataIndex: 'status', key: 'status', render: (status: number) => }, { title: t('pricing.pay_time'), dataIndex: 'pay_time', key: 'pay_time', render: (pay_time: unknown) => formatDateTime(pay_time as string, 'YYYY-MM-DD HH:mm:ss'), }, { title: t('common.operation'), key: 'action', fixed: 'right', render: (_, record) => ( ), }, ]; return (