index.jsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import React,{Component} from 'react';
  2. import style from './index.less';
  3. import {Button,InlineTag,ItemBox,Notify,Textarea} from '@commonComp';
  4. import TailInlineTag from '@commonComp/TailInlineTag';
  5. import chooseType from '@containers/eleType.js';
  6. import SearchDrop from '@components/SearchDrop';
  7. import {filterDataArr,getPageCoordinate,windowEventHandler,isIE} from '@utils/tools'
  8. import $ from 'jquery';
  9. class CurrentIll extends Component{
  10. constructor(props){
  11. super(props);
  12. this.state = {
  13. boxEditable:true,
  14. showMoudle:false,
  15. forbidInput:false,
  16. mainFlag:true,
  17. mainData:[],
  18. boxMark:"2",
  19. boxLeft:0,
  20. boxTop:0,
  21. show:true,
  22. tmpScroll:0,
  23. tmpTop:0,
  24. setDataTimer:null
  25. }
  26. this.toggleEditable = this.toggleEditable.bind(this);
  27. this.handleFocus = this.handleFocus.bind(this);
  28. this.onchange = this.onchange.bind(this);
  29. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  30. this.handleClick = this.handleClick.bind(this);
  31. this.handleBlur = this.handleBlur.bind(this);
  32. }
  33. componentWillReceiveProps(nextProps){
  34. this.setState({boxLeft:nextProps.boxLeft})
  35. }
  36. toggleEditable(){
  37. this.setState({
  38. boxEditable:!this.state.boxEditable
  39. })
  40. }
  41. handleFocus(e){
  42. // 判断主诉是否为空
  43. const {mainData,mainText,setData,moduleNum,mainIds,data,changeEditIll,editClear,symptomFeature,isChronic} = this.props;
  44. const that = this;
  45. let {setDataTimer} = this.state;
  46. let mainFinallyText = filterDataArr(mainText);
  47. // if(mainData.length == 0 && !mainText[0]){
  48. if(!mainFinallyText){
  49. //弹窗提醒
  50. Notify.error("无法操作,请先输入主诉");
  51. this.setState({
  52. forbidInput:true
  53. })
  54. }else {
  55. let num = moduleNum.num;//主诉使用了几个模板
  56. // isChronic为一个对象
  57. if(data.length==0 && !isChronic || !isChronic.name ){
  58. clearTimeout(setDataTimer);
  59. setDataTimer = setTimeout(function(){//延时,等待主诉失焦数据返回
  60. setData && setData({num,mainData,mainIds,symptomFeature:symptomFeature.featureData,isChronic});
  61. },200)
  62. this.setState({
  63. setDataTimer
  64. })
  65. }
  66. this.setState({
  67. showMoudle:true,
  68. forbidInput:false,
  69. boxEditable:false,
  70. setDataTimer
  71. })
  72. changeEditIll(false)
  73. /*const showTimer = setTimeout(function(){
  74. that.setState({
  75. showMoudle:true,
  76. forbidInput:false,
  77. boxEditable:false,
  78. })
  79. changeEditIll(false)
  80. },150)
  81. clearTimeout(showTimer);*/
  82. }
  83. }
  84. onchange(e){//监听输入事件,主诉无数据不能输入
  85. const ev = e || window.event;
  86. ev.target.innerText?(ev.target.innerText = ""):(ev.target.innerHTML="");
  87. }
  88. handleClick(e){//让搜索框跟随鼠标点击移动
  89. // e.stopPropagation(); //冒泡到最顶层关闭其他下拉
  90. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  91. const {getSearchLocation} = this.props;
  92. let leftL=0; //用焦点元素的左边距替换鼠标点击的左边距,高度还是鼠标点击的位置
  93. if(isIE()){
  94. leftL = getPageCoordinate(e).boxLeft
  95. }else{
  96. const ele = document.activeElement;
  97. if(ele.toString().indexOf('HTMLSpanElement') == -1){ //点击的不是span无法聚焦就不再设置位置
  98. return;
  99. }
  100. leftL = ele.offsetLeft+90
  101. }
  102. // console.log(getPageCoordinate(e).boxTop)
  103. getSearchLocation(getPageCoordinate(e).boxTop,leftL)
  104. this.setState({
  105. // boxLeft:getPageCoordinate(e).boxLeft,
  106. // boxLeft:leftL,
  107. // boxTop:getPageCoordinate(e).boxTop,
  108. tmpScroll: $("#addScrollEvent")[0].scrollTop,
  109. tmpTop:getPageCoordinate(e).boxTop
  110. });
  111. windowEventHandler('scroll',()=>{ //弹窗跟随滚动条滚动或者关闭弹窗
  112. let scrollYs = $("#addScrollEvent")[0].scrollTop;
  113. let boxTop = this.state.tmpTop - scrollYs + this.state.tmpScroll
  114. getSearchLocation(boxTop,this.state.boxLeft)
  115. },$("#addScrollEvent")[0])
  116. }
  117. handleSearchSelect(obj){
  118. const {questionId,name} = obj;
  119. const {fetchModules,focusIndex,span} = this.props;
  120. fetchModules&&fetchModules({id:questionId,index:focusIndex,name,span});
  121. }
  122. getInlineTag(){
  123. const {data,showArr,selecteds,saveText,insertProcess,symptomIds,allModules} = this.props;
  124. const boxMark = '2';
  125. let list = data&&data.map((item,i)=>{
  126. if(item.flag && item.flag==3){
  127. return <TailInlineTag {...item} showText={item.relationModuleName} handleTailClick={(obj)=>{insertProcess(obj,allModules)}}></TailInlineTag>
  128. }else {
  129. return chooseType({item,boxMark,i,hideTag:false,showArr,selecteds,saveText,mainIds:symptomIds});
  130. }
  131. })
  132. return list;
  133. }
  134. handleBlur(e){
  135. const {freeText} = this.props;
  136. const ev = e || window.event;
  137. const data = ev.target.innerText || e.target.innerHTML;
  138. if(!isIE()){
  139. e.target.innerText?(e.target.innerText=""):(e.target.innerHTML="")
  140. freeText && freeText(data.trim());
  141. }else{
  142. if(datas.length==0){
  143. freeText && freeText(data);
  144. }
  145. }
  146. }
  147. render(){
  148. const {fuzhen,isChronic,type,fetchPushInfos,handleInput,isRead,saveText,searchData,totalHide,showArr,focusIndex,editClear,data,boxLeft,boxTop} = this.props;
  149. const {showMoudle,forbidInput,boxMark,show} = this.state;
  150. const searchFlag = searchData.length > 0 ? true : false;
  151. if(+type===1){ //文本模式
  152. return <Textarea title='现病史' boxMark='2'
  153. isRead={isRead}
  154. value={saveText[0]}
  155. fuzhen={fuzhen}
  156. isChronic={isChronic}
  157. handlePush={fetchPushInfos}
  158. handleInput={handleInput}/>;
  159. }
  160. return <div className={style['current-ill']}>
  161. <ItemBox title='现病史'
  162. editable={editClear||data.length==0?true:false}
  163. handleFocus={this.handleFocus}
  164. onchange={forbidInput?(e)=>{this.onchange(e)}:''}
  165. handleClick={this.handleClick}
  166. handleBlur={this.handleBlur}>
  167. {data.length>0?this.getInlineTag():(saveText[0]?saveText[0]:'')}
  168. </ItemBox>
  169. {searchFlag ? <SearchDrop data={searchData} show={!totalHide} onSelect={this.handleSearchSelect} left={boxLeft} top={boxTop} />:""}
  170. </div>
  171. }
  172. }
  173. export default CurrentIll;