index.jsx 3.7 KB

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