index.jsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React, { Component } from 'react';
  2. import style from './index.less';
  3. import delIcon from '@common/images/del_nor.png';
  4. import {windowEventHandler,getCurrentDate,getWindowInnerHeight} from '@utils/tools'
  5. class MedicalInfo extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.$inp = React.createRef();
  9. this.$cont = React.createRef();
  10. this.state={
  11. val:''
  12. };
  13. this.search = this.search.bind(this);
  14. this.handleChange = this.handleChange.bind(this);
  15. this.clear = this.clear.bind(this);
  16. this.getSearchList = this.getSearchList.bind(this);
  17. this.handleEnter = this.handleEnter.bind(this);
  18. }
  19. getSearchList() {
  20. const { getAllConceptDetail,searchResult } = this.props;
  21. return searchResult && searchResult.map((item) => {
  22. return <li key={item.conceptId} onClick={() =>getAllConceptDetail({name: item.name, type: item.type})}>
  23. <span>{item.name}</span>
  24. <i>( {item.libTypeName} )</i>
  25. <button>查看</button>
  26. </li>;
  27. });
  28. }
  29. search(){
  30. const {handleChangeValue} = this.props;
  31. const val = this.$inp.current.value;
  32. handleChangeValue&&handleChangeValue(val);
  33. }
  34. handleChange(){
  35. this.setState({
  36. val:this.$inp.current.value
  37. });
  38. }
  39. handleEnter(e){
  40. if(e.keyCode==13){
  41. this.search();
  42. }
  43. }
  44. clear(){
  45. const {clearResult} = this.props;
  46. this.$inp.current.value = '';
  47. this.setState({
  48. val:''
  49. });
  50. clearResult&&clearResult();
  51. }
  52. componentDidMount(){
  53. const height = getWindowInnerHeight()-170;
  54. this.$cont.current.style.height = height+"px";
  55. if(this.$cont.current){
  56. windowEventHandler('resize', ()=>{
  57. const height = getWindowInnerHeight()-170;
  58. this.$cont.current.style.height = height+"px";
  59. });
  60. }
  61. }
  62. render() {
  63. const {searchResult} = this.props;
  64. const {val} = this.state;
  65. return (
  66. <div className={style['search-cont']} ref={this.$cont}>
  67. <div className={style['search-box']}>
  68. <p className={style['title']}>医学知识搜索</p>
  69. <p className={style['cont']}>
  70. <input type="text" className={style['input']} ref={this.$inp} onInput={this.handleChange} onKeyUp={this.handleEnter}/>
  71. {val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  72. <button onClick={this.search}>搜索</button>
  73. </p>
  74. </div>
  75. {searchResult&&searchResult.length>0?<div className={style['result']}>
  76. <p className={style['title']}>查询内容</p>
  77. <ul>
  78. {this.getSearchList()}
  79. </ul>
  80. </div>:<p className={style['no-data']}>暂无搜索结果!</p>}
  81. </div>
  82. )
  83. }
  84. }
  85. export default MedicalInfo;