index.jsx 4.8 KB

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