Files
xin-school/web/pages/merchant-portal/payment/index.tsx
T
2026-06-17 12:41:49 +08:00

139 lines
4.3 KiB
TypeScript

import { Tag, Typography } from 'antd';
import React from 'react';
import XinTable from '@/components/XinTable';
import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings';
import type IOrderPayment from '@/domain/iOrderPayment';
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<IOrderPayment>[] = [
{
title: t('merchant.portal.payment.id'),
dataIndex: 'id',
hideInForm: true,
sorter: true,
align: 'center',
width: 80,
},
{
title: t('merchant.portal.payment.payment_no'),
dataIndex: 'payment_no',
valueType: 'text',
align: 'center',
hideInSearch: true,
},
{
title: t('merchant.portal.payment.order_id'),
dataIndex: 'order_id',
valueType: 'text',
align: 'center',
hideInSearch: true,
},
{
title: t('merchant.portal.payment.amount'),
dataIndex: 'amount',
valueType: 'text',
align: 'center',
render: (value: number) => ${value ?? '0.00'}`,
},
{
title: t('merchant.portal.payment.pay_type'),
dataIndex: 'pay_type',
valueType: 'select',
fieldProps: {
options: [
{ value: 0, label: t('merchant.portal.payment.pay_type.0') },
{ value: 1, label: t('merchant.portal.payment.pay_type.1') },
],
},
render: (value: number) => {
const colorMap: Record<number, string> = { 0: 'default', 1: 'blue' };
const labelMap: Record<number, string> = {
0: t('merchant.portal.payment.pay_type.0'),
1: t('merchant.portal.payment.pay_type.1'),
};
return <Tag color={colorMap[value] ?? 'default'}>{labelMap[value] ?? '-'}</Tag>;
},
filters: [
{ text: t('merchant.portal.payment.pay_type.0'), value: 0 },
{ text: t('merchant.portal.payment.pay_type.1'), value: 1 },
],
align: 'center',
},
{
title: t('merchant.portal.payment.status'),
dataIndex: 'status',
valueType: 'select',
fieldProps: {
options: [
{ value: 0, label: t('merchant.portal.payment.status.0') },
{ value: 1, label: t('merchant.portal.payment.status.1') },
{ value: 2, label: t('merchant.portal.payment.status.2') },
],
},
render: (value: number) => {
const colorMap: Record<number, string> = { 0: 'warning', 1: 'success', 2: 'error' };
const labelMap: Record<number, string> = {
0: t('merchant.portal.payment.status.0'),
1: t('merchant.portal.payment.status.1'),
2: t('merchant.portal.payment.status.2'),
};
return <Tag color={colorMap[value] ?? 'default'}>{labelMap[value] ?? '-'}</Tag>;
},
filters: [
{ text: t('merchant.portal.payment.status.0'), value: 0 },
{ text: t('merchant.portal.payment.status.1'), value: 1 },
{ text: t('merchant.portal.payment.status.2'), value: 2 },
],
align: 'center',
},
{
title: t('merchant.portal.payment.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.payment.created_at'),
hideInForm: true,
hideInSearch: true,
dataIndex: 'created_at',
align: 'center',
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
},
];
const tableProps: XinTableProps<IOrderPayment> = {
api: '/merchant-portal/payment',
columns,
rowKey: 'id',
accessName: 'merchant.portal.payment',
addShow: false,
editShow: false,
scroll: { x: 1000 },
cardProps: { variant: 'borderless' },
pagination: { size: 'small', style: { marginBottom: 0 } },
};
return (
<>
<div className="mb-5">
<Title level={3}>{t('merchant.portal.payment.page.title')}</Title>
<Text type="secondary">{t('merchant.portal.payment.page.description')}</Text>
</div>
<XinTable<IOrderPayment> {...tableProps} />
</>
);
};
export default Table;