123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- import React, { Component } from 'react';
- import style from './index.less';
- import delIcon from '@common/images/del_nor.png';
- import {windowEventHandler,getCurrentDate,getWindowInnerHeight} from '@utils/tools'
- class MedicalInfo extends Component {
- constructor(props) {
- super(props);
- this.$inp = React.createRef();
- this.$cont = React.createRef();
- this.state={
- val:'',
- hasSearch: false,
- msg:''
- };
- this.search = this.search.bind(this);
- this.handleChange = this.handleChange.bind(this);
- this.clear = this.clear.bind(this);
- this.getSearchList = this.getSearchList.bind(this);
- this.handleEnter = this.handleEnter.bind(this);
- }
- getSearchList() {
- const { getAllConceptDetail,searchResult } = this.props;
- return searchResult && searchResult.map((item) => {
- return <li key={item.conceptId}
- title='点击查看详情'
- onClick={() =>getAllConceptDetail({name: item.name, type: item.type})}>
- <span>{item.name}</span>
- <i>( {item.libTypeName} )</i>
- {/*<button>查看</button>*/}
- </li>;
- });
- }
- search(){
- if(this.state.hasSearch === false) {
- this.setState({
- hasSearch: true,
- msg:'暂无搜索结果!'
- })
- }
- const {handleChangeValue} = this.props;
- const val = this.$inp.current.value;
- handleChangeValue&&handleChangeValue(val);
- }
- handleChange(){
- const value = this.$inp.current.value;
- const {clearResult} = this.props;
- this.setState({
- val: value
- });
- if (value === '') {
- this.setState({
- val: '',
- hasSearch: false,
- msg: ''
- });
- clearResult && clearResult();
- }
- }
- handleEnter(e){
- if(e.keyCode==13){
- this.search();
- }
- }
- clear(){
- const {clearResult} = this.props;
- this.$inp.current.value = '';
- this.setState({
- val:'',
- hasSearch: false,
- msg:''
- });
- clearResult&&clearResult();
- }
- componentDidMount(){
- const height = getWindowInnerHeight()-170;
- this.$cont.current.style.height = height+"px";
- if(this.$cont.current){
- windowEventHandler('resize', ()=>{
- const height = getWindowInnerHeight()-170;
- this.$cont.current.style.height = height+"px";
- });
- }
- }
- componentWillReceiveProps(){
- this.setState({
- hasSearch: false
- });
- }
- render() {
- const {searchResult} = this.props;
- const {val, hasSearch,msg} = this.state;
- return (
- <div className={style['search-cont']} ref={this.$cont}>
- <div className={style['search-box']}>
- <p className={style['title']}>医学知识搜索</p>
- <p className={style['cont']}>
- <input type="text" className={style['input']} ref={this.$inp} onInput={this.handleChange} onKeyUp={this.handleEnter}/>
- {val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
- <button onClick={this.search}>搜索</button>
- </p>
- </div>
- {searchResult&&searchResult.length>0?<div className={style['result']}>
- <p className={style['title']}>查询内容</p>
- <ul>
- {this.getSearchList()}
- </ul>
- </div>:<p className={style['no-data']}>{hasSearch?'搜索中...':msg}</p>}
- </div>
- )
-
-
- }
- }
- export default MedicalInfo;
|