index.jsx 9.5 KB

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