Organization.tsx
2.34 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
import React from 'react';
import {
TreeSelect,
} from 'antd';
import type {
TreeSelectProps,
} from 'antd/lib/tree-select';
import {
requestCode,
} from '@/services/server';
export interface SetSelectProps extends TreeSelectProps<any> {
value?: any;
onChange?: (val: string | undefined, options: Record<string, any>) => void;
}
/**
* @name 选择部门组件
*/
export default class Index extends React.Component<SetSelectProps>{
state = {
treeData: [],
}
componentDidMount() {
this.optionSelect();
}
optionSelect() {
requestCode('xn.master.organizationTree.find',{}).then((data: any) => {
const { result } = data;
function filterArray(arr: any) {
return arr.map((item: any) => {
const { id, name, subList } = item;
return {
...item,
key: id,
title: name,
children: filterArray(subList),
}
})
}
if (result) {
this.setState({
treeData: filterArray(result),
})
}
})
}
render() {
const { treeData } = this.state;
const { value, style, multiple, placeholder, onChange } = this.props;
return (
<TreeSelect
showSearch
allowClear
value={value}
multiple={multiple}
placeholder={placeholder || '请选择部门'}
treeNodeFilterProp="title"
style={style}
onChange={(val) => {
let option = {};
function listof(arr: any) {
arr.forEach((item: any) => {
const { id, children } = item;
if (id === val) {
option = item;
return;
}
if (children) listof(children);
})
}
listof(treeData);
if(onChange) onChange(val, option);
}}
treeData={treeData}
>
</TreeSelect>
)
}
}