index.jsx 11 KB

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