|
@@ -5,35 +5,15 @@ import request from '@/utils/request';
|
5
|
5
|
import apis from '@/services/apis';
|
6
|
6
|
import moment from 'moment';
|
7
|
7
|
import TreedataFrom from './form';
|
|
8
|
+import TreedataAdd from './addForm';
|
|
9
|
+import { values } from 'lodash';
|
8
|
10
|
const { TreeNode, DirectoryTree } = Tree;
|
9
|
11
|
const FormItem = Form.Item;
|
10
|
12
|
const { Search } = Input;
|
11
|
13
|
const { TabPane } = Tabs;
|
12
|
14
|
|
13
|
|
-const treeData =
|
14
|
|
- [
|
15
|
|
- {
|
16
|
|
- title: 'institutionId',
|
17
|
|
- name: 'institutionName',
|
18
|
|
- key: '0-0-0',
|
19
|
|
- selectable: false,
|
20
|
|
- children: [
|
21
|
|
- { name: 'institutionName', phone: '13184013427', remark: "", day: "1991-11-22", cardId: '210203197503102721', sex: 2, id: '4242', belon: 2, homeaddres: 2, key: '0-0-0-1', },
|
22
|
|
- { title: '柯琼彦', phone: '13184013427', remark: "", day: "1991-11-22", cardId: '210203197503102721', sex: 2, id: '4242', belon: 2, homeaddres: 2, key: '0-0-0-2', },
|
23
|
|
- ],
|
24
|
|
- },
|
25
|
|
- {
|
26
|
|
- title: '分厂员工管理',
|
27
|
|
- key: '0-0-1',
|
28
|
|
- selectable: false,
|
29
|
|
- children: [
|
30
|
|
- { title: '伏佳', phone: '18613523527', remark: "", day: "1992-10-11", cardId: '520323197806058856', sex: 1, id: '1124', belon: 4, homeaddres: 4, key: '0-0-1-0' },
|
31
|
|
- { title: '舒宏', phone: '14736632088', remark: "", day: "1992-12-13", cardId: '610729197408202551', sex: 1, id: '4534', belon: 3, homeaddres: 2, key: '0-0-1-1' },
|
32
|
|
- { title: '狄莉珍', phone: '17604898508', remark: "", day: "1993-10-11", cardId: '820000195008115837', sex: 1, id: '4242', belon: 1, homeaddres: 5, key: '0-0-1-2' },
|
33
|
|
- ],
|
34
|
|
- },
|
35
|
|
- ]
|
36
|
|
-
|
|
15
|
+const treeData = []
|
|
16
|
+const updateTreeData = fetch(apis.Institution.instiAlert); //接口
|
37
|
17
|
|
38
|
18
|
|
39
|
19
|
|
|
@@ -45,25 +25,36 @@ class TreeDemo extends React.Component {
|
45
|
25
|
constructor(props) {
|
46
|
26
|
super(props)
|
47
|
27
|
this.state = {
|
48
|
|
- expandedKeys: ['0-0-0', '0-0-1'],
|
49
|
|
- autoExpandParent: false,
|
50
|
|
- checkedKeys: ['0-0-0'],
|
51
|
|
- searchValue: '',
|
52
|
|
- selectedKeys: [],
|
|
28
|
+ // autoExpandParent: false,
|
53
|
29
|
// treeTitle: [info.node.props],
|
|
30
|
+ // checkedKeys: ['0-0-0'],
|
|
31
|
+ expandedKeys: [],//展开的key
|
|
32
|
+ checkedKeys: [],//选中的key
|
|
33
|
+ autoExpandParent: true,
|
|
34
|
+ searchValue: '',
|
|
35
|
+ selectedKeys: [],//搜索得key
|
54
|
36
|
checked: true,
|
55
|
37
|
treeData: [],
|
56
|
38
|
testarr: []
|
57
|
39
|
};
|
58
|
40
|
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ // onExpand = expandedKeys => {
|
|
44
|
+ // this.setState({
|
|
45
|
+ // expandedKeys,
|
|
46
|
+ // autoExpandParent: false,
|
|
47
|
+ // });
|
|
48
|
+ // };
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
59
|
52
|
// --------标签页
|
60
|
53
|
callback = (key) => {
|
61
|
54
|
console.log(key);
|
62
|
55
|
}
|
63
|
56
|
|
64
|
57
|
|
65
|
|
-
|
66
|
|
-
|
67
|
58
|
onExpand = expandedKeys => {
|
68
|
59
|
console.log('onExpand', expandedKeys);
|
69
|
60
|
|
|
@@ -79,125 +70,90 @@ class TreeDemo extends React.Component {
|
79
|
70
|
this.setState({
|
80
|
71
|
sex: e.target.value
|
81
|
72
|
});
|
82
|
|
- console.log(valeu);
|
|
73
|
+ console.log(value);
|
83
|
74
|
};
|
84
|
75
|
|
85
|
76
|
//修改
|
86
|
|
- onChangethis = (value) => {
|
87
|
|
-
|
88
|
|
- const treeData = this.state.treeData
|
89
|
|
- let Data1 = this.state.treeData
|
90
|
|
- for (var i = 0; i < treeData.length; i++) {
|
91
|
|
- for (var j = 0; j < treeData[i].children.length; j++) {
|
92
|
|
- // console.log(Data1[i].children[j].key);
|
93
|
|
- // console.log("---------")
|
94
|
|
- // console.log(value);
|
95
|
|
- if (treeData[i].children[j].key == value.key) {
|
96
|
|
-
|
97
|
|
- Data1[i].children[j] = value
|
98
|
|
- //qileguaile wo cao
|
99
|
|
- console.log(Data1[i].children[j]);
|
100
|
|
- // console.log(treeData[i].children[j].key)
|
101
|
|
- break
|
102
|
|
- }
|
103
|
|
- }
|
104
|
|
- }
|
105
|
|
- this.setState({
|
106
|
|
- treeData1: Data1
|
107
|
|
- }, () => {
|
108
|
|
- message.success('修改成功!')
|
109
|
|
- })
|
110
|
|
-
|
111
|
|
- }
|
112
|
|
- //删除
|
113
|
|
- onDelect = (value) => {
|
114
|
|
- const treeData = this.state.treeData
|
115
|
|
- let Data1 = this.state.treeData
|
116
|
|
- for (var i = 0; i < treeData.length; i++) {
|
117
|
|
- for (var j = 0; j < treeData[i].children.length; j++) {
|
118
|
77
|
|
119
|
|
- if (treeData[i].children[j].key == value.key) {
|
120
|
|
-
|
121
|
|
- delete Data1[i].children[j]
|
122
|
|
- break
|
123
|
|
- }
|
124
|
|
- }
|
125
|
|
-
|
126
|
|
- }
|
127
|
|
- // console.log("----Data1-----")
|
128
|
|
- // console.log(Data1)
|
129
|
|
- this.setState({
|
130
|
|
- treeData: Data1
|
131
|
|
- }, () => {
|
132
|
|
- message.success('shanchuchenggong')
|
133
|
|
- })
|
|
78
|
+ onChangethis = async (value) => {
|
|
79
|
+ //获取tree的修改前数据
|
|
80
|
+ const testarr = this.state.treeData
|
|
81
|
+ //把tree的修改前数据赋修改代存数据
|
|
82
|
+ // let Data1 = this.state.treeData
|
|
83
|
+ console.log('value*********>>', value)
|
|
84
|
+ // console.log('Data1------------>', Data1)
|
|
85
|
+ // urlData: { id: value.institutionId }
|
|
86
|
+ // //修改树的数据存在Data1
|
|
87
|
+ // for (var i = 0; i < testarr.length; i++) {
|
|
88
|
+ // // console.log('ID------------>', Data1[i].key);
|
|
89
|
+ // if (testarr[i].key == value.institutionId) {
|
|
90
|
+ // Data1[i] = value
|
|
91
|
+ // const res = request(`/api/admin/institution/${Data1[i].institutionId}`, {
|
|
92
|
+ // method: 'PUT',
|
|
93
|
+ // data: value,
|
|
94
|
+ // })
|
|
95
|
+ // console.log('*************', value)
|
|
96
|
+ // // console.log('*institutionName*****', institutionName)
|
|
97
|
+
|
|
98
|
+ // if (res.success) {
|
|
99
|
+ // message.success("成功")
|
|
100
|
+ // } else {
|
|
101
|
+ // message.error("失败")
|
|
102
|
+ // }
|
|
103
|
+ // }
|
|
104
|
+ // }
|
|
105
|
+ // this.setState({
|
|
106
|
+ // treeData1: Data1
|
|
107
|
+ // }, () => {
|
|
108
|
+ // message.success('修改成功!')
|
|
109
|
+ // })
|
134
|
110
|
|
135
|
111
|
}
|
136
|
112
|
|
137
|
113
|
|
138
|
|
-
|
|
114
|
+ //单击赋值
|
139
|
115
|
onSelect = (values, info) => {
|
140
|
|
- // this.FromValue(info.node)
|
141
|
|
- console.log(this.state.treeData)
|
142
|
|
- console.log(info)
|
143
|
116
|
this.setState({ values }, () => {
|
144
|
117
|
this.formRef.current.setFieldsValue({
|
145
|
118
|
...info.node.props,
|
146
|
|
- key: info.node.props.eventKey,//event
|
147
|
|
- day: moment(info.node.props.day)
|
|
119
|
+ // institutionId: info.node.props.institutionId,//event
|
|
120
|
+ // day: moment(info.node.props.day)
|
148
|
121
|
})
|
149
|
|
- console.log(this.getTreeData)
|
150
|
|
-
|
151
|
|
- // moment(info.node.props.day).format('YYYY-MM-DD')
|
|
122
|
+ console.log(info.node.props);
|
152
|
123
|
})
|
153
|
124
|
}
|
154
|
125
|
|
155
|
|
-
|
156
|
|
-
|
157
|
|
- // getTreeData = (e) => {
|
158
|
|
- // request({
|
159
|
|
- // url: "http://localhost:8000/api/admin/institution/list",
|
160
|
|
- // method: 'GET',
|
161
|
|
-
|
162
|
|
- // // params: {leveltype: 3, cityId},
|
163
|
|
- // action: "admin.institution.get",
|
164
|
|
- // }).then((treeData) => {
|
165
|
|
- // setData(treeData)
|
166
|
|
- // console.log(this.getTreeData)
|
167
|
|
- // })
|
168
|
|
- // }
|
169
|
|
-
|
170
|
|
-
|
171
|
|
-
|
172
|
|
-
|
173
|
|
-
|
174
|
|
-
|
|
126
|
+ //首次加载
|
175
|
127
|
async institutionTree(params) {
|
176
|
128
|
let arr = []
|
177
|
|
-
|
178
|
129
|
return request('/api/admin/institution/list', {
|
179
|
130
|
method: 'GET',
|
180
|
131
|
data: params,
|
181
|
132
|
}).then((testarr2) => {
|
182
|
133
|
this.setState({ testarr: testarr2 }, () => {
|
183
|
|
- console.log("testarr2")
|
184
|
|
- console.log(this.state.testarr)
|
|
134
|
+ // console.log("testarr2")
|
|
135
|
+ // console.log(this.state.testarr)
|
185
|
136
|
// title: 'institutionId',
|
186
|
137
|
// name: 'institutionName',
|
187
|
138
|
// key: '0-0-0',
|
188
|
139
|
const arr2 = this.state.testarr
|
189
|
140
|
for (var i = 0; i < this.state.testarr.length; i++) {
|
190
|
141
|
let list = {
|
191
|
|
- title: 'institutionId',
|
192
|
|
- name: 'institutionName',
|
193
|
|
- key: '0-0-0'
|
|
142
|
+ title: '',
|
|
143
|
+ institutionName: 'institutionName',
|
|
144
|
+ // name: 'institutionId',
|
|
145
|
+ institutionId: 'institutionId',
|
|
146
|
+ key: '0-0-0',
|
194
|
147
|
}
|
|
148
|
+ list.institutionName = arr2[i].institutionName
|
195
|
149
|
list.title = arr2[i].institutionName
|
196
|
|
- list.key = '0' + i.toString
|
|
150
|
+ list.institutionId = arr2[i].institutionId
|
|
151
|
+ list.key = arr2[i].institutionId
|
|
152
|
+ // '0' + i.toString
|
197
|
153
|
arr.push(list)
|
198
|
|
-
|
199
|
154
|
}
|
200
|
|
-
|
|
155
|
+ // console.log("arr")
|
|
156
|
+ // console.log(arr)
|
201
|
157
|
this.setState({
|
202
|
158
|
treeData: arr
|
203
|
159
|
})
|
|
@@ -207,27 +163,17 @@ class TreeDemo extends React.Component {
|
207
|
163
|
})
|
208
|
164
|
}
|
209
|
165
|
|
210
|
|
- componentDidMount() {
|
211
|
|
- // fetch(`http://localhost:8000/api/admin/institution/list`, {
|
212
|
|
- // headers: {
|
213
|
|
- // Authorization: "Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiIxIiwib3JnSWQiOiIxIiwiZXhwIjoxNjI3MDQ1MjQxfQ.7FhVDoI0dEECZinRUzMzcLl-kcobkamZSqoUzTxBTRo"
|
214
|
|
- // }
|
215
|
|
- // }).then((res) => {
|
216
|
|
- // console.log(res)
|
217
|
|
- // }),
|
218
|
|
- // this.institutionTree()
|
219
|
|
- this.institutionTree([])
|
220
|
|
-
|
221
|
|
- }
|
222
|
|
-
|
223
|
166
|
|
224
|
167
|
|
225
|
168
|
|
|
169
|
+ UNSAFE_componentWillMount() {
|
|
170
|
+ this.institutionTree([])
|
226
|
171
|
|
|
172
|
+ }
|
227
|
173
|
|
228
|
174
|
|
229
|
175
|
renderTreeNodes = data =>
|
230
|
|
- data.map(item => {
|
|
176
|
+ (data || []).map(item => {//初始化data
|
231
|
177
|
if (item.children) {
|
232
|
178
|
return (
|
233
|
179
|
<TreeNode title={item.title} key={item.key} dataRef={item} >
|
|
@@ -237,29 +183,13 @@ class TreeDemo extends React.Component {
|
237
|
183
|
}
|
238
|
184
|
return <TreeNode key={item.key} {...item} />;
|
239
|
185
|
});
|
240
|
|
- //搜索框
|
241
|
|
- // onChange = e => {
|
242
|
|
- // const { value } = e.target;
|
243
|
|
- // const expandedKeys = treeData
|
244
|
|
- // .map(item => {
|
245
|
|
- // if (item.title.indexOf(value) > -1) {
|
246
|
|
- // return getParentKey(item.key, gData);
|
247
|
|
- // }
|
248
|
|
- // return null;
|
249
|
|
- // })
|
250
|
|
- // .filter((item, i, self) => item && self.indexOf(item) === i);
|
251
|
|
- // this.setState({
|
252
|
|
- // expandedKeys,
|
253
|
|
- // searchValue: value,
|
254
|
|
- // autoExpandParent: true,
|
255
|
|
- // });
|
256
|
|
- // };
|
|
186
|
+
|
257
|
187
|
|
258
|
188
|
|
259
|
189
|
|
260
|
190
|
|
261
|
191
|
render() {
|
262
|
|
- const { searchValue } = this.state;
|
|
192
|
+ const { searchValue, autoExpandParent, expandedKeys, checkedKeys } = this.state;
|
263
|
193
|
return (
|
264
|
194
|
<Card>
|
265
|
195
|
<Row >
|
|
@@ -268,13 +198,20 @@ class TreeDemo extends React.Component {
|
268
|
198
|
<FormItem
|
269
|
199
|
label="管辖部门"
|
270
|
200
|
>
|
271
|
|
- {/* <Search style={{ marginBottom: 8 }} placeholder="Search" onChange={this.onChange} /> */}
|
|
201
|
+ <Search style={{ marginBottom: 8 }} placeholder="Search" onChange={this.onChange} />
|
272
|
202
|
<Tree
|
273
|
203
|
// api={apis.Institution.instIist}
|
|
204
|
+ // checkable
|
|
205
|
+ onExpand={this.onExpand}
|
|
206
|
+ expandedKeys={expandedKeys}
|
|
207
|
+ autoExpandParent={autoExpandParent}
|
|
208
|
+ // checkedKeys={checkedKeys}
|
|
209
|
+
|
274
|
210
|
showLine
|
275
|
|
- defaultExpandedKeys={['0-0']}
|
|
211
|
+ // defaultExpandedKeys={['0-0']}
|
276
|
212
|
onSelect={this.onSelect}
|
277
|
213
|
treeData={this.state.treeData}
|
|
214
|
+ // treeData={loop(gData)}
|
278
|
215
|
// api={apis.Institution.instIist}
|
279
|
216
|
>
|
280
|
217
|
{this.renderTreeNodes(this.state.treeData)}
|
|
@@ -289,14 +226,17 @@ class TreeDemo extends React.Component {
|
289
|
226
|
<TabPane tab='编辑' key='1'>
|
290
|
227
|
<TreedataFrom
|
291
|
228
|
ref={this.formRef}
|
|
229
|
+ api={apis.Institution.instiAlert}
|
292
|
230
|
triggerRef={this.bindRef}
|
293
|
231
|
onChangethis={this.onChangethis}
|
294
|
232
|
onSubmit={this.onChangethis}
|
295
|
233
|
/>
|
296
|
234
|
</TabPane>
|
297
|
|
- <TabPane tab='新增' key='2'>
|
298
|
|
- <div>You cannot set a form field before rendering a field associated with the value. </div>
|
299
|
|
- </TabPane>
|
|
235
|
+ {/* <TabPane tab='新增' key='2'>
|
|
236
|
+ <TreedataAdd
|
|
237
|
+ >
|
|
238
|
+ </TreedataAdd>
|
|
239
|
+ </TabPane> */}
|
300
|
240
|
|
301
|
241
|
</Tabs>
|
302
|
242
|
</Card>
|