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 ScaleSearch extends Component { constructor(props) { super(props); this.$inp = React.createRef(); this.$cont = React.createRef(); this.$ul = 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.handleEnter = this.handleEnter.bind(this); } getResult(id){ const {formulaResult} = this.props; const scale=formulaResult&&formulaResult[id]; let result = scale&&scale.calcalculate?scale.calcalculate.result:null; if(result){ return ( 结果:{result.value} {result.text} ); } return ''; } showScale(item){ const {scaleInfo,getScale,showScaleFn} = this.props; if(scaleInfo&&scaleInfo[item.conceptId]){ showScaleFn&&showScaleFn(item); }else{ getScale(item); } } getSearchList() { const { searchResult } = this.props; const that = this; if(searchResult&&searchResult.length>0){ setTimeout(function(){ that.$ul.current.style.height = getWindowInnerHeight()-248+'px'; },100); } return searchResult && searchResult.map((item) => { return
  • {item.name}{this.getResult(item.conceptId)} {item.showType===0?

    • {item.searchName}

    :''} {/**/}
  • ; }); } 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:'' }); this.$inp.current.focus(); clearResult&&clearResult(); } componentDidMount(){ const height = getWindowInnerHeight()-148; this.$cont.current.style.height = height+"px"; windowEventHandler('resize', ()=>{ if(this.$cont.current){ const height = getWindowInnerHeight()-148; this.$cont.current.style.height = height+"px"; } if(this.$ul.current){ const height = getWindowInnerHeight()-248; this.$ul.current.style.height = height+"px"; } }); } componentWillReceiveProps(){ this.setState({ hasSearch: false }); } render() { const {searchResult} = this.props; const {val, hasSearch,msg} = this.state; return (

    {val?清空:''}

    {searchResult&&searchResult.length>0?

    搜索内容

    :

    {hasSearch?'搜索中...':msg}

    }
    ) } } export default ScaleSearch;