index.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. this.handleEnter = this.handleEnter.bind(this);
  17. }
  18. getResult(id){
  19. const {formulaResult} = this.props;
  20. const scale=formulaResult&&formulaResult[id];
  21. let result = scale&&scale.calcalculate?scale.calcalculate.result:null;
  22. if(result){
  23. return <i>( 结果:{result.value} {result.text} )</i>;
  24. }
  25. return '';
  26. }
  27. showScale(item){
  28. const {scaleInfo,getScale,showScaleFn} = this.props;
  29. if(scaleInfo&&scaleInfo[item.id]){
  30. showScaleFn&&showScaleFn(item);
  31. }else{
  32. getScale(item);
  33. }
  34. }
  35. getSearchList() {
  36. const { searchResult } = this.props;
  37. return searchResult && searchResult.map((item) => {
  38. return <li key={item.conceptId} onClick={this.showScale.bind(this,{id:item.conceptId,name:item.name})}>
  39. <span className={style['scale-name']}>{item.name}{this.getResult(item.conceptId)}</span>
  40. <button>查看</button>
  41. </li>;
  42. });
  43. }
  44. search(){
  45. const {handleChangeValue} = this.props;
  46. const val = this.$inp.current.value;
  47. handleChangeValue&&handleChangeValue(val);
  48. }
  49. handleChange(){
  50. this.setState({
  51. val:this.$inp.current.value
  52. });
  53. }
  54. handleEnter(e){
  55. if(e.keyCode==13){
  56. this.search();
  57. }
  58. }
  59. clear(){
  60. const {clearResult} = this.props;
  61. this.$inp.current.value = '';
  62. this.setState({
  63. val:''
  64. });
  65. clearResult&&clearResult();
  66. }
  67. componentDidMount(){
  68. const height = getWindowInnerHeight()-170;
  69. this.$cont.current.style.height = height+"px";
  70. if(this.$cont.current){
  71. windowEventHandler('resize', ()=>{
  72. const height = getWindowInnerHeight()-170;
  73. this.$cont.current.style.height = height+"px";
  74. });
  75. }
  76. }
  77. render() {
  78. const {searchResult} = this.props;
  79. const {val} = this.state;
  80. return (
  81. <div className={style['search-cont']} ref={this.$cont}>
  82. <div className={style['search-box']}>
  83. <p className={style['title']}>量表搜索</p>
  84. <p className={style['cont']}>
  85. <input type="text" className={style['input']} ref={this.$inp} onInput={this.handleChange} onKeyUp={this.handleEnter}/>
  86. {val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  87. <button onClick={this.search}>搜索</button>
  88. </p>
  89. </div>
  90. {searchResult&&searchResult.length>0?<div className={style['result']}>
  91. <p className={style['title']}>查询内容</p>
  92. <ul>
  93. {this.getSearchList()}
  94. </ul>
  95. </div>:<p className={style['no-data']}>暂无搜索结果!</p>}
  96. </div>
  97. )
  98. }
  99. }
  100. export default ScaleSearch;