index.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * showType:1-本体,2-同义词,3-子项,同义词展示在括号内
  14. * retrievalName:同义词
  15. * name:本体
  16. **/
  17. class SearchDrop extends Component{
  18. constructor(props){
  19. super(props);
  20. this.handleSelect = this.handleSelect.bind(this);
  21. }
  22. getClass(){
  23. let name = style['text-list'];
  24. let isHide = this.props.show?'':style['hide'];
  25. switch (this.props.type){
  26. case 'text':
  27. name = style['text-list'];
  28. break;
  29. case 'label':
  30. name = style['label-list'];
  31. break;
  32. default:
  33. name = style['text-list'];
  34. }
  35. return classNames(style['list'],name,isHide);
  36. }
  37. getStyle(){
  38. const {left,top} = this.props;
  39. return {
  40. left:left?left:'',
  41. top:top?top:''
  42. }
  43. }
  44. handleSelect(e,item){
  45. e.stopPropagation();
  46. const {onSelect,onShow} = this.props;
  47. onSelect&&onSelect(item);
  48. // onShow&&onShow(e,false);
  49. }
  50. render(){
  51. let litext = '';
  52. return <div className={this.getClass()} contenteditable="false" id="searchBox" style={this.getStyle()}>
  53. <ul>
  54. {this.props.data&&this.props.data.map((it)=>{
  55. litext = it.showType==1?it.name:it.name+'('+it.retrievalName+')';
  56. return <li onClick={(e)=>this.handleSelect(e,it)} title={litext}>{litext}</li>
  57. })}
  58. </ul>
  59. </div>
  60. }
  61. }
  62. export default SearchDrop;