Bladeren bron

诊断延迟搜索

zhouna 6 jaren geleden
bovenliggende
commit
bfad6c4041
2 gewijzigde bestanden met toevoegingen van 15 en 6 verwijderingen
  1. 14 5
      src/components/DiagResultSearch/index.jsx
  2. 1 1
      src/components/PreviewBody/index.jsx

+ 14 - 5
src/components/DiagResultSearch/index.jsx

@@ -3,13 +3,15 @@ import style from './index.less';
 import close from './img/close.png'
 import search from './img/search.png'
 import DiagnosticItem from '@containers/DiagnosticItem'
+import config from '@config/index';
 import $ from 'jquery';
 class DiagResultSearch extends Component {
     constructor(props) {
         super(props);
         this.state = {
             showClose: false,
-            focus: true
+            focus: true,
+            timer:null
         };
         this.searchInput = React.createRef();
         this.handleInput = this.handleInput.bind(this);
@@ -54,10 +56,17 @@ class DiagResultSearch extends Component {
     handleInput(value) {
         const {  setSearchValue, getSearchResult } = this.props;
         value.length > 0 ? this.setState({showClose: true}) : this.setState({showClose: false});
-        if(value.trim() == ''){
-          return  getSearchResult('');
-        }
-        getSearchResult(value.trim());
+        clearTimeout(this.state.timer);
+        let timer = setTimeout(()=>{
+            clearTimeout(this.state.timer);
+          if(value.trim() == ''){
+            return  getSearchResult('');
+          }
+          getSearchResult(value.trim());
+        },config.delayTime);
+        this.setState({
+          timer
+        });
     }
     clearInput() {
         const {  setSearchValue, getSearchResult } = this.props;

+ 1 - 1
src/components/PreviewBody/index.jsx

@@ -108,7 +108,7 @@ class PreviewBody extends Component {
     render() {
         const { show, preInfo, dataJson, dataStr,baseObj } = this.props;
         const infoNull = JSON.stringify(preInfo) == '{}';
-        console.log(dataStr,baseObj)
+
         return <div className={style['content']}>
             <div className={style['contents']} id="content" style={{margin:"0 auto"}}>
                 <div ref={this.$content} className={style['hisName']}>{preInfo.hospitalName}</div>