index.jsx 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import {getPageCoordinate,windowEventHandler,isIE} from '@utils/tools';
  7. import $ from "jquery";
  8. class CheckBody extends Component{
  9. constructor(props){
  10. super(props);
  11. this.state={
  12. boxMark:'4',
  13. boxLeft:0,
  14. boxTop:0,
  15. tmpScroll:0,
  16. tmpTop:0,
  17. };
  18. this.handleClick = this.handleClick.bind(this);
  19. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  20. this.getData = this.getData.bind(this);
  21. //this.handleInput = this.handleInput.bind(this);
  22. }
  23. getLabels(){
  24. const {data,showArr,saveText,selecteds} = this.props;
  25. let arr = [],list=[];
  26. const {boxMark} = this.state;
  27. if(data){
  28. list = data;
  29. arr = list.map((it,i)=>{
  30. return chooseType({item:it,boxMark,i,showArr,saveText,selecteds});
  31. });
  32. }
  33. return arr;
  34. }
  35. handleClick(e){//让搜索框跟随鼠标点击移动
  36. // e.stopPropagation();
  37. const {fetchPushInfos,totalHide} = this.props;
  38. //fetchPushInfos&&fetchPushInfos();
  39. this.getData();
  40. if(totalHide){
  41. return ;
  42. }
  43. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  44. let leftL=0; //用焦点元素的左边距替换鼠标点击的左边距,高度还是鼠标点击的位置
  45. if(isIE()){
  46. leftL = getPageCoordinate(e).boxLeft
  47. }else{
  48. const ele = document.activeElement;
  49. if(ele.toString().indexOf('HTMLSpanElement') == -1){ //点击的不是span无法聚焦就不再设置位置
  50. return;
  51. }
  52. leftL = ele.offsetLeft+90
  53. }
  54. // console.log(leftL,getPageCoordinate(e).boxLeft)
  55. this.setState({
  56. // boxLeft:getPageCoordinate(e).boxLeft,
  57. boxLeft:leftL,
  58. boxTop:getPageCoordinate(e).boxTop,
  59. tmpScroll: $("#addScrollEvent")[0].scrollTop,
  60. tmpTop:getPageCoordinate(e).boxTop
  61. });
  62. windowEventHandler('scroll',()=>{ //弹窗跟随滚动条滚动或者关闭弹窗
  63. let scrollYs = $("#addScrollEvent")[0].scrollTop;
  64. this.setState({
  65. boxTop:this.state.tmpTop - scrollYs + this.state.tmpScroll
  66. })
  67. },$("#addScrollEvent")[0])
  68. }
  69. handleSearchSelect(obj){
  70. const {questionId,name} = obj;
  71. const {fetchModules,focusTextIndex,span,searchInEnd} = this.props;
  72. fetchModules&&fetchModules({id:questionId,index:focusTextIndex,name,span,searchInEnd});
  73. }
  74. getData(){
  75. //第一次聚焦查体时,主诉有数据则调接口,主诉无数据则显示提示;其他时间查体模板数据不调接口
  76. const {hasMain,isEmpty} = this.props;
  77. //无主诉提示在EditableSpan里
  78. //有主诉时且本身无数据,第一次点击获取数据,(不论获取成功与否)再点击不获取(直到刷新成空白页或清空)
  79. if(hasMain&&isEmpty!=false){
  80. this.props.getInit();
  81. }
  82. }
  83. render(){
  84. const {searchData,totalHide,data} = this.props;
  85. const {boxLeft,boxTop,boxMark} = this.state;
  86. return <div className={style['container']}>
  87. <ItemBox title='查体' handleClick={this.handleClick}>
  88. {this.getLabels()}
  89. {searchData && searchData.length>0?<SearchDrop data={searchData} show={!totalHide} left={boxLeft} top={boxTop} onSelect={this.handleSearchSelect}></SearchDrop>:''}
  90. </ItemBox>
  91. </div>
  92. }
  93. }
  94. export default CheckBody;