Files
xin-procurement/web/pages/customer/store.tsx
T
2026-08-14 23:47:49 +08:00

152 lines
3.8 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { Tag, Typography } from 'antd';
import XinTable from '@/components/XinTable';
import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings.ts';
import type IStore from '@/domain/iStore.ts';
import { STORE_STATUS_MAP } from '@/domain/iStore.ts';
import type ICustomerLevel from '@/domain/iCustomerLevel.ts';
import { getLevelOptions } from '@/api/customer/level.ts';
const { Title, Text } = Typography;
/**
* 门店管理
*/
const StorePage: React.FC = () => {
const [levels, setLevels] = useState<ICustomerLevel[]>([]);
useEffect(() => {
getLevelOptions().then((res) => setLevels(res.data.data ?? []));
}, []);
const levelOptions = levels.map((l) => ({ label: l.name, value: l.id }));
const columns: XinTableColumn<IStore>[] = [
{
title: 'ID',
dataIndex: 'id',
hideInForm: true,
hideInSearch: true,
width: 70,
align: 'center',
},
{
title: '门店名称',
dataIndex: 'name',
valueType: 'text',
required: true,
rules: [{ required: true, message: '请输入门店名称' }],
},
{
title: '门店编码',
dataIndex: 'code',
valueType: 'text',
hideInForm: true
},
{
title: '客户等级',
dataIndex: 'level_id',
valueType: 'select',
required: true,
rules: [{ required: true, message: '请选择客户等级' }],
fieldProps: {
options: levelOptions,
showSearch: true,
optionFilterProp: 'label',
},
render: (_, record) =>
record.level ? <Tag color="blue">{record.level.name}</Tag> : <Tag>未设置</Tag>,
},
{
title: '联系人',
dataIndex: 'contact',
valueType: 'text',
hideInSearch: true,
},
{
title: '联系电话',
dataIndex: 'phone',
valueType: 'text',
hideInSearch: true,
},
{
title: '门店地址',
dataIndex: 'address',
valueType: 'textarea',
hideInSearch: true,
fieldProps: { rows: 1 },
colProps: { span: 24 }
},
{
title: '回款周期(天)',
dataIndex: 'payment_cycle_days',
valueType: 'digit',
hideInSearch: true,
initialValue: 0,
fieldProps: { min: 0, precision: 0 },
align: 'center',
},
{
title: '总采购金额',
dataIndex: 'total_purchase_amount',
hideInForm: true,
hideInSearch: true,
align: 'center',
render: (_, record) => (
<Text strong className={'text-[red]'}>¥{record.total_purchase_amount ?? '0.00'}</Text>
),
},
{
title: '状态',
dataIndex: 'status',
valueType: 'radioButton',
initialValue: 1,
fieldProps: {
options: [
{ value: 1, label: '正常' },
{ value: 0, label: '停用' },
],
},
render: (_, record) => {
const item = STORE_STATUS_MAP[record.status ?? 1];
return <Tag color={item?.color}>{item?.text}</Tag>;
},
},
{
title: '备注',
dataIndex: 'remark',
valueType: 'textarea',
hideInSearch: true,
hideInTable: true,
fieldProps: { rows: 2 },
colProps: { span: 24 }
},
];
const tableProps: XinTableProps<IStore> = {
api: '/customer/store',
columns,
rowKey: 'id',
accessName: 'customer.store',
formProps: {
grid: true,
colProps: { span: 12 },
rowProps: { gutter: 20 },
layout: 'vertical',
},
modalProps: { width: 720 },
};
return (
<>
<div className="mb-5">
<Title level={3}>门店管理</Title>
<Text type="secondary">门店即客户,小程序下单主体;客户等级决定商品价格,回款周期影响对账单应结算日期。</Text>
</div>
<XinTable<IStore> {...tableProps} />
</>
);
};
export default StorePage;