181 lines
4.8 KiB
TypeScript
181 lines
4.8 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 IMerchantProduct from '@/domain/iMerchantProduct';
|
|
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<IMerchantProduct>[] = [
|
|
{
|
|
title: t('merchant.product.id'),
|
|
dataIndex: 'id',
|
|
hideInForm: true,
|
|
sorter: true,
|
|
align: 'center',
|
|
width: 80,
|
|
},
|
|
{
|
|
title: t('merchant.product.name'),
|
|
dataIndex: 'name',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
required: true,
|
|
rules: [{ required: true, message: t('merchant.product.name.required') }],
|
|
},
|
|
{
|
|
title: t('merchant.product.merchant_id'),
|
|
dataIndex: 'merchant_id',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
required: true,
|
|
},
|
|
{
|
|
title: t('merchant.product.category_id'),
|
|
dataIndex: 'category_id',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
},
|
|
{
|
|
title: t('merchant.product.price'),
|
|
dataIndex: 'price',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
render: (value: number) => `¥${value || '0.00'}`,
|
|
},
|
|
{
|
|
title: t('merchant.product.original_price'),
|
|
dataIndex: 'original_price',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
hideInSearch: true,
|
|
render: (value: number) => value ? `¥${value}` : '-',
|
|
},
|
|
{
|
|
title: t('merchant.product.stock'),
|
|
dataIndex: 'stock',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
hideInSearch: true,
|
|
},
|
|
{
|
|
title: t('merchant.product.sales'),
|
|
dataIndex: 'sales',
|
|
hideInForm: true,
|
|
hideInSearch: true,
|
|
align: 'center',
|
|
},
|
|
{
|
|
title: t('merchant.product.unit'),
|
|
dataIndex: 'unit',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
hideInSearch: true,
|
|
},
|
|
{
|
|
title: t('merchant.product.description'),
|
|
dataIndex: 'description',
|
|
valueType: 'text',
|
|
hideInTable: true,
|
|
hideInSearch: true,
|
|
},
|
|
{
|
|
title: t('merchant.product.status'),
|
|
dataIndex: 'status',
|
|
valueType: 'radioButton',
|
|
fieldProps: {
|
|
options: [
|
|
{ value: 0, label: t('merchant.product.status.0') },
|
|
{ value: 1, label: t('merchant.product.status.1') },
|
|
],
|
|
},
|
|
render: (value: number) => {
|
|
return value === 1
|
|
? <Tag color="success">{t('merchant.product.status.1')}</Tag>
|
|
: <Tag color="default">{t('merchant.product.status.0')}</Tag>;
|
|
},
|
|
filters: [
|
|
{ text: t('merchant.product.status.0'), value: 0 },
|
|
{ text: t('merchant.product.status.1'), value: 1 },
|
|
],
|
|
align: 'center',
|
|
},
|
|
{
|
|
title: t('merchant.product.is_recommend'),
|
|
dataIndex: 'is_recommend',
|
|
valueType: 'radioButton',
|
|
fieldProps: {
|
|
options: [
|
|
{ value: 0, label: t('merchant.product.is_recommend.0') },
|
|
{ value: 1, label: t('merchant.product.is_recommend.1') },
|
|
],
|
|
},
|
|
render: (value: number) => {
|
|
return value === 1
|
|
? <Tag color="orange">{t('merchant.product.is_recommend.1')}</Tag>
|
|
: <Tag>{t('merchant.product.is_recommend.0')}</Tag>;
|
|
},
|
|
align: 'center',
|
|
},
|
|
{
|
|
title: t('merchant.product.sort'),
|
|
dataIndex: 'sort',
|
|
valueType: 'text',
|
|
align: 'center',
|
|
hideInSearch: true,
|
|
},
|
|
{
|
|
title: t('merchant.product.created_at'),
|
|
hideInForm: true,
|
|
hideInSearch: true,
|
|
dataIndex: 'created_at',
|
|
align: 'center',
|
|
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
|
|
},
|
|
{
|
|
title: t('merchant.product.updated_at'),
|
|
hideInForm: true,
|
|
hideInSearch: true,
|
|
dataIndex: 'updated_at',
|
|
align: 'center',
|
|
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
|
|
},
|
|
];
|
|
|
|
const tableProps: XinTableProps<IMerchantProduct> = {
|
|
api: '/merchant/product',
|
|
columns,
|
|
rowKey: 'id',
|
|
accessName: 'merchant.product',
|
|
scroll: { x: 1600 },
|
|
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.product.page.title')}</Title>
|
|
<Text type="secondary">{t('merchant.product.page.description')}</Text>
|
|
</div>
|
|
<XinTable<IMerchantProduct> {...tableProps} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Table;
|