Files
xin-school/web/pages/merchant/store/index.tsx
T
2026-06-17 09:13:49 +08:00

166 lines
4.6 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 IMerchantStore from '@/domain/iMerchantStore';
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<IMerchantStore>[] = [
{
title: t('merchant.store.id'),
dataIndex: 'id',
hideInForm: true,
sorter: true,
align: 'center',
width: 80,
},
{
title: t('merchant.store.name'),
dataIndex: 'name',
valueType: 'text',
align: 'center',
required: true,
rules: [{ required: true, message: t('merchant.store.name.required') }],
},
{
title: t('merchant.store.user_id'),
dataIndex: 'user_id',
valueType: 'text',
align: 'center',
required: true,
hideInSearch: true,
},
{
title: t('merchant.store.category_id'),
dataIndex: 'category_id',
valueType: 'text',
align: 'center',
},
{
title: t('merchant.store.contact_name'),
dataIndex: 'contact_name',
valueType: 'text',
align: 'center',
hideInSearch: true,
},
{
title: t('merchant.store.contact_mobile'),
dataIndex: 'contact_mobile',
valueType: 'text',
align: 'center',
hideInSearch: true,
},
{
title: t('merchant.store.address'),
dataIndex: 'address',
valueType: 'text',
hideInTable: true,
hideInSearch: true,
},
{
title: t('merchant.store.description'),
dataIndex: 'description',
valueType: 'text',
hideInTable: true,
hideInSearch: true,
},
{
title: t('merchant.store.balance'),
dataIndex: 'balance',
hideInForm: true,
hideInSearch: true,
align: 'center',
render: (value: number) => ${value || '0.00'}`,
},
{
title: t('merchant.store.min_price'),
dataIndex: 'min_price',
valueType: 'text',
align: 'center',
hideInSearch: true,
render: (value: number) => ${value || '0.00'}`,
},
{
title: t('merchant.store.status'),
dataIndex: 'status',
valueType: 'radioButton',
fieldProps: {
options: [
{ value: 0, label: t('merchant.store.status.0') },
{ value: 1, label: t('merchant.store.status.1') },
{ value: 2, label: t('merchant.store.status.2') },
{ value: 3, label: t('merchant.store.status.3') },
],
},
render: (value: number) => {
const colorMap: Record<number, string> = { 0: 'processing', 1: 'success', 2: 'warning', 3: 'error' };
const labelMap: Record<number, string> = {
0: t('merchant.store.status.0'), 1: t('merchant.store.status.1'),
2: t('merchant.store.status.2'), 3: t('merchant.store.status.3'),
};
return <Tag color={colorMap[value] || 'default'}>{labelMap[value] || '-'}</Tag>;
},
filters: [
{ text: t('merchant.store.status.0'), value: 0 },
{ text: t('merchant.store.status.1'), value: 1 },
{ text: t('merchant.store.status.2'), value: 2 },
{ text: t('merchant.store.status.3'), value: 3 },
],
align: 'center',
},
{
title: t('merchant.store.created_at'),
hideInForm: true,
hideInSearch: true,
dataIndex: 'created_at',
align: 'center',
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
},
{
title: t('merchant.store.updated_at'),
hideInForm: true,
hideInSearch: true,
dataIndex: 'updated_at',
align: 'center',
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
},
];
const tableProps: XinTableProps<IMerchantStore> = {
api: '/merchant/store',
columns,
rowKey: 'id',
accessName: 'merchant.store',
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 (
<>
<div className="mb-5">
<Title level={3}>{t('merchant.store.page.title')}</Title>
<Text type="secondary">{t('merchant.store.page.description')}</Text>
</div>
<XinTable<IMerchantStore> {...tableProps} />
</>
);
};
export default Table;