mutilOptions.js
4.52 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
import React from 'react'
import UserManageBar from '@components/Common/WhiteBar/index'
import { Form, Button, Input, Tree, message, Radio, } from 'antd'
import Utils from '@src/utils/utils'
const FormItem = Form.Item;
const TreeNode = Tree.TreeNode
//创建所属机构树
class OrgOptionsForm extends React.Component {
state = {}
//查询角色列表
queryList = () => {
let data = this.props.form.getFieldsValue();
if (!data.name || !data.name.replace(/\s+/g, "")) {
message.warn('请输入角色名')
return
}
this.props.getRoleParam(data.name.replace(/\s+/g, ""))
this.setState({
checkedKeys: []
})
}
componentWillMount(){
this.reset()
const { setRadioId } = this.props
console.log(setRadioId)
this.setState({
checkedKeys:setRadioId ? [setRadioId.key] : ''
})
}
//重置
reset = () => {
this.props.getRoleInfo()
this.props.form.resetFields()
this.setState({
checkedKeys: []
})
this.props.getRoleObj({})
}
//递归获取树形机构图
renderTreeNodes = (data) => {
const selfObj = this.props.selfObj
const { setRadioId } = this.props
console.log('selfObj',selfObj)
return data.map((item,index ) => {
if (item.roles && item.roles.length > 0) {
return <TreeNode
icon={<Radio ref={item.name} disabled={selfObj ? (selfObj.key== item.id ? true:false) :false}
checked={setRadioId.key == item.id} value={item.id} />}
title={<span> {Utils.formatTableColumn(item.name)}</span>}
key={item.id}
name={item.name}
>
{selfObj? selfObj.key== item.id ? delete item.roles: this.renderTreeNodes(item.roles):this.renderTreeNodes(item.roles)}
</TreeNode>
} else {
return <TreeNode icon={<Radio ref={item.name} disabled={selfObj ? (selfObj.key== item.id ? true:false) :false} checked={setRadioId.key== item.id} value={item.id} />} title={<span> {Utils.formatTableColumn(item.name)}
</span>} key={item.id}
name={item.name}
>
</TreeNode>
}
})
}
onCheck = (checkedKeys) => {
// this.props.patchMenuInfo(checkedKeys)
}
onSelect = (checkedKeys, e) => {
// console.log(e.node.props.name)
// console.log(checkedKeys.includes('top'));
if (checkedKeys.includes('top') || checkedKeys.length === 0) return
this.setState({
checkedKeys,
checked: {
key: checkedKeys[0],
val: e.node.props.name
}
})
// console.log('子组件',this.state.checked);
const selfObj = this.props.selfObj
if(selfObj){
if( selfObj.key !== checkedKeys[0]){
if (checkedKeys && checkedKeys.length > 0) {
this.props.getRoleObj(
{
key: checkedKeys[0],
val: e.node.props.name
}
)
}
}
}else{
if (checkedKeys && checkedKeys.length > 0) {
this.props.getRoleObj(
{
key: checkedKeys[0],
val: e.node.props.name
}
)
}
}
}
render() {
const { getFieldDecorator } = this.props.form;
const roleOptionsArr = this.props.roleOptionsArr || []
return (
<div>
<Form layout="inline" >
<FormItem >
<label >角色名称</label>
{
getFieldDecorator('name', {
// initialValue: '雨轩',
})(
<Input placeholder="角色名称" />
)
}
</FormItem>
<FormItem style={{ marginTop: 38, }} >
<Button onClick={(item) => { this.queryList(item) }} style={{ background: '#00BB29', color: "#fff", marginRight: 4 }} >查询</Button>
<Button onClick={this.reset} style={{ background: '#ED1719', color: "#fff" }} type="danger">重置</Button>
</FormItem>
</Form>
<UserManageBar title="详细数据" />
<div className="treeTable" >
{roleOptionsArr.length !== 0 ?
<Tree
// checkable
showIcon
//defaultExpandAll
className="orgTree"
onSelect={(checkedKeys, e) => { this.onSelect(checkedKeys, e) }}
>
{this.renderTreeNodes(roleOptionsArr)}
</Tree>
: <div className="ant-table-placeholder">No data</div>
}
</div>
</div>
);
}
}
OrgOptionsForm = Form.create({})(OrgOptionsForm)
export default OrgOptionsForm