EmpCombo.js 1.8 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';  
import {connect} from 'react-redux';
import cx from 'classnames';
import s from './form.scss';
import {Select } from 'antd';
const Option = Select.Option;

import {fiterEmployeesStatu}  from '../../../utils/hrUtil';

class EmpCombo extends React.Component {
    constructor(props) {
        super(props);   
        this.searchOption=this.searchOption.bind(this);
    }
    static propTypes = {   
        employees:PropTypes.array,
        defaultValue:PropTypes.string
    } 
    static defaultProps={  
        defaultValue:'',
        onChange:(value)=>{

        }
    } 
    searchOption(inputValue, option){
        const {name,pinyin,pinyinfl}=option.props;
        if(name.indexOf(inputValue)!=-1||
            pinyin.indexOf(inputValue)!=-1||
            pinyinfl.indexOf(inputValue)!=-1){
            return true;
        }else{
            return false;
        }
    }
    render(){    
        console.log(this.props);
        const {employees,defaultValue}=this.props;
        const _employees=fiterEmployeesStatu(employees);
        return( 
           <Select showSearch  defaultValue={defaultValue} value={this.props.value}
                    placeholder={this.props.placeholder||"请选择人员"}     notFoundContent="无法找到" 
                    filterOption={this.searchOption}  onChange={this.props.onChange}>
                {_employees.map((employee,i)=>{
                    return <Option key={i} value={employee.uuid} {...employee} >{employee.name}</Option>
                })}
            </Select>
        )
    }
}


const mapStateToProps = (state) => {
    const {hrSetting:{employees}}=state; 
    return {
        employees 
    };
}

export default connect(mapStateToProps)(EmpCombo);