@@ -5,7 +5,7 @@ import { PlusOutlined } from '@ant-design/icons';
5
5
import type { ActionType , ProColumns , ProDescriptionsItemProps } from '@ant-design/pro-components' ;
6
6
import { PageContainer , ProDescriptions , ProTable } from '@ant-design/pro-components' ;
7
7
import { FormattedMessage , history , Link , useIntl , useParams } from '@umijs/max' ;
8
- import { Button , Drawer , message , Popconfirm , TreeSelect } from 'antd' ;
8
+ import { Button , Drawer , message , Popconfirm , TreeSelect , Select } from 'antd' ;
9
9
import { DataNode } from 'antd/es/tree' ;
10
10
import React , { useEffect , useRef , useState } from 'react' ;
11
11
import { fieldIntl } from '@/util/fieldIntl' ;
@@ -17,9 +17,11 @@ import {
17
17
putDepartmentsId ,
18
18
} from '@/services/admin/department' ;
19
19
import { statusOptions } from '@/util/statusOptions' ;
20
+ import { getUsers } from '@/services/admin/user' ;
20
21
21
22
const TableList : React . FC = ( ) => {
22
23
const [ showDetail , setShowDetail ] = useState < boolean > ( false ) ;
24
+ const [ userOptions , setUserOptions ] = useState < { label : string ; value : string } [ ] > ( [ ] ) ;
23
25
24
26
const actionRef = useRef < ActionType > ( ) ;
25
27
const [ currentRow , setCurrentRow ] = useState < API . Role > ( ) ;
@@ -79,6 +81,23 @@ const TableList: React.FC = () => {
79
81
{
80
82
title : fieldIntl ( intl , 'leaderID' ) ,
81
83
dataIndex : 'leaderID' ,
84
+ render : ( _ , record ) => {
85
+ const leader = userOptions . find ( ( user ) => user . value === record . leaderID ) ;
86
+ return leader ?. label || '-' ;
87
+ } ,
88
+ renderFormItem : ( ) => (
89
+ < Select
90
+ showSearch
91
+ placeholder = { intl . formatMessage ( {
92
+ id : 'pages.department.leader.placeholder' ,
93
+ defaultMessage : '请选择负责人' ,
94
+ } ) }
95
+ options = { userOptions }
96
+ filterOption = { ( input , option ) =>
97
+ ( option ?. label ?? '' ) . toLowerCase ( ) . includes ( input . toLowerCase ( ) )
98
+ }
99
+ />
100
+ ) ,
82
101
} ,
83
102
{
84
103
title : fieldIntl ( intl , 'phone' ) ,
@@ -136,14 +155,14 @@ const TableList: React.FC = () => {
136
155
hideInDescriptions : true ,
137
156
hideInForm : true ,
138
157
render : ( _ , record ) => [
139
- < Access key = "/department /edit" >
140
- < Link to = { `/department /${ record . id } ` } key = "edit" >
158
+ < Access key = "/departments /edit" >
159
+ < Link to = { `/departments /${ record . id } ` } key = "edit" >
141
160
< Button key = "edit" >
142
161
< FormattedMessage id = "pages.title.edit" defaultMessage = "Edit" />
143
162
</ Button >
144
163
</ Link >
145
164
</ Access > ,
146
- < Access key = "/department /delete" >
165
+ < Access key = "/departments /delete" >
147
166
< Popconfirm
148
167
key = "delete"
149
168
title = { intl . formatMessage ( {
@@ -224,6 +243,20 @@ const TableList: React.FC = () => {
224
243
}
225
244
} , [ id ] ) ;
226
245
246
+ useEffect ( ( ) => {
247
+ // 获取用户列表用于选择负责人
248
+ getUsers ( { pageSize : 1000 } ) . then ( ( res ) => {
249
+ if ( res . data ) {
250
+ setUserOptions (
251
+ res . data . map ( ( user ) => ( {
252
+ label : user . name || user . username || '' ,
253
+ value : user . id || '' ,
254
+ } ) ) ,
255
+ ) ;
256
+ }
257
+ } ) ;
258
+ } , [ ] ) ;
259
+
227
260
return (
228
261
< PageContainer title = { indexTitle ( id ) } >
229
262
< ProTable < API . Department , API . getDepartmentsParams >
@@ -239,8 +272,8 @@ const TableList: React.FC = () => {
239
272
type = { id ? 'form' : 'table' }
240
273
onSubmit = { id ? onSubmit : undefined }
241
274
toolBarRender = { ( ) => [
242
- < Access key = "/department /create" >
243
- < Link to = "/department /create" key = "create" >
275
+ < Access key = "/departments /create" >
276
+ < Link to = "/departments /create" key = "create" >
244
277
< Button type = "primary" key = "create" >
245
278
< PlusOutlined /> < FormattedMessage id = "pages.table.new" defaultMessage = "New" />
246
279
</ Button >
0 commit comments