index.jsx 3.8 KB

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