1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
| import { Button, Space, Tag } from 'antd';
| import type { ProColumns } from '@ant-design/pro-components';
| import type { OrgType, OrgVO } from './types';
|
| export const orgTypeMeta: Record<OrgType, { text: string; color: string }> = {
| HQ: { text: '总部', color: 'gold' },
| BRANCH: { text: '分公司', color: 'blue' },
| DEALER: { text: '经销商', color: 'green' },
| AGENT: { text: '代理商', color: 'purple' },
| DEPT: { text: '部门', color: 'cyan' },
| TEAM: { text: '团队', color: 'orange' },
| };
|
| /** 兼容后端返回未知类型,避免直接索引得到 undefined。 */
| export const getOrgTypeMeta = (type?: string) => {
| const key = String(type ?? '').toUpperCase() as OrgType;
| return orgTypeMeta[key] ?? { text: type || '-', color: 'default' };
| };
|
| export const createDepartmentColumns = (options: {
| leaderNameMap: Map<number, string>;
| onCreateChild: (record: OrgVO) => void;
| onEdit: (record: OrgVO) => void;
| onToggle: (record: OrgVO) => void;
| onDelete: (record: OrgVO) => void;
| }): ProColumns<OrgVO>[] => [
| {
| title: '部门名称',
| dataIndex: 'orgName',
| width: 260,
| fieldProps: { placeholder: '请输入部门名称' },
| },
| {
| title: '组织类型',
| dataIndex: 'orgType',
| width: 120,
| valueType: 'select',
| valueEnum: {
| HQ: { text: '总部' },
| BRANCH: { text: '分公司' },
| DEALER: { text: '经销商' },
| AGENT: { text: '代理商' },
| DEPT: { text: '部门' },
| TEAM: { text: '团队' },
| },
| render: (_value, record) => {
| const meta = getOrgTypeMeta(record.orgType);
| return (
| <Tag color={meta.color} bordered={false}>
| {meta.text}
| </Tag>
| );
| },
| },
| {
| title: '负责人',
| dataIndex: 'leaderId',
| width: 140,
| search: false,
| render: (_value, record) => {
| if (!record.leaderId) return '-';
| return options.leaderNameMap.get(record.leaderId) ?? `#${record.leaderId}`;
| },
| },
| {
| title: '所在地区',
| dataIndex: 'region',
| width: 140,
| search: false,
| render: (_value, record) => record.region || '-',
| },
| {
| title: '排序',
| dataIndex: 'sortOrder',
| width: 80,
| search: false,
| render: (_value, record) => record.sortOrder ?? '-',
| },
| {
| title: '状态',
| dataIndex: 'status',
| width: 100,
| valueType: 'select',
| valueEnum: {
| true: { text: '启用' },
| false: { text: '停用' },
| },
| render: (_value, record) => (
| <Tag color={record.status ? 'green' : 'default'} bordered={false}>
| {record.status ? '启用' : '停用'}
| </Tag>
| ),
| },
| {
| title: '操作',
| key: 'action',
| valueType: 'option',
| width: 260,
| render: (_value, record) => (
| <Space size={0}>
| <Button type="link" size="small" onClick={() => options.onCreateChild(record)}>
| 新增子部门
| </Button>
| {/* 总部为租户根组织,不允许编辑 */}
| <Button
| type="link"
| size="small"
| disabled={record.orgType === 'HQ'}
| onClick={() => options.onEdit(record)}
| >
| 编辑
| </Button>
| <Button type="link" size="small" onClick={() => options.onToggle(record)}>
| {record.status ? '停用' : '启用'}
| </Button>
| <Button type="link" size="small" danger onClick={() => options.onDelete(record)}>
| 删除
| </Button>
| </Space>
| ),
| },
| ];
|
|