index.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React,{Component} from 'react';
  2. import classNames from 'classnames';
  3. import style from "./index.less";
  4. /****
  5. * 主诉常见症状下拉
  6. * 接收参数:
  7. * data: json数组
  8. * show:true/false
  9. * textKey: 选项文字字段名
  10. * idKey: 选项id字段名
  11. * type: text选项为纯文本,label选项为标签
  12. * onSelect: 选中事件
  13. *
  14. * ***/
  15. class CommonSymptom extends Component{
  16. constructor(props){
  17. super(props);
  18. this.handleSelect = this.handleSelect.bind(this);
  19. }
  20. getClass(){
  21. let name = style['text-list'];
  22. let isHide = this.props.show?'':style['hide'];
  23. switch (this.props.type){
  24. case 'text':
  25. name = style['text-list'];
  26. break;
  27. case 'label':
  28. name = style['label-list'];
  29. break;
  30. default:
  31. name = style['text-list'];
  32. }
  33. return classNames(style['list'],name,isHide);
  34. }
  35. handleSelect(e,item){
  36. e.stopPropagation();
  37. const {onSelect,onShow} = this.props;
  38. onSelect&&onSelect(item);
  39. // onShow&&onShow(e,false);
  40. }
  41. render(){
  42. const {data} = this.props;
  43. return <div className={this.getClass()} contenteditable="false">
  44. <ul className={style["listBox"]}>
  45. {data&&data.map((it)=>{
  46. return <li onClick={(e)=>this.handleSelect(e,it)}>{it.name}</li>
  47. })}
  48. </ul>
  49. </div>
  50. }
  51. }
  52. export default CommonSymptom;