import { Tag, Typography } from 'antd'; import React from 'react'; import XinTable from '@/components/XinTable'; import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings'; import type IOrder from '@/domain/iOrder'; import { useTranslation } from 'react-i18next'; import dayjs from 'dayjs'; import relativeTime from 'dayjs/plugin/relativeTime'; const { Title, Text } = Typography; dayjs.extend(relativeTime); const Table: React.FC = () => { const { t } = useTranslation(); const columns: XinTableColumn[] = [ { title: t('merchant.portal.order.id'), dataIndex: 'id', hideInForm: true, sorter: true, align: 'center', width: 80, }, { title: t('merchant.portal.order.order_no'), dataIndex: 'order_no', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('merchant.portal.order.user_id'), dataIndex: 'user_id', valueType: 'text', align: 'center', hideInSearch: true, }, { title: t('merchant.portal.order.total_amount'), dataIndex: 'total_amount', hideInForm: true, hideInSearch: true, align: 'center', render: (value: number) => `¥${value ?? '0.00'}`, }, { title: t('merchant.portal.order.discount_amount'), dataIndex: 'discount_amount', hideInForm: true, hideInSearch: true, align: 'center', render: (value: number) => `¥${value ?? '0.00'}`, }, { title: t('merchant.portal.order.delivery_fee'), dataIndex: 'delivery_fee', hideInForm: true, hideInSearch: true, align: 'center', render: (value: number) => `¥${value ?? '0.00'}`, }, { title: t('merchant.portal.order.payment_amount'), dataIndex: 'payment_amount', hideInForm: true, hideInSearch: true, align: 'center', render: (value: number) => `¥${value ?? '0.00'}`, }, { title: t('merchant.portal.order.pay_type'), dataIndex: 'pay_type', valueType: 'select', fieldProps: { options: [ { value: 0, label: t('merchant.portal.order.pay_type.0') }, { value: 1, label: t('merchant.portal.order.pay_type.1') }, ], }, render: (value: number) => { const colorMap: Record = { 0: 'default', 1: 'blue' }; const labelMap: Record = { 0: t('merchant.portal.order.pay_type.0'), 1: t('merchant.portal.order.pay_type.1'), }; return {labelMap[value] ?? '-'}; }, filters: [ { text: t('merchant.portal.order.pay_type.0'), value: 0 }, { text: t('merchant.portal.order.pay_type.1'), value: 1 }, ], align: 'center', }, { title: t('merchant.portal.order.pay_status'), dataIndex: 'pay_status', valueType: 'select', fieldProps: { options: [ { value: 0, label: t('merchant.portal.order.pay_status.0') }, { value: 1, label: t('merchant.portal.order.pay_status.1') }, { value: 2, label: t('merchant.portal.order.pay_status.2') }, { value: 3, label: t('merchant.portal.order.pay_status.3') }, ], }, render: (value: number) => { const colorMap: Record = { 0: 'warning', 1: 'success', 2: 'processing', 3: 'default' }; const labelMap: Record = { 0: t('merchant.portal.order.pay_status.0'), 1: t('merchant.portal.order.pay_status.1'), 2: t('merchant.portal.order.pay_status.2'), 3: t('merchant.portal.order.pay_status.3'), }; return {labelMap[value] ?? '-'}; }, filters: [ { text: t('merchant.portal.order.pay_status.0'), value: 0 }, { text: t('merchant.portal.order.pay_status.1'), value: 1 }, { text: t('merchant.portal.order.pay_status.2'), value: 2 }, { text: t('merchant.portal.order.pay_status.3'), value: 3 }, ], align: 'center', }, { title: t('merchant.portal.order.status'), dataIndex: 'status', valueType: 'select', fieldProps: { options: [ { value: 0, label: t('merchant.portal.order.status.0') }, { value: 1, label: t('merchant.portal.order.status.1') }, { value: 2, label: t('merchant.portal.order.status.2') }, { value: 3, label: t('merchant.portal.order.status.3') }, { value: 4, label: t('merchant.portal.order.status.4') }, ], }, render: (value: number) => { const colorMap: Record = { 0: 'warning', 1: 'processing', 2: 'processing', 3: 'success', 4: 'default' }; const labelMap: Record = { 0: t('merchant.portal.order.status.0'), 1: t('merchant.portal.order.status.1'), 2: t('merchant.portal.order.status.2'), 3: t('merchant.portal.order.status.3'), 4: t('merchant.portal.order.status.4'), }; return {labelMap[value] ?? '-'}; }, filters: [ { text: t('merchant.portal.order.status.0'), value: 0 }, { text: t('merchant.portal.order.status.1'), value: 1 }, { text: t('merchant.portal.order.status.2'), value: 2 }, { text: t('merchant.portal.order.status.3'), value: 3 }, { text: t('merchant.portal.order.status.4'), value: 4 }, ], align: 'center', }, { title: t('merchant.portal.order.paid_at'), dataIndex: 'paid_at', hideInForm: true, hideInSearch: true, align: 'center', render: (value: string) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '-'), }, { title: t('merchant.portal.order.completed_at'), dataIndex: 'completed_at', hideInForm: true, hideInSearch: true, align: 'center', render: (value: string) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '-'), }, { title: t('merchant.portal.order.remark'), dataIndex: 'remark', valueType: 'text', hideInSearch: true, align: 'center', }, { title: t('merchant.portal.order.created_at'), hideInForm: true, hideInSearch: true, dataIndex: 'created_at', align: 'center', render: (value: string) => (value ? dayjs(value).fromNow() : '-'), }, ]; const tableProps: XinTableProps = { api: '/merchant-portal/order', columns, rowKey: 'id', accessName: 'merchant.portal.order', addShow: false, editShow: false, scroll: { x: 1400 }, formProps: { grid: true, colProps: { span: 12 }, rowProps: { gutter: [30, 0] }, layout: 'vertical', }, modalProps: { width: 800 }, cardProps: { variant: 'borderless' }, pagination: { size: 'small', style: { marginBottom: 0 } }, }; return ( <>
{t('merchant.portal.order.page.title')} {t('merchant.portal.order.page.description')}
{...tableProps} /> ); }; export default Table;