index.jsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. import Filters from './Filters';
  6. class MedicalInfo extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.$inp = React.createRef();
  10. this.$cont = React.createRef();
  11. this.$ul = React.createRef();
  12. this.state={
  13. val:'',
  14. hasSearch: false,
  15. msg:'',
  16. typeChecks:['0'],
  17. };
  18. this.search = this.search.bind(this);
  19. this.handleChange = this.handleChange.bind(this);
  20. this.clear = this.clear.bind(this);
  21. this.getSearchList = this.getSearchList.bind(this);
  22. this.handleEnter = this.handleEnter.bind(this);
  23. this.handleTypeCheck = this.handleTypeCheck.bind(this);
  24. this.showScale=this.showScale.bind(this);
  25. }
  26. showScale(item){
  27. const {scaleInfo,getScale,showScaleFn} = this.props;
  28. if(scaleInfo&&scaleInfo[item.conceptId]){
  29. showScaleFn&&showScaleFn(item);
  30. }else{
  31. getScale(item);
  32. }
  33. }
  34. getSearchList() {
  35. const { getAllConceptDetail,searchResult } = this.props;
  36. const that = this;
  37. if(searchResult&&searchResult.length>0){
  38. setTimeout(function(){
  39. that.$ul.current.style.height = getWindowInnerHeight()-278+'px';
  40. },100);
  41. }
  42. return searchResult && searchResult.map((item) => {
  43. return <li key={item.conceptId}
  44. title='点击查看详情'
  45. onClick={()=>+item.type===21?this.showScale(item):getAllConceptDetail({name: item.name, type: item.type, uname: item.uniqueName,position:0,showName:item.name})}>
  46. <span>{item.name}</span>
  47. <i>( {item.libTypeName} )</i>
  48. {item.retrievalName?<p>• {item.retrievalName}</p>:''}
  49. {/*<button>查看</button>*/}
  50. </li>;
  51. });
  52. }
  53. search(){
  54. if(this.state.hasSearch === false) {
  55. this.setState({
  56. hasSearch: true,
  57. msg:'暂无搜索结果!'
  58. })
  59. }
  60. const {handleChangeValue} = this.props;
  61. const val = this.$inp.current.value;
  62. handleChangeValue&&handleChangeValue(val,this.state.typeChecks);
  63. }
  64. handleChange(){
  65. const value = this.$inp.current.value;
  66. const {clearResult} = this.props;
  67. this.setState({
  68. val: value
  69. });
  70. if (value === '') {
  71. this.setState({
  72. val: '',
  73. hasSearch: false,
  74. msg: '',
  75. });
  76. clearResult && clearResult();
  77. }
  78. }
  79. handleEnter(e){
  80. if(e.keyCode==13){
  81. this.search();
  82. }
  83. }
  84. clear(){
  85. const {clearResult} = this.props;
  86. this.$inp.current.value = '';
  87. this.setState({
  88. val:'',
  89. hasSearch: false,
  90. msg:''
  91. });
  92. this.$inp.current.focus();
  93. clearResult&&clearResult();
  94. }
  95. handleTypeCheck(val){
  96. let {typeChecks} = this.state;
  97. //const allChecked = typeChecks.includes('0');
  98. const alli = typeChecks.findIndex((it)=>it==='0');
  99. const allChecked = alli!==-1;
  100. if(val==='0'){ //全部与其他互斥
  101. !allChecked?typeChecks=['0']:typeChecks.splice(alli,1);
  102. }else{
  103. allChecked&&typeChecks.splice(alli,1);
  104. if(!typeChecks.includes(val)){
  105. typeChecks.push(val);
  106. }else{
  107. const i = typeChecks.findIndex((it)=>val===it);
  108. typeChecks.splice(i,1);
  109. }
  110. }
  111. this.setState({
  112. typeChecks:typeChecks
  113. });
  114. }
  115. componentDidMount(){
  116. const height = getWindowInnerHeight()-148;
  117. this.$cont.current.style.height = height+"px";
  118. this.props.getFilters();
  119. windowEventHandler('resize', ()=>{
  120. if(this.$cont.current){
  121. const height = getWindowInnerHeight()-148;
  122. this.$cont.current.style.height = height+"px";
  123. }
  124. if(this.$ul.current){
  125. const height = getWindowInnerHeight()-278;
  126. this.$ul.current.style.height = height+"px";
  127. }
  128. });
  129. }
  130. componentWillReceiveProps(){
  131. this.setState({
  132. hasSearch: false
  133. });
  134. }
  135. render() {
  136. const {searchResult,filterList} = this.props;
  137. const {val, hasSearch,msg,typeChecks} = this.state;
  138. return (
  139. <div className={style['search-cont']} ref={this.$cont}>
  140. <div className={style['search-box']}>
  141. <p className={style['cont']}>
  142. <input placeholder="医学知识搜索" type="text" className={style['input']} ref={this.$inp} onInput={this.handleChange} onKeyUp={this.handleEnter}/>
  143. {val?<img src={delIcon} id='clearMedicalInfoSearch' alt="清空" onClick={this.clear}/>:''}
  144. <button onClick={this.search}>搜索</button>
  145. </p>
  146. <Filters data ={filterList} checkeds={typeChecks} handleCheck={this.handleTypeCheck}></Filters>
  147. </div>
  148. {searchResult&&searchResult.length>0?<div className={style['result']}>
  149. <p className={style['title']}>搜索内容</p>
  150. <ul ref={this.$ul}>
  151. {this.getSearchList()}
  152. </ul>
  153. </div>:<p className={style['no-data']}>{hasSearch?'搜索中...':msg}</p>}
  154. </div>
  155. )
  156. }
  157. }
  158. export default MedicalInfo;