PositionField.js
3.4 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
import React,{PropTypes} from 'react';
import { connect } from 'react-redux';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './form.scss';
import {loadOrganizations} from '../../../redux/actions/hrSetting';
import {createRecord} from '../../../utils/formUtil';
import {getPositions} from '../../../utils/orgUtil';
import {Form,Select,Tag,Input,Button,Col} from 'antd';
const Option = Select.Option;
const FormItem = Form.Item;
const InputGroup = Input.Group;
const OptGroup = Select.OptGroup;
const getOptions=(positions)=>{
let children = [];
positions.map((position,i)=>{
children.push(<Option key={position.uuid} {...position}>{position.name}</Option>);
})
return children;
}
class PositionField extends React.Component {
constructor(props) {
super(props);
this.filterOption=this.filterOption.bind(this);
this.selectChange=this.selectChange.bind(this);
this.state={
organizationName:'',
orgUuid:'',
positions:[]
}
}
static propTypes = {
label:PropTypes.string,
options:PropTypes.object,
organizations:PropTypes.array
}
static defaultProps={
}
filterOption(inputValue, option){ /*过滤*/
const {name,pinyin,pinyinfl}=option.props;
if(name&&name.indexOf(inputValue)!=-1){
return true
}if(pinyin&&pinyin.indexOf(inputValue)!=-1){
return true
}if(pinyinfl&&pinyinfl.indexOf(inputValue)!=-1){
return true
}
return false;
}
selectChange(value){
const {field={}}=this.props;
field.onChange(value);
}
componentDidMount(){
const self=this;
getPositions().then(data=>{
self.setState({
positions:data.items
})
}).catch(err=>{
})
}
componentWillReceiveProps(nextProps){
}
componentDidUpdate(prevProps,prevState){
}
componentWillUnmount() {
}
render(){
const {label,options,name,field={},organizations=[]}=this.props;
const {organizationName,orgUuid,positions}=this.state;
let defaultValue=field.value;
if(defaultValue&&defaultValue.indexOf(',')!=-1){
defaultValue=field.value.split(',');
}else if(defaultValue){
defaultValue=orgUuid ? [orgUuid] : [field.value];
}else{
defaultValue=[]
}
return(
<FormItem
label={label}
labelCol={{ span: 6 }}
wrapperCol={{ span: 14 }}
required={options.is_required}
validateStatus={null}
help="">
<Select
name={name}
style={{display:'inline-block'}}
multiple={false}
style={{ width: '100%' }}
placeholder={options.tooltip}
notFoundContent='没有找到'
filterOption={this.filterOption}
optionLabelProp='name'
disabled={false}
value={defaultValue}
onChange={this.selectChange}>
{getOptions(positions)}
</Select>
</FormItem>
)
}
}
const mapStateToProps = (state) => {
const {hrSetting:{organizations}}= state;
return {
organizations
};
}
export default connect(mapStateToProps)(PositionField);