index.jsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import React,{Component} from 'react';
  2. import style from './index.less';
  3. import {Button,InlineTag,ItemBox,DropDown,DropList,Textarea,Notify} from '@commonComp';
  4. import TailInlineTag from '@commonComp/TailInlineTag';
  5. import SearchDrop from '@components/SearchDrop';
  6. import CommonSymptom from '@components/CommonSymptom';
  7. import chooseType from '@containers/eleType.js';
  8. import config from "@config/index";
  9. import {isIE,getPageCoordinate,windowEventHandler,filterDataArr} from "@utils/tools.js"
  10. import $ from 'jquery';
  11. class MainSuit extends Component{
  12. constructor(props){
  13. super(props);
  14. this.state = {
  15. boxEditable:true,
  16. show:false,
  17. showModule:false,
  18. inputData:"",
  19. boxLeft:null,
  20. boxTop:null,
  21. selecSearch:"",
  22. symptom:false,
  23. search:false,
  24. timer:null,
  25. blurTimer:null,
  26. inpText:'',
  27. clearTimer:null,
  28. overFlag:false,
  29. tmpScroll:0,
  30. tmpTop:0,
  31. };
  32. this.toggleEditable = this.toggleEditable.bind(this);
  33. this.handleFocus = this.handleFocus.bind(this);
  34. this.handleSelect = this.handleSelect.bind(this);
  35. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  36. this.handleChange = this.handleChange.bind(this);
  37. this.handleClick = this.handleClick.bind(this);
  38. this.handleBlur = this.handleBlur.bind(this);
  39. }
  40. componentWillReceiveProps(nextProps){
  41. this.setState({boxLeft:nextProps.boxLeft})
  42. }
  43. toggleEditable(){
  44. this.setState({
  45. boxEditable:!this.state.boxEditable
  46. })
  47. }
  48. getInlineTag(){
  49. const {datas,showArr,handleTailClick,selecteds,saveText,addModuleName,mainIds,allModules} = this.props;
  50. const boxMark = '1';
  51. let list = datas&&datas.map((item,i)=>{
  52. if(item.flag && item.flag==3){
  53. /*return <TailInlineTag {...item} showText={addModuleName} handleTailClick={(obj)=>{handleTailClick(obj,saveText)}}></TailInlineTag>*/
  54. return <TailInlineTag {...item} showText={item.relationModuleName} handleTailClick={(obj)=>{handleTailClick(obj,saveText,allModules)}}></TailInlineTag>
  55. }else {
  56. return chooseType({item,boxMark,i,hideTag:false,showArr,selecteds,saveText,mainIds});
  57. }
  58. })
  59. return list;
  60. }
  61. handleFocus(e){
  62. e.stopPropagation();
  63. const {getCommonSymptoms,datas,clearDiagnose} = this.props;
  64. let innerText = e.target.innerText || e.target.innerHTML;//兼容火狐43
  65. clearDiagnose&&clearDiagnose();//清除复诊数据
  66. if(!isIE()){//IE会触发onfocus和onblur事件
  67. if(!innerText.trim()){//有内容就走搜索接口
  68. getCommonSymptoms && getCommonSymptoms();
  69. this.setState({
  70. symptom:true,
  71. inpText:innerText
  72. })
  73. }else{
  74. this.setState({
  75. symptom:false,
  76. inpText:innerText
  77. })
  78. }
  79. }else{
  80. if(datas.length==0 && !innerText.trim()){
  81. getCommonSymptoms && getCommonSymptoms();
  82. this.setState({
  83. symptom:true
  84. })
  85. }
  86. }
  87. }
  88. /*handleShow(e,show){
  89. e.stopPropagation();
  90. if(e.target.tagName=="INPUT"){
  91. return ;
  92. }
  93. }*/
  94. handleSelect(item){//选中的常见症状
  95. if(item.select.length>0){
  96. const {clearCommS,insertMain,getData} = this.props;
  97. // 获取主诉模板
  98. getData && getData();
  99. // 让模板出现
  100. this.setState({
  101. showModule:true,
  102. symptom: false,
  103. })
  104. //选中后清空下拉结果
  105. insertMain && insertMain(item);
  106. clearCommS && clearCommS();
  107. }else{//没有选中点确定-关闭
  108. this.setState({
  109. symptom: false
  110. })
  111. }
  112. }
  113. handleSearchSelect(item){
  114. const {clearSearch,insertSearch,datas,span,saveText} = this.props;
  115. let mainText = filterDataArr(saveText);//主诉字数
  116. const itemL = item.name.length;
  117. let lengths = mainText.length + itemL;
  118. if(lengths>config.limited){
  119. Notify.info(config.limitText);
  120. clearSearch && clearSearch();
  121. return
  122. }
  123. // clearTimeout(this.state.timer);
  124. if(datas.length==0){//没有使用模板时点击搜索结构要展开模板
  125. insertSearch &&insertSearch({item,span});
  126. this.setState({
  127. search: false,
  128. showModule:true,
  129. inpText:''
  130. })
  131. }else{
  132. insertSearch &&insertSearch({item,span});
  133. this.setState({
  134. search: false,
  135. })
  136. }
  137. // 清空搜索结果
  138. clearSearch && clearSearch();
  139. }
  140. handleClick(e){//让搜索框跟随鼠标点击移动
  141. // e.stopPropagation(); //冒泡到最顶层关闭其他下拉
  142. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  143. const {getSearchLocation} = this.props;
  144. let leftL=0; //用焦点元素的左边距替换鼠标点击的左边距,高度还是鼠标点击的位置
  145. let num = this.props.datas.length == 0?0:60
  146. if(isIE()){
  147. leftL = getPageCoordinate(e).boxLeft
  148. }else{
  149. const ele = document.activeElement;
  150. leftL = ele.offsetLeft+num
  151. }
  152. getSearchLocation(getPageCoordinate(e).boxTop,leftL)
  153. this.setState({
  154. // boxLeft:getPageCoordinate(e).boxLeft,
  155. // boxLeft:leftL,
  156. // boxTop:getPageCoordinate(e).boxTop,
  157. tmpScroll: $("#addScrollEvent")[0].scrollTop,
  158. tmpTop:getPageCoordinate(e).boxTop
  159. });
  160. windowEventHandler('scroll',()=>{ //弹窗跟随滚动条滚动或者关闭弹窗
  161. let scrollYs = $("#addScrollEvent")[0].scrollTop;
  162. let boxTop = this.state.tmpTop - scrollYs + this.state.tmpScroll
  163. getSearchLocation(boxTop,this.state.boxLeft)
  164. },$("#addScrollEvent")[0])
  165. }
  166. handleChange(e){
  167. const ev = e || window.event;
  168. const data = ev.target.innerText || ev.target.innerHTML;
  169. const {getSearchData,searchData,datas,pushMessage,reTotalHide,saveText} = this.props;
  170. const {overFlag,inpText} = this.state;
  171. reTotalHide && reTotalHide();//重置homePage中的控制项
  172. const that = this;
  173. if(data&&data.length > config.limited){
  174. Notify.info(config.limitText);
  175. if(overFlag){
  176. ev.target.innerText?(ev.target.innerText = inpText) : (ev.target.innerHTML = inpText);
  177. ev.target.blur();
  178. return
  179. }
  180. ev.target.innerText?(ev.target.innerText = data.substr(0,config.limited)):(ev.target.innerHTML = data.substr(0,config.limited)); //输入法内输入多个字再按enter的情况
  181. ev.target.blur();
  182. this.setState({
  183. inpText:data.substr(0,config.limited),
  184. overFlag:true
  185. })
  186. return false;
  187. }
  188. this.setState({
  189. inpText:data,
  190. overFlag:false
  191. })
  192. if(datas && datas.length > 0){//使用模板
  193. return false;
  194. }
  195. // 有输入内容或搜索结果时关闭,否则显示
  196. if(data && data.trim()||searchData.length>0){
  197. this.setState({
  198. symptom:false
  199. })
  200. }else{
  201. this.setState({
  202. symptom:true
  203. })
  204. }
  205. clearTimeout(this.state.timer);
  206. const timer = setTimeout(function(){
  207. pushMessage && pushMessage(data);
  208. //调搜索接口 使用模板走EditableSpan里的搜索方法
  209. getSearchData && getSearchData({inpStr:data,boxMark:1,itemType:0});
  210. },config.delayTime);
  211. this.setState({
  212. timer
  213. });
  214. }
  215. handleBlur(e){//隐藏常见症状下拉、存自由输入的值
  216. const {freeText,saveText,datas,clearSearch,getSymptomFeature,currentData} = this.props;
  217. const that = this;
  218. let data = this.state.inpText;
  219. if(!isIE()){
  220. if(currentData&&currentData.length==0){//现病史没有模板的时候才去获取
  221. getSymptomFeature && getSymptomFeature(e.target.innerText);
  222. }
  223. e.target.innerText?(e.target.innerText=""):(e.target.innerHTML="")
  224. freeText && freeText(data.trim());
  225. }else{
  226. if(datas.length==0){
  227. const ev = e || window.event;
  228. const data = ev.target.innerText;
  229. // freeText && freeText(data.trim());
  230. freeText && freeText(data);
  231. }
  232. }
  233. // 延时关闭常见症状下拉、清空搜索结果,不延时会影响选中
  234. const clearTimer = setTimeout(function(){
  235. clearSearch && clearSearch();
  236. clearTimeout(clearTimer);
  237. // that.setState({
  238. // symptom:false
  239. // })
  240. },config.delayTime-200);
  241. }
  242. render(){
  243. const {type,CommonSymptoms,searchData,fetchPushInfos,isRead,totalHide,handleInput,fuzhen,saveText,editClear,datas,commSymHide,boxLeft,boxTop} = this.props;
  244. const {showModule,show,symptom,search} = this.state;
  245. const symptomFlag = CommonSymptoms.length>0 ? true : false;
  246. const searchFlag = searchData.length>0 ? true : false;
  247. const boxTop1 = datas.length>0?boxTop:45;
  248. const boxLeft1 = datas.length>0?boxLeft:85;
  249. if(+type===1){ //文本模式
  250. return <Textarea title='主诉' boxMark='1' isRead={isRead} value={saveText[0]} handlePush={fetchPushInfos} handleInput={handleInput} />;
  251. }
  252. return <div className={`${'mainsuit-box'} ${style['main-suit']}`} id="mainsuitBox">
  253. <ItemBox
  254. fuzhen={fuzhen}
  255. title='主诉'
  256. editable={editClear||datas.length==0?true:false}
  257. boxLineHeight="24px"
  258. handleFocus={this.handleFocus}
  259. onchange={(e)=>{this.handleChange(e)}}
  260. handleClick={this.handleClick}
  261. handleBlur={this.handleBlur}
  262. data={datas}
  263. boxId="mainSuit">
  264. {datas.length>0?<div style={{display:'inline-block'}}>{this.getInlineTag()}</div>:(saveText[0]?saveText[0]:'')}
  265. </ItemBox>
  266. {/*没有推送结果就不显示*/}
  267. {symptomFlag && !searchFlag ? <CommonSymptom data={CommonSymptoms} show={!totalHide&&symptom} onSelect={this.handleSelect} /> : ( searchFlag ? <SearchDrop data={searchData} show={!commSymHide} onSelect={this.handleSearchSelect} left={boxLeft1} top={boxTop1} mainEmpty={datas.length==0?true:false}/>:"")}
  268. </div>
  269. }
  270. }
  271. export default MainSuit;