index.jsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React,{Component} from 'react';
  2. import style from './index.less';
  3. import {Button,InlineTag,ItemBox,EditableSpan,Notify} from '@commonComp';
  4. import chooseType from '@containers/eleType.js';
  5. import SearchDrop from '@components/SearchDrop';
  6. class CheckBody extends Component{
  7. constructor(props){
  8. super(props);
  9. this.state={
  10. boxMark:'4',
  11. boxLeft:'0px',
  12. boxTop:'0px'
  13. };
  14. this.handleClick = this.handleClick.bind(this);
  15. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  16. this.getData = this.getData.bind(this);
  17. //this.handleInput = this.handleInput.bind(this);
  18. }
  19. getLabels(){
  20. const {data,showArr,saveText,selecteds} = this.props;
  21. let arr = [],list=[];
  22. const {boxMark} = this.state;
  23. if(data){
  24. list = data;
  25. arr = list.map((it,i)=>{
  26. return chooseType({item:it,boxMark,i,showArr,saveText,selecteds});
  27. });
  28. }
  29. return arr;
  30. }
  31. handleClick(e){//让搜索框跟随鼠标点击移动
  32. //e.stopPropagation();
  33. const {fetchPushInfos,totalHide} = this.props;
  34. //fetchPushInfos&&fetchPushInfos();
  35. this.getData();
  36. if(totalHide){
  37. return ;
  38. }
  39. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  40. const ele = document.activeElement;
  41. const height = ele.offsetHeight;
  42. let boxTop = (+(ele.offsetTop)+height)+'px';
  43. let boxLeft = ele.offsetLeft + 'px';
  44. this.setState({
  45. boxLeft:boxLeft,
  46. boxTop:boxTop
  47. });
  48. }
  49. handleSearchSelect(obj){
  50. const {questionId,name} = obj;
  51. const {fetchModules,focusTextIndex,span,searchInEnd} = this.props;
  52. fetchModules&&fetchModules({id:questionId,index:focusTextIndex,name,span,searchInEnd});
  53. }
  54. getData(){
  55. //第一次聚焦查体时,主诉有数据则调接口,主诉无数据则显示提示;其他时间查体模板数据不调接口
  56. const {hasMain,saveText,data,isEmpty} = this.props;
  57. const hasData = saveText.join("")||data.length>0;
  58. if(!hasMain&&isEmpty){ //无主诉且本身无数据时,点击提示(空白页、清空)
  59. Notify.error("无法操作,请先输入主诉");
  60. return ;
  61. }
  62. //有主诉时且本身无数据,第一次点击获取数据,(不论获取成功与否)再点击不获取(直到刷新成空白页或清空)
  63. if(hasMain&&isEmpty!=false){
  64. this.props.getInit();
  65. }
  66. }
  67. render(){
  68. const {searchData,totalHide,data} = this.props;
  69. const {boxLeft,boxTop,boxMark} = this.state;
  70. return <div className={style['container']}>
  71. <ItemBox title='查体' handleClick={this.handleClick}>
  72. {this.getLabels()}
  73. {searchData && searchData.length>0?<SearchDrop data={searchData} show={!totalHide} left={boxLeft} top={boxTop} onSelect={this.handleSearchSelect}></SearchDrop>:''}
  74. </ItemBox>
  75. </div>
  76. }
  77. }
  78. export default CheckBody;