index.jsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 ScaleSearch extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.$inp = React.createRef();
  9. this.$cont = React.createRef();
  10. this.state={
  11. val:''
  12. };
  13. this.search = this.search.bind(this);
  14. this.handleChange = this.handleChange.bind(this);
  15. this.clear = this.clear.bind(this);
  16. }
  17. getResult(id){
  18. const {formulaResult} = this.props;
  19. const scale=formulaResult&&formulaResult[id];
  20. let result = scale&&scale.calcalculate?scale.calcalculate.result:null;
  21. if(result){
  22. return <i>( 结果:{result.value} {result.text} )</i>;
  23. }
  24. return '';
  25. }
  26. getSearchList() {
  27. const { searchResult,getScale } = this.props;
  28. return searchResult && searchResult.map((item) => {
  29. return <li key={item.conceptId} onClick={()=>getScale({id:item.conceptId,name:item.name})}>
  30. <span className={style['scale-name']}>{item.name}</span>
  31. {this.getResult(item.conceptId)}
  32. <button>查看</button>
  33. </li>;
  34. });
  35. }
  36. search(){
  37. const {handleChangeValue} = this.props;
  38. const val = this.$inp.current.value;
  39. handleChangeValue&&handleChangeValue(val);
  40. }
  41. handleChange(){
  42. this.setState({
  43. val:this.$inp.current.value
  44. });
  45. }
  46. clear(){
  47. this.$inp.current.value = '';
  48. this.setState({
  49. val:''
  50. });
  51. }
  52. componentDidMount(){
  53. const height = getWindowInnerHeight()-170;
  54. this.$cont.current.style.height = height+"px";
  55. if(this.$cont.current){
  56. windowEventHandler('resize', ()=>{
  57. const height = getWindowInnerHeight()-170;
  58. this.$cont.current.style.height = height+"px";
  59. });
  60. }
  61. }
  62. render() {
  63. const {searchResult} = this.props;
  64. const {val} = this.state;
  65. return (
  66. <div className={style['mefical-info-wrapper']} ref={this.$cont}>
  67. <div className={style['search-cont']}>
  68. <p className={style['title']}>量表搜索</p>
  69. <p className={style['cont']}>
  70. <input type="text" className={style['input']} ref={this.$inp} onChange={this.handleChange}/>
  71. {val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  72. <button onClick={this.search}>搜索</button>
  73. </p>
  74. {searchResult&&searchResult.length>0?<div className={style['result']}>
  75. <p className={style['title']}>查询内容</p>
  76. <ul>
  77. {this.getSearchList()}
  78. </ul>
  79. </div>:<p className={style['no-data']}>暂无搜索结果!</p>}
  80. </div>
  81. </div>
  82. )
  83. }
  84. }
  85. export default ScaleSearch;