index.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. hasSearch: false,
  13. msg:''
  14. };
  15. this.search = this.search.bind(this);
  16. this.handleChange = this.handleChange.bind(this);
  17. this.clear = this.clear.bind(this);
  18. this.getSearchList = this.getSearchList.bind(this);
  19. this.handleEnter = this.handleEnter.bind(this);
  20. }
  21. getSearchList() {
  22. const { getAllConceptDetail,searchResult } = this.props;
  23. return searchResult && searchResult.map((item) => {
  24. return <li key={item.conceptId}
  25. title='点击查看详情'
  26. onClick={() =>getAllConceptDetail({name: item.name, type: item.type})}>
  27. <span>{item.name}</span>
  28. <i>( {item.libTypeName} )</i>
  29. {/*<button>查看</button>*/}
  30. </li>;
  31. });
  32. }
  33. search(){
  34. if(this.state.hasSearch === false) {
  35. this.setState({
  36. hasSearch: true,
  37. msg:'暂无搜索结果!'
  38. })
  39. }
  40. const {handleChangeValue} = this.props;
  41. const val = this.$inp.current.value;
  42. handleChangeValue&&handleChangeValue(val);
  43. }
  44. handleChange(){
  45. const value = this.$inp.current.value;
  46. const {clearResult} = this.props;
  47. this.setState({
  48. val: value
  49. });
  50. if (value === '') {
  51. this.setState({
  52. val: '',
  53. hasSearch: false,
  54. msg: ''
  55. });
  56. clearResult && clearResult();
  57. }
  58. }
  59. handleEnter(e){
  60. if(e.keyCode==13){
  61. this.search();
  62. }
  63. }
  64. clear(){
  65. const {clearResult} = this.props;
  66. this.$inp.current.value = '';
  67. this.setState({
  68. val:'',
  69. hasSearch: false,
  70. msg:''
  71. });
  72. clearResult&&clearResult();
  73. }
  74. componentDidMount(){
  75. const height = getWindowInnerHeight()-170;
  76. this.$cont.current.style.height = height+"px";
  77. if(this.$cont.current){
  78. windowEventHandler('resize', ()=>{
  79. const height = getWindowInnerHeight()-170;
  80. this.$cont.current.style.height = height+"px";
  81. });
  82. }
  83. }
  84. componentWillReceiveProps(){
  85. this.setState({
  86. hasSearch: false
  87. });
  88. }
  89. render() {
  90. const {searchResult} = this.props;
  91. const {val, hasSearch,msg} = this.state;
  92. return (
  93. <div className={style['search-cont']} ref={this.$cont}>
  94. <div className={style['search-box']}>
  95. <p className={style['title']}>医学知识搜索</p>
  96. <p className={style['cont']}>
  97. <input type="text" className={style['input']} ref={this.$inp} onInput={this.handleChange} onKeyUp={this.handleEnter}/>
  98. {val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  99. <button onClick={this.search}>搜索</button>
  100. </p>
  101. </div>
  102. {searchResult&&searchResult.length>0?<div className={style['result']}>
  103. <p className={style['title']}>查询内容</p>
  104. <ul>
  105. {this.getSearchList()}
  106. </ul>
  107. </div>:<p className={style['no-data']}>{hasSearch?'搜索中...':msg}</p>}
  108. </div>
  109. )
  110. }
  111. }
  112. export default MedicalInfo;