index.jsx 4.1 KB

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