index.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 rePushIcon from '../../common/images/icon2.png';
  11. import config from '@config/index';
  12. class CheckBody extends Component{
  13. constructor(props){
  14. super(props);
  15. this.state={
  16. boxMark:'4',
  17. boxLeft:0,
  18. boxTop:0,
  19. showAll:false
  20. };
  21. this.handleClick = this.handleClick.bind(this);
  22. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  23. this.getData = this.getData.bind(this);
  24. this.showHide = this.showHide.bind(this);
  25. //this.handleInput = this.handleInput.bind(this);
  26. }
  27. componentWillReceiveProps(next){
  28. if((this.props.defaultShowAll&&!next.defaultShowAll)||(!this.props.defaultShowAll&&next.defaultShowAll)||(!this.props.isEmpty&&next.isEmpty)){
  29. this.setState({
  30. showAll:next.defaultShowAll
  31. })
  32. }
  33. }
  34. isThereHigh(arr,ids){
  35. if(!arr||!ids){
  36. return false;
  37. }
  38. const item = arr.find((it)=>{
  39. return ids.includes(it.id);
  40. });
  41. if(item){
  42. return true;
  43. }
  44. return false;
  45. }
  46. getLabels(){
  47. const {data,showArr,saveText,importLabel,setHighter} = this.props;
  48. let arr = [],list=[];
  49. const {boxMark,showAll} = this.state;
  50. const moreNum =data.length-[...data].reverse().findIndex((it)=>it.showInCheck)-1;//被隐藏的位置
  51. const moreText = filterDataArr([...saveText].splice(moreNum+1)); //被收起的标签中是否有有值得,有则不能再收起showMoreBtn?more:''
  52. const hasHigh = this.isThereHigh([...data].splice(moreNum+1),importLabel); //隐藏的标签中是否有高亮的
  53. 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>;
  54. const showMoreBtn = data.length>config.showCheckNum&&(data.length-1>moreNum&&!data[0].full)&&!moreText&&!hasHigh;
  55. let showArray = data.filter((it)=>{
  56. if(it.showInCheck)
  57. return it;
  58. });
  59. const showData = moreText||hasHigh||showAll?[...data]:showArray;//[...data].splice(0,config.showCheckNum*2+1);
  60. if(showData){
  61. list = showData;
  62. arr = list.map((it,i)=>{
  63. const preIsExt = list[i-1]&&list[i-1].specFlag===4?true:false;//前一个标签是否为体征标签
  64. const afterIsExt = list[i+1]&&list[i+1].specFlag===4?true:false;//后一个标签是否为体征标签
  65. return chooseType({item:it,preIsExt,afterIsExt,boxMark,i,showArr,saveText,importLabel,setHighter});
  66. });
  67. }
  68. showMoreBtn&&arr.push(more); //是否显示收起展开按钮
  69. return arr;
  70. }
  71. handleClick(e){//让搜索框跟随鼠标点击移动
  72. // e.stopPropagation();
  73. const {totalHide,getSearchLocation} = this.props;
  74. this.getData();
  75. if(totalHide){
  76. return ;
  77. }
  78. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  79. //搜索框位置
  80. const ele = document.activeElement;
  81. const height = ele.offsetHeight;
  82. let boxTop = (+(ele.offsetTop)+height);
  83. let boxLeft = ele.offsetLeft;
  84. this.setState({
  85. boxLeft:boxLeft,
  86. boxTop:boxTop
  87. });
  88. }
  89. handleSearchSelect(obj){
  90. const {questionId,name} = obj;
  91. const {fetchModules,focusTextIndex,span,searchInEnd} = this.props;
  92. fetchModules&&fetchModules({id:questionId,index:focusTextIndex,name,span,searchInEnd});
  93. }
  94. getData(){
  95. //第一次聚焦查体时,主诉有数据则调接口,主诉无数据则显示提示;其他时间查体模板数据不调接口
  96. const {hasMain,isEmpty} = this.props;
  97. if(!hasMain&&isEmpty){
  98. Notify.error("无法操作,请先输入主诉");
  99. return;
  100. }
  101. //无主诉提示在EditableSpan里
  102. //有主诉时且本身无数据,第一次点击获取数据,(不论获取成功与否)再点击不获取(直到刷新成空白页或清空)
  103. if(hasMain&&isEmpty!=false){
  104. this.props.getInit();
  105. }
  106. }
  107. showHide(){
  108. this.setState({
  109. showAll:!this.state.showAll
  110. });
  111. }
  112. render(){
  113. const {searchData,totalHide,rePush,hasMain,isEmpty,isChronic} = this.props;
  114. const {boxLeft,boxTop} = this.state;
  115. return <ItemBox title='查体' handleClick={this.handleClick}>
  116. {!isEmpty&&!isChronic?<img className={style['refresh']} src={rePushIcon} title='重新加载' onClick={!hasMain&&isEmpty?null:rePush}/>:''}
  117. {this.getLabels()}
  118. {/*{showMoreBtn?more:''}*/}
  119. {searchData && searchData.length>0?<SearchDrop data={searchData} show={!totalHide} left={boxLeft} top={boxTop} onSelect={this.handleSearchSelect}></SearchDrop>:''}
  120. </ItemBox>
  121. }
  122. }
  123. CheckBody.contextTypes = {
  124. scrollArea: React.PropTypes.object
  125. };
  126. export default CheckBody;