|
@@ -1,36 +1,37 @@
|
1
|
1
|
|
2
|
2
|
import { Row, Col, Card, Tree, Form, TreeSelect, Input, InputNumber, Modal, Button, message } from 'antd'
|
|
3
|
+import moment from 'moment';
|
3
|
4
|
// import React, { useEffect, useState, useCallback,useRef } from 'react';
|
4
|
5
|
import TreedataFrom from './form';
|
5
|
6
|
|
6
|
|
-const { TreeNode,DirectoryTree } = Tree;
|
|
7
|
+const { TreeNode, DirectoryTree } = Tree;
|
7
|
8
|
const FormItem = Form.Item;
|
8
|
9
|
|
9
|
10
|
//-----------------------------------
|
10
|
|
- const onAdd = (key) => {
|
11
|
|
- if (expandedKeys.indexOf(key) === -1) {
|
12
|
|
- expandedKeyArr.push(key);
|
13
|
|
- }
|
14
|
|
- expandedKeys(expandedKeyArr.slice());
|
15
|
|
- addNode(key, treeData);//添加节点 树形
|
16
|
|
- setData(treeData.slice());//添加子项
|
17
|
|
- };
|
|
11
|
+const onAdd = (key) => {
|
|
12
|
+ if (expandedKeys.indexOf(key) === -1) {
|
|
13
|
+ expandedKeyArr.push(key);
|
|
14
|
+ }
|
|
15
|
+ expandedKeys(expandedKeyArr.slice());
|
|
16
|
+ addNode(key, treeData);//添加节点 树形
|
|
17
|
+ setData(treeData.slice());//添加子项
|
|
18
|
+};
|
18
|
19
|
//-----------------------------------
|
19
|
20
|
const confirm = data => {
|
20
|
21
|
// {...data,isPublish}
|
21
|
|
- if (data.key !== 0) {
|
22
|
|
- Modal.confirm({
|
23
|
|
- title: '确认删除吗?',
|
24
|
|
- okText: '确认',
|
25
|
|
- cancelText: '取消',
|
26
|
|
- onOk() {
|
27
|
|
- message.error('失败');
|
28
|
|
-
|
29
|
|
- },
|
30
|
|
- });
|
31
|
|
- }else{
|
32
|
|
- message.error('error')
|
33
|
|
- }
|
|
22
|
+ if (data.key !== 0) {
|
|
23
|
+ Modal.confirm({
|
|
24
|
+ title: '确认删除吗?',
|
|
25
|
+ okText: '确认',
|
|
26
|
+ cancelText: '取消',
|
|
27
|
+ onOk() {
|
|
28
|
+ message.error('失败');
|
|
29
|
+
|
|
30
|
+ },
|
|
31
|
+ });
|
|
32
|
+ } else {
|
|
33
|
+ message.error('error')
|
|
34
|
+ }
|
34
|
35
|
}
|
35
|
36
|
|
36
|
37
|
|
|
@@ -44,41 +45,51 @@ const confirm = data => {
|
44
|
45
|
// var uuid = s.join("");
|
45
|
46
|
// return uuid;
|
46
|
47
|
// }
|
47
|
|
-const treeData = [
|
48
|
|
- {
|
49
|
|
- title: '分厂厂长管理',
|
50
|
|
- key: '0',
|
51
|
|
- children: [
|
52
|
|
- { title: '郎岩',phone:'15920583224', cardId:'511502199103223189',sex:1,id:'0212',belon:1,homeaddres:1, key: '0-0-0-1' },
|
53
|
|
- { title: '柯琼彦',phone:'13184013427', cardId:'210203197503102721', sex:2 ,id:'4242',belon:2,homeaddres:2, key: '0-0-0-2' ,},
|
54
|
|
- ],
|
55
|
|
- },
|
56
|
|
- {
|
|
48
|
+// import moment from 'moment';
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+const treeData =
|
|
52
|
+ [
|
|
53
|
+ {
|
|
54
|
+ title: '分厂厂长管理',
|
|
55
|
+ key: '0',
|
|
56
|
+ selectable: false,
|
|
57
|
+ children: [
|
|
58
|
+ { title: '郎岩', phone: '15920583224', remark: "", day: "1992-11-13", cardId: '511502199103223189', sex: 1, id: '0212', belon: 1, homeaddres: 1, key: '0-0-0-1' },//这个不行么 你写错了 你那是v4的写法在哪?刚刚那个啊。对
|
|
59
|
+ { title: '柯琼彦', phone: '13184013427', remark: "", day: "1991-11-22", cardId: '210203197503102721', sex: 2, id: '4242', belon: 2, homeaddres: 2, key: '0-0-0-2', },
|
|
60
|
+ ],
|
|
61
|
+ },
|
|
62
|
+ {
|
57
|
63
|
title: '分厂员工管理',
|
58
|
64
|
key: '0-0-1',
|
|
65
|
+ selectable: false,
|
59
|
66
|
children: [
|
60
|
|
- { title: '伏佳', phone:'18613523527', cardId:'520323197806058856',sex:1 ,id:'1124', belon:4,homeaddres:4,key: '0-0-1-0' },
|
61
|
|
- { title: '舒宏', phone:'14736632088', cardId:'610729197408202551', sex:1 ,id:'4534', belon:3,homeaddres:2,key: '0-0-1-1' },
|
62
|
|
- { title: '狄莉珍',phone:'17604898508', cardId:'820000195008115837', sex:1 ,id:'4242',belon:1,homeaddres:5, key: '0-0-1-2' },
|
|
67
|
+ { title: '伏佳', phone: '18613523527', remark: "", day: "1992-10-11", cardId: '520323197806058856', sex: 1, id: '1124', belon: 4, homeaddres: 4, key: '0-0-1-0' },
|
|
68
|
+ { title: '舒宏', phone: '14736632088', remark: "", day: "1992-12-13", cardId: '610729197408202551', sex: 1, id: '4534', belon: 3, homeaddres: 2, key: '0-0-1-1' },
|
|
69
|
+ { title: '狄莉珍', phone: '17604898508', remark: "", day: "1993-10-11", cardId: '820000195008115837', sex: 1, id: '4242', belon: 1, homeaddres: 5, key: '0-0-1-2' },
|
63
|
70
|
],
|
64
|
|
- },
|
65
|
|
-];
|
66
|
|
-// const item = this.info.node.key
|
|
71
|
+ },
|
|
72
|
+ ]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+// const item = this.info.node.key 不是!!!!
|
67
|
78
|
|
68
|
79
|
class TreeDemo extends React.Component {
|
69
|
80
|
formRef = React.createRef();
|
70
|
|
-
|
71
|
|
-
|
72
|
|
- constructor(props){
|
73
|
|
- super(props)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+ constructor(props) {
|
|
84
|
+ super(props)
|
74
|
85
|
this.state = {
|
75
|
86
|
expandedKeys: ['0-0-0', '0-0-1'],
|
76
|
87
|
autoExpandParent: false,
|
77
|
88
|
checkedKeys: ['0-0-0'],
|
78
|
89
|
selectedKeys: [],
|
79
|
|
- treeTitle:[],
|
80
|
|
- checked:true
|
81
|
|
-
|
|
90
|
+ // treeTitle: [info.node.props],
|
|
91
|
+ checked: true,
|
|
92
|
+ treeData: treeData
|
82
|
93
|
};
|
83
|
94
|
}
|
84
|
95
|
|
|
@@ -86,8 +97,8 @@ class TreeDemo extends React.Component {
|
86
|
97
|
onExpand = expandedKeys => {
|
87
|
98
|
console.log('onExpand', expandedKeys);
|
88
|
99
|
|
89
|
|
- // 如果没有将 autoExpandParent 设置为 false,如果子项展开,父项不能折叠。
|
90
|
|
- // 或者,您可以删除所有扩展的子键。
|
|
100
|
+ // 如果没有将 autoExpandParent 设置为 false,如果子项展开,父项不能折叠。
|
|
101
|
+ // 或者,您可以删除所有扩展的子键。
|
91
|
102
|
this.setState({
|
92
|
103
|
expandedKeys,
|
93
|
104
|
autoExpandParent: false,
|
|
@@ -102,36 +113,75 @@ class TreeDemo extends React.Component {
|
102
|
113
|
};
|
103
|
114
|
|
104
|
115
|
|
|
116
|
+ onChangethis = (value) => {
|
105
|
117
|
|
|
118
|
+ const treeData = this.state.treeData
|
106
|
119
|
|
107
|
|
- onSelect=(value,info)=>{
|
108
|
|
- this.setState({value},()=>{
|
109
|
|
- this.formRef.current.setFieldsValue({
|
110
|
|
- ...info.node.props,
|
111
|
|
- })
|
|
120
|
+ let Data1 = this.state.treeData
|
|
121
|
+ for (var i = 0; i < treeData.length; i++) {
|
|
122
|
+
|
|
123
|
+ for (var j = 0; j < treeData[i].children.length; j++) {
|
|
124
|
+ // console.log(Data1[i].children[j].key);
|
|
125
|
+ // console.log("---------")
|
|
126
|
+ // console.log(value);
|
|
127
|
+ if (treeData[i].children[j].key == value.key) {
|
|
128
|
+
|
|
129
|
+ Data1[i].children[j] = value
|
|
130
|
+ //qileguaile wo cao
|
|
131
|
+ console.log(Data1[i].children[j]);
|
|
132
|
+ // console.log(treeData[i].children[j].key)
|
|
133
|
+ break
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ }
|
|
138
|
+ }
|
|
139
|
+ //删除
|
|
140
|
+ onDelect = (value) => {
|
|
141
|
+ const treeData = this.state.treeData
|
|
142
|
+ let Data1 = this.state.treeData
|
|
143
|
+ for (var i = 0; i < treeData.length; i++) {
|
|
144
|
+ for (var j = 0; j < treeData[i].children.length; j++) {
|
|
145
|
+
|
|
146
|
+ if (treeData[i].children[j].key == value.key) {
|
|
147
|
+
|
|
148
|
+ delete Data1[i].children[j]
|
|
149
|
+ break
|
|
150
|
+ }
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ }
|
|
154
|
+ // console.log("----Data1-----")
|
|
155
|
+ // console.log(Data1)
|
|
156
|
+ this.setState({
|
|
157
|
+ treeData: Data1
|
|
158
|
+ }, () => {
|
|
159
|
+ message.success('shanchuchenggong')
|
112
|
160
|
})
|
|
161
|
+
|
113
|
162
|
}
|
114
|
163
|
|
115
|
164
|
|
116
|
165
|
|
117
|
|
-// onSelect=(value,info)=>{
|
118
|
|
-// this.setState({value},()=>{
|
119
|
|
-// this.$nextTick(()=>{
|
120
|
|
-// setTimeout(()=>{
|
121
|
|
-// this.formRef.current.setFieldsValue({
|
122
|
|
-// ...info.node.props,
|
123
|
|
-// })
|
124
|
|
-// })
|
125
|
|
-// })
|
|
166
|
+ onSelect = (values, info) => {
|
|
167
|
+ // this.FromValue(info.node)
|
|
168
|
+ console.log(this.state.treeData)
|
|
169
|
+ console.log(info)
|
|
170
|
+ this.setState({ values }, () => {
|
|
171
|
+ this.formRef.current.setFieldsValue({
|
|
172
|
+ ...info.node.props,
|
|
173
|
+ key: info.node.props.eventKey,//event
|
|
174
|
+ day: moment(info.node.props.day)
|
|
175
|
+ })
|
126
|
176
|
|
127
|
|
-// console.log(this.state.info);
|
|
177
|
+ console.log(values, info)
|
128
|
178
|
|
129
|
|
-// })
|
130
|
|
-// }
|
|
179
|
+ // moment(info.node.props.day).format('YYYY-MM-DD')
|
|
180
|
+ })
|
|
181
|
+ }
|
131
|
182
|
|
132
|
183
|
|
133
|
184
|
|
134
|
|
-;
|
135
|
185
|
|
136
|
186
|
renderTreeNodes = data =>
|
137
|
187
|
data.map(item => {
|
|
@@ -139,8 +189,7 @@ class TreeDemo extends React.Component {
|
139
|
189
|
return (
|
140
|
190
|
<TreeNode title={item.title} key={item.key} dataRef={item} >
|
141
|
191
|
{this.renderTreeNodes(item.children)}
|
142
|
|
-
|
143
|
|
- </TreeNode>
|
|
192
|
+ </TreeNode >
|
144
|
193
|
);
|
145
|
194
|
}
|
146
|
195
|
return <TreeNode key={item.key} {...item} />;
|
|
@@ -151,50 +200,47 @@ class TreeDemo extends React.Component {
|
151
|
200
|
render() {
|
152
|
201
|
|
153
|
202
|
return (
|
154
|
|
- <Card>
|
155
|
|
- <Row >
|
156
|
|
- <Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 0 }}>
|
157
|
|
- <Card>
|
|
203
|
+ <Card>
|
|
204
|
+ <Row >
|
|
205
|
+ <Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 0 }}>
|
|
206
|
+ <Card>
|
158
|
207
|
<FormItem
|
159
|
|
- label="管辖部门"
|
160
|
|
- >
|
161
|
|
- <Button type="primary" style={{marginRight:'20px'}} onClick={onAdd} >
|
162
|
|
- 增加
|
163
|
|
- </Button>
|
164
|
|
- {/* onDelete={() => onDelete(item.key)} */}
|
165
|
|
- <Button type="danger" >
|
166
|
|
- 删除
|
167
|
|
- </Button>
|
168
|
|
- <Tree
|
169
|
|
- allowClear
|
170
|
|
- treeDefaultExpandAll
|
171
|
|
- treeData={this.state.treeData}
|
172
|
|
- showLine={true}
|
173
|
|
- onExpand={this.onExpand}
|
174
|
|
- expandedKeys={this.state.expandedKeys}
|
175
|
|
- autoExpandParent={this.state.autoExpandParent}
|
176
|
|
- onCheck={this.onCheck}
|
177
|
|
- checkedKeys={this.state.checkedKeys}
|
178
|
|
- onSelect={this.onSelect}
|
179
|
|
- selectedKeys={this.state.selectedKeys}
|
|
208
|
+ label="管辖部门"
|
180
|
209
|
>
|
181
|
|
- {this.renderTreeNodes(treeData)}
|
182
|
|
- </Tree >
|
183
|
|
-
|
184
|
|
- </FormItem>
|
185
|
|
- </Card>
|
186
|
|
- </Col>
|
187
|
|
- <Col xs={{ span: 10, offset: 10 }} lg={{ span: 10, offset: 4 }}>
|
188
|
|
- <Card>
|
189
|
|
- <TreedataFrom
|
190
|
|
- ref={this.formRef}
|
191
|
|
- />
|
192
|
|
- </Card>
|
193
|
|
- </Col>
|
194
|
|
- </Row>
|
195
|
|
- </Card>
|
|
210
|
+ <Button type="primary" onClick={onAdd} >
|
|
211
|
+ 增加
|
|
212
|
+ </Button>
|
|
213
|
+
|
|
214
|
+ <Tree
|
|
215
|
+
|
|
216
|
+ showLine
|
|
217
|
+ // switcherIcon={<DownOutlined />}
|
|
218
|
+ defaultExpandedKeys={['0-0-0']}
|
|
219
|
+ onSelect={this.onSelect}
|
|
220
|
+ treeData={this.state.treeData}
|
|
221
|
+ >
|
|
222
|
+ {this.renderTreeNodes(this.state.treeData)}
|
|
223
|
+ {/* 动态渲染 */}
|
|
224
|
+ </Tree >
|
|
225
|
+ {/* 不加入生命周期不会有更改a */}
|
|
226
|
+ </FormItem>
|
|
227
|
+ </Card>
|
|
228
|
+ </Col>
|
|
229
|
+ <Col xs={{ span: 10, offset: 10 }} lg={{ span: 10, offset: 4 }}>
|
|
230
|
+ <Card>
|
|
231
|
+ <TreedataFrom
|
|
232
|
+ ref={this.formRef}
|
|
233
|
+ triggerRef={this.bindRef}
|
|
234
|
+ onChangethis={this.onChangethis}
|
|
235
|
+ onSubmit={this.onChangethis}
|
|
236
|
+ />
|
|
237
|
+ </Card>
|
|
238
|
+ </Col>
|
|
239
|
+ </Row>
|
|
240
|
+ </Card>
|
196
|
241
|
);
|
197
|
242
|
}
|
|
243
|
+
|
198
|
244
|
}
|
199
|
245
|
|
200
|
|
-export default TreeDemo
|
|
246
|
+export default TreeDemo
|