|
@@ -1,60 +1,67 @@
|
1
|
|
-import React from 'react';
|
2
|
|
-import {
|
3
|
|
- PlusOutlined,
|
4
|
|
- DeleteOutlined,
|
5
|
|
-} from '@ant-design/icons';
|
|
1
|
+import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
+import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
|
6
|
3
|
import { Button, Card, Row, Col, Tree, Tooltip, Popconfirm } from "antd";
|
7
|
|
-import Page from '@/components/Page';
|
|
4
|
+import Page from "@/components/Page";
|
8
|
5
|
import { getSysOrg, deleteSysOrg } from "@/service/sysorg";
|
9
|
|
-import { arr2Tree } from '@/utils/array';
|
10
|
|
-import useBool from '@/utils/hooks/useBool';
|
11
|
|
-import Form from './components/Form';
|
|
6
|
+import { arr2Tree } from "@/utils/array";
|
12
|
7
|
|
13
|
|
-export default (props) => {
|
|
8
|
+import { getSysUser } from "@/service/sysuser";
|
|
9
|
+import useBool from "@/utils/hooks/useBool";
|
|
10
|
+import Form from "./components/Form";
|
14
|
11
|
|
|
12
|
+export default (props) => {
|
15
|
13
|
const [loading, startLoading, stopLoading] = useBool();
|
16
|
14
|
const [list, setList] = React.useState([]);
|
17
|
15
|
const [current, setCurrernt] = React.useState();
|
18
|
|
- const [parentId, setParentId] = React.useState('-1');
|
|
16
|
+ const [parentId, setParentId] = React.useState("-1");
|
|
17
|
+ const [queryUserList, setQueryUserList] = useState([]);
|
19
|
18
|
|
20
|
19
|
const [parentList, treeData] = React.useMemo(() => {
|
21
|
|
- const plist = [{orgId: '-1', name: '根节点'}].concat(list);
|
22
|
|
- const [tree] = arr2Tree((list || []).map(x => ({
|
23
|
|
- title: x.name,
|
24
|
|
- key: x.orgId,
|
25
|
|
- parentId: x.orgPId,
|
26
|
|
- raw: x,
|
27
|
|
- })));
|
|
20
|
+ const plist = [{ orgId: "-1", name: "根节点" }].concat(list);
|
|
21
|
+ const [tree] = arr2Tree(
|
|
22
|
+ (list || []).map((x) => ({
|
|
23
|
+ title: x.name,
|
|
24
|
+ key: x.orgId,
|
|
25
|
+ parentId: x.orgPId,
|
|
26
|
+ raw: x,
|
|
27
|
+ }))
|
|
28
|
+ );
|
28
|
29
|
|
29
|
30
|
return [plist, tree];
|
30
|
|
- }, [list])
|
|
31
|
+ }, [list]);
|
|
32
|
+
|
|
33
|
+ useEffect(() => {
|
|
34
|
+ getSysUser({ current: 1, pageSize: 500, pageNum: 1 }).then((res) =>
|
|
35
|
+ setQueryUserList(res.records || [])
|
|
36
|
+ );
|
|
37
|
+ }, []);
|
31
|
38
|
|
32
|
39
|
const changeCurrent = (org) => {
|
33
|
40
|
setCurrernt(org);
|
34
|
|
- setParentId(org?.orgPId || '-1');
|
35
|
|
- }
|
|
41
|
+ setParentId(org?.orgPId || "-1");
|
|
42
|
+ };
|
36
|
43
|
|
37
|
44
|
const onSelect = (selectedKeys, e) => {
|
38
|
|
- changeCurrent(e.node.raw)
|
39
|
|
- }
|
|
45
|
+ changeCurrent(e.node.raw);
|
|
46
|
+ };
|
40
|
47
|
|
41
|
48
|
const onClick = (org) => {
|
42
|
49
|
changeCurrent(org);
|
43
|
|
- }
|
|
50
|
+ };
|
44
|
51
|
|
45
|
|
- const onAdd = (parent = '-1') => {
|
|
52
|
+ const onAdd = (parent = "-1") => {
|
46
|
53
|
setParentId(parent);
|
47
|
54
|
setCurrernt();
|
48
|
|
- }
|
|
55
|
+ };
|
49
|
56
|
|
50
|
57
|
const onDelete = (org) => {
|
51
|
58
|
deleteSysOrg(org.orgId).then(() => {
|
52
|
|
- setList(list.filter(x => x.orgId !== org.orgId))
|
|
59
|
+ setList(list.filter((x) => x.orgId !== org.orgId));
|
53
|
60
|
});
|
54
|
|
- }
|
|
61
|
+ };
|
55
|
62
|
|
56
|
63
|
const queryList = React.useCallback(() => {
|
57
|
|
- getSysOrg({pageSize: 500}).then(res => {
|
|
64
|
+ getSysOrg({ pageSize: 500 }).then((res) => {
|
58
|
65
|
setList(res.records || []);
|
59
|
66
|
changeCurrent();
|
60
|
67
|
});
|
|
@@ -63,7 +70,7 @@ export default (props) => {
|
63
|
70
|
const onFormChange = () => {
|
64
|
71
|
// 重新查一次数据
|
65
|
72
|
queryList();
|
66
|
|
- }
|
|
73
|
+ };
|
67
|
74
|
|
68
|
75
|
React.useEffect(() => {
|
69
|
76
|
queryList();
|
|
@@ -76,27 +83,45 @@ export default (props) => {
|
76
|
83
|
<Card
|
77
|
84
|
title="单位"
|
78
|
85
|
onSelect={onSelect}
|
79
|
|
- extra={<Button type='link' onClick={() => onAdd()}>新增</Button>}
|
|
86
|
+ extra={
|
|
87
|
+ <Button type="link" onClick={() => onAdd()}>
|
|
88
|
+ 新增
|
|
89
|
+ </Button>
|
|
90
|
+ }
|
80
|
91
|
>
|
81
|
92
|
<Tree
|
82
|
93
|
blockNode
|
83
|
94
|
treeData={treeData}
|
84
|
95
|
// onSelect={onSelect}
|
85
|
96
|
titleRender={(node) => (
|
86
|
|
- <div style={{display: 'flex'}} onClick={e => e.stopPropagation()}>
|
87
|
|
- <div style={{lineHeight: '32px', flex: 1}} onClick={() => onClick(node.raw)}>
|
|
97
|
+ <div
|
|
98
|
+ style={{ display: "flex" }}
|
|
99
|
+ onClick={(e) => e.stopPropagation()}
|
|
100
|
+ >
|
|
101
|
+ <div
|
|
102
|
+ style={{ lineHeight: "32px", flex: 1 }}
|
|
103
|
+ onClick={() => onClick(node.raw)}
|
|
104
|
+ >
|
88
|
105
|
{node.title}
|
89
|
106
|
</div>
|
90
|
|
- <div style={{width: '80px', flex: 'none'}}>
|
|
107
|
+ <div style={{ width: "80px", flex: "none" }}>
|
91
|
108
|
<Tooltip title="新增子节点">
|
92
|
|
- <Button type='link' icon={<PlusOutlined />} onClick={() => onAdd(node.raw.orgId)}></Button>
|
|
109
|
+ <Button
|
|
110
|
+ type="link"
|
|
111
|
+ icon={<PlusOutlined />}
|
|
112
|
+ onClick={() => onAdd(node.raw.orgId)}
|
|
113
|
+ ></Button>
|
93
|
114
|
</Tooltip>
|
94
|
115
|
<Tooltip title="删除节点">
|
95
|
116
|
<Popconfirm
|
96
|
117
|
title="确认进行删除操作?"
|
97
|
118
|
onConfirm={() => onDelete(node.raw)}
|
98
|
119
|
>
|
99
|
|
- <Button type='link' danger icon={<DeleteOutlined />}></Button>
|
|
120
|
+ <Button
|
|
121
|
+ type="link"
|
|
122
|
+ danger
|
|
123
|
+ icon={<DeleteOutlined />}
|
|
124
|
+ ></Button>
|
100
|
125
|
</Popconfirm>
|
101
|
126
|
</Tooltip>
|
102
|
127
|
</div>
|
|
@@ -107,10 +132,16 @@ export default (props) => {
|
107
|
132
|
</Col>
|
108
|
133
|
<Col span={16}>
|
109
|
134
|
<Card>
|
110
|
|
- <Form org={current} parentId={parentId} list={parentList} onChange={onFormChange} />
|
|
135
|
+ <Form
|
|
136
|
+ org={current}
|
|
137
|
+ parentId={parentId}
|
|
138
|
+ list={parentList}
|
|
139
|
+ queryUserList={queryUserList}
|
|
140
|
+ onChange={onFormChange}
|
|
141
|
+ />
|
111
|
142
|
</Card>
|
112
|
143
|
</Col>
|
113
|
144
|
</Row>
|
114
|
145
|
</Page>
|
115
|
|
- )
|
116
|
|
-}
|
|
146
|
+ );
|
|
147
|
+};
|