index.jsx 4.5 KB

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