133 lines
3.4 KiB
TypeScript
133 lines
3.4 KiB
TypeScript
import React from 'react';
|
||
import { Tag, Typography, Image } from 'antd';
|
||
import XinTable from '@/components/XinTable';
|
||
import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings.ts';
|
||
import type ICustomerLevel from '@/domain/iCustomerLevel.ts';
|
||
import { CUSTOMER_LEVEL_STATUS_MAP } from '@/domain/iCustomerLevel.ts';
|
||
|
||
const { Title, Text } = Typography;
|
||
|
||
/**
|
||
* 客户等级管理
|
||
*/
|
||
const CustomerLevelPage: React.FC = () => {
|
||
const columns: XinTableColumn<ICustomerLevel>[] = [
|
||
{
|
||
title: 'ID',
|
||
dataIndex: 'id',
|
||
hideInForm: true,
|
||
hideInSearch: true,
|
||
width: 70,
|
||
align: 'center',
|
||
},
|
||
{
|
||
title: '等级名称',
|
||
dataIndex: 'name',
|
||
valueType: 'text',
|
||
required: true,
|
||
align: 'center',
|
||
rules: [{ required: true, message: '请输入等级名称' }],
|
||
},
|
||
{
|
||
title: '价格上浮比例',
|
||
dataIndex: 'percent',
|
||
valueType: 'digit',
|
||
hideInSearch: true,
|
||
initialValue: 0,
|
||
tooltip: '该等级售价 = 成本价 × (100 + 上浮比例) / 100',
|
||
fieldProps: { min: 0, max: 999.99, precision: 2, suffix: '%', placeholder: '如 30 表示成本价上浮 30%' },
|
||
align: 'center',
|
||
render: (_, record) => <Tag color="blue">{Number(record.percent ?? 0)}%</Tag>,
|
||
},
|
||
{
|
||
title: '排序',
|
||
dataIndex: 'sort',
|
||
valueType: 'digit',
|
||
hideInSearch: true,
|
||
initialValue: 0,
|
||
fieldProps: { min: 0 },
|
||
},
|
||
{
|
||
title: '图片等级',
|
||
dataIndex: 'icon_id',
|
||
valueType: 'image',
|
||
fieldProps: {
|
||
action: '/customer/level/upload',
|
||
mode: 'single',
|
||
maxCount: 1,
|
||
changeType: "id"
|
||
},
|
||
render: (_, record: ICustomerLevel) => {
|
||
const url = record.icon_url
|
||
if (!url) return '-';
|
||
return (
|
||
<Image
|
||
src={url}
|
||
width={30}
|
||
height={30}
|
||
style={{ objectFit: 'cover', borderRadius: 4 }}
|
||
/>
|
||
);
|
||
},
|
||
align: 'center',
|
||
hideInSearch: true,
|
||
},
|
||
{
|
||
title: '状态',
|
||
dataIndex: 'status',
|
||
valueType: 'radioButton',
|
||
initialValue: 1,
|
||
fieldProps: {
|
||
options: [
|
||
{ value: 1, label: '正常' },
|
||
{ value: 0, label: '停用' },
|
||
],
|
||
},
|
||
render: (_, record) => {
|
||
const item = CUSTOMER_LEVEL_STATUS_MAP[record.status ?? 1];
|
||
return <Tag color={item?.color}>{item?.text}</Tag>;
|
||
},
|
||
},
|
||
{
|
||
title: '创建时间',
|
||
dataIndex: 'updated_at',
|
||
hideInForm: true,
|
||
hideInSearch: true,
|
||
align: 'center',
|
||
},
|
||
{
|
||
title: '创建时间',
|
||
dataIndex: 'created_at',
|
||
hideInForm: true,
|
||
hideInSearch: true,
|
||
align: 'center',
|
||
},
|
||
];
|
||
|
||
const tableProps: XinTableProps<ICustomerLevel> = {
|
||
api: '/customer/level',
|
||
columns,
|
||
rowKey: 'id',
|
||
accessName: 'customer.level',
|
||
formProps: {
|
||
grid: true,
|
||
colProps: { span: 12 },
|
||
rowProps: { gutter: 20 },
|
||
layout: 'vertical',
|
||
},
|
||
modalProps: { width: 640 },
|
||
};
|
||
|
||
return (
|
||
<>
|
||
<div className="mb-5">
|
||
<Title level={3}>客户等级</Title>
|
||
<Text type="secondary">按等级配置价格上浮比例:售价 = 成本价 × (100 + 上浮比例) / 100,门店绑定等级后小程序端按对应价格展示。</Text>
|
||
</div>
|
||
<XinTable<ICustomerLevel> {...tableProps} />
|
||
</>
|
||
);
|
||
};
|
||
|
||
export default CustomerLevelPage;
|