index.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }
  18. getSearchList() {
  19. const { getAllConceptDetail,searchResult } = this.props;
  20. return searchResult && searchResult.map((item) => {
  21. return <li key={item.conceptId} onClick={() =>getAllConceptDetail({name: item.name, type: item.type})}>
  22. <span>{item.name}</span>
  23. <i>( {item.libTypeName} )</i>
  24. <button>查看</button>
  25. </li>;
  26. });
  27. }
  28. search(){
  29. const {handleChangeValue} = this.props;
  30. const val = this.$inp.current.value;
  31. handleChangeValue&&handleChangeValue(val);
  32. }
  33. handleChange(){
  34. console.log('change')
  35. this.setState({
  36. val:this.$inp.current.value
  37. });
  38. }
  39. clear(){
  40. this.$inp.current.value = '';
  41. this.setState({
  42. val:''
  43. });
  44. }
  45. componentDidMount(){
  46. const height = getWindowInnerHeight()-170;
  47. this.$cont.current.style.height = height+"px";
  48. if(this.$cont.current){
  49. windowEventHandler('resize', ()=>{
  50. const height = getWindowInnerHeight()-170;
  51. this.$cont.current.style.height = height+"px";
  52. });
  53. }
  54. }
  55. render() {
  56. const {searchResult} = this.props;
  57. const {val} = this.state;
  58. return (
  59. <div className={style['mefical-info-wrapper']} ref={this.$cont}>
  60. <div className={style['search-cont']}>
  61. <p className={style['title']}>医学知识搜索</p>
  62. <p className={style['cont']}>
  63. <input type="text" className={style['input']} ref={this.$inp} />
  64. {val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  65. <button onClick={this.search}>搜索</button>
  66. </p>
  67. {searchResult&&searchResult.length>0?<div className={style['result']}>
  68. <p className={style['title']}>查询内容</p>
  69. <ul>
  70. {this.getSearchList()}
  71. </ul>
  72. </div>:<p className={style['no-data']}>暂无搜索结果!</p>}
  73. </div>
  74. </div>
  75. )
  76. }
  77. }
  78. export default MedicalInfo;