index.js
6.03 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import React from 'react'
import './index.less'
import { Input, Form, Button, Table, message, Radio} from 'antd'
import { UserManageBar } from '@components/Common'
import axios from '@src/axios/index'
import Utils from '@src/utils/utils'
import {API_SYSORORG_MANAGE } from '@src/Api'
const FormItem = Form.Item;
class LayerOrgSelect extends React.Component {
constructor(props) {
super(props)
this.state = {
orgVisible: this.props.orgVisible,
treeData: [{id: 1 ,childOrgs: [], name: 'a'},{id: 2 ,childOrgs: [], name: 'b'}],
treeLoad: false,
isExpand: false,
orgData: { // 树结构的选中的值
id: null,
name: ''
},
searchForm:{ //树结构的查询条件
orgId: null,
orgName: ''
},
}
}
componentDidMount() {
this.getOrgTreeList()
this.props.onRef(this)
}
//获取机构树状图
getOrgTreeList = (isLocal) => {
this.setState({
treeData:[],
treeLoad: true,
orgData: {name: isLocal === 'reset' || isLocal === 'search' ? '' : this.props.orgData.name }}, ()=> {
// if(isLocal !== 'search') {
// this.props.form.setFieldsValue({layerOrgName: this.state.orgData.name})
// }
var searchData = this.props.form.getFieldsValue()
if(isLocal !== 'search') {
searchData['layerOrgName'] = this.state.orgData.name
// this.props.form.setFieldsValue({layerOrgName: this.state.orgData.name})
}
axios.ajax({
url: API_SYSORORG_MANAGE.getOrgByName,
data:{
name: searchData.layerOrgName || '',
pageNum: 1,
pageSize: 999999
}
}).then(res => {
if (res && res.length > 0) {
this.setState({
treeData: res,
orgData: {id: this.state.searchForm.orgId},
isExpand: false,
treeLoad: false
})
} else {
this.setState({
treeData: [],
isExpand: false,
treeLoad: false
})
}
})
});
}
// 树搜索
searchOrgOpt = (e)=> {
this.setState({treeLoad:true, orgData:{id: this.state.searchForm.orgId}})
this.getOrgTreeList('search')
}
// 机构的重置搜索
orgReset = ()=> {
this.props.form.resetFields('layerOrgName');
this.setState({orgData:{id: this.state.searchForm.orgId}})
this.setState({treeData: []}, ()=> {
this.getOrgTreeList('reset')
})
}
onExpand = (expanded, record)=> {
let _this = this
let arr = [];
this.setState({treeLoad: true})
if (expanded) {
axios.ajax({
url: API_SYSORORG_MANAGE.getChildsOrgByCode,
data: {
code: record.code
}
}).then(res => {
if (res && res.length > 0) {
arr = _this.renderTree(this.state.treeData, record, res)
this.setState({treeData: arr, treeLoad: false})
} else {
this.setState({
treeLoad : false
})
return
}
})
} else {
arr = _this.renderTree(this.state.treeData, record, [])
this.setState({treeData: arr, treeLoad: false})
}
}
renderTree (data, record, res) {
let _this = this
data.forEach((item,index) => {
if(item.id === record.id){
item.childOrgs =res
}else{
if(item.childOrgs && item.childOrgs.length){
_this.renderTree(item.childOrgs, record, res)
}
}
})
return data
}
render () {
const { getFieldDecorator } = this.props.form;
const _this = this
const treeCol =[
{title: '机构名称',key: 'name',dataIndex: 'name',width: '300px',align: 'left',className: 'tdWidth', render(text, records,index) {
const obj = records
return <Radio ref={records.name} data-name={records.name} checked={_this.props.orgData.id == records.id} value={records.id}
onClick= {(e)=> _this.props.selectTree(e, obj)}>
{ Utils.formatTableColumn(records.name) }
</Radio>
}},
{title: '机构级别',key: 'orgGrade',dataIndex: 'orgGrade', width: '80px',align: 'center',className: 'tdWidth', render(orgGrade) {
return Utils.formatTableColumn(orgGrade)
}},
{title: '更新时间',key: 'updateTime',dataIndex: 'updateTime',width: '100px',align: 'center', render(name) {
return Utils.formateDateToYMD(name)
}},
{title: '备注',key: 'remark',dataIndex: 'remark',width: '180px',align: 'center',className: 'tdWidth', render(name) {
return Utils.formatTableColumn(name)
}}
];
return (
<div>
<Form layout="inline" name="orgForm">
<FormItem >
<label >机构名称</label>
{
getFieldDecorator('layerOrgName', {
})(
<Input placeholder="机构名称" />
)
}
</FormItem>
<FormItem style={{ marginTop: 38, }} >
<Button onClick={(item) => { this.searchOrgOpt(item) }} style={{ background: '#00BB29', color: "#fff", marginRight: 4 }} >查询</Button>
<Button onClick={this.orgReset} style={{ background: '#ED1719', color: "#fff" }} type="danger">重置</Button>
</FormItem>
</Form>
<UserManageBar title="详细数据" />
<div className="reTable exTable borderTable orgTable">
<Table
rowKey= 'id'
key={`table-${this.state.treeData && this.state.treeData.length}`}
bordered={false}
columns={treeCol}
defaultExpandAllRows = {this.state.isExpand}
loading={this.state.treeLoad}
dataSource={this.state.treeData}
childrenColumnName= 'childOrgs'
onExpand = {this.onExpand}
pagination={false}
scroll={{ y: 340 }}
/>
</div>
</div>
)
}
}
LayerOrgSelect = Form.create({})(LayerOrgSelect)
export default LayerOrgSelect