
import React,{Component} from 'react';
import PropTypes from 'prop-types';
import style from './index.less';
/***
下拉框无殊组件
datas：父组件传来的数据，为数组，必须
noSpecialFlag：互斥标识，2选中其他 1选中无殊 0默认无选中;
noSpecial：选中标识，true选中，
noSpecialClick：点击事件
**/
class Normal extends React.Component{
  constructor(props){
    super(props);
    this.preventS = this.preventS.bind(this);
  }

  preventS(e){
    e.stopPropagation();
  }

  handleClick(name){
    const {noSpecialClick} =this.props;
    noSpecialClick && noSpecialClick(name);
  }

  getLabs(){
    const {noSpecialFlag,noSpecial,noSpecialClick,datas} =this.props;
    if(noSpecialFlag ==1){
      let list = datas.map((it,i)=>{
        return <span className={style['disabled']} >{it.name}</span>
      })
      return list;
    }else{
      let list = datas.map((it,i)=>{
        return <span className={noSpecial?style['selected-span']:''} onClick={()=>{this.handleClick(it.name)}}>{it.name}</span>
      })
      return list;
    }
  }

  render(){
    return <div className={style['sentence']} contentEditable='false' onClick={this.preventS}>
      {this.getLabs()}
    </div>
  }
}

Normal.propTypes = {
    handleClick:PropTypes.func,
    noSpecial:PropTypes.bool,
    datas:PropTypes.array
};

export default Normal;
