index.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import React,{Component} from 'react';
  2. import style from './index.less';
  3. import {Button,InlineTag,ItemBox,DropDown,DropList,Textarea,Notify,ConfirmModal} 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,getAllDataList,getAllDataStringList,ifOtherClear} from "@utils/tools.js"
  10. import { initItemList } from '@store/async-actions/historyTemplates';
  11. import tableIcon from '@common/images/table.png';
  12. import iconRadioDefault from '@common/images/icon-radio-default.png'
  13. import iconRadioActive from '@common/images/icon-radio-active.png'
  14. import { pushAllDataList } from '@utils/tools';
  15. import $ from 'jquery';
  16. import store from '@store';
  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. activeHistory: -1,
  38. showHistoryCase:false
  39. };
  40. this.toggleEditable = this.toggleEditable.bind(this);
  41. this.handleFocus = this.handleFocus.bind(this);
  42. this.handleSelect = this.handleSelect.bind(this);
  43. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  44. this.handleChange = this.handleChange.bind(this);
  45. this.handleClick = this.handleClick.bind(this);
  46. this.handleBlur = this.handleBlur.bind(this);
  47. this.referRecord = this.referRecord.bind(this);
  48. this.noReferRecord = this.noReferRecord.bind(this);
  49. this.referCase = this.referCase.bind(this);
  50. this.closeHistoryCaseModal = this.closeHistoryCaseModal.bind(this);
  51. this.handleQuoteClick = this.handleQuoteClick.bind(this);
  52. }
  53. componentWillReceiveProps(nextProps){
  54. this.setState({boxLeft:nextProps.boxLeft})
  55. }
  56. toggleEditable(){
  57. this.setState({
  58. boxEditable:!this.state.boxEditable
  59. })
  60. }
  61. getInlineTag(){
  62. const {datas,showArr,handleTailClick,selecteds,saveText,addModuleName,mainIds,allModules} = this.props;
  63. const boxMark = '1';
  64. let list = datas&&datas.map((item,i)=>{
  65. if(item.flag && item.flag==3){
  66. /*return <TailInlineTag {...item} showText={addModuleName} handleTailClick={(obj)=>{handleTailClick(obj,saveText)}}></TailInlineTag>*/
  67. return <TailInlineTag {...item} showText={item.relationModuleName} handleTailClick={(obj)=>{handleTailClick(obj,saveText,allModules)}}></TailInlineTag>
  68. }else {
  69. return chooseType({item,boxMark,i,hideTag:false,showArr,selecteds,saveText,mainIds});
  70. }
  71. })
  72. return list;
  73. }
  74. handleFocus(e){
  75. e.stopPropagation();
  76. const {getCommonSymptoms,datas,clearDiagnose} = this.props;
  77. let innerText = e.target.innerText || e.target.innerHTML;//兼容火狐43
  78. clearDiagnose&&clearDiagnose();//清除复诊数据
  79. if(!isIE()){//IE会触发onfocus和onblur事件
  80. if(!innerText.trim()){//有内容就走搜索接口
  81. getCommonSymptoms && getCommonSymptoms();
  82. this.setState({
  83. symptom:true,
  84. inpText:innerText
  85. })
  86. }else{
  87. this.setState({
  88. symptom:false,
  89. inpText:innerText
  90. })
  91. }
  92. }else{
  93. if(datas.length==0 && !innerText.trim()){
  94. getCommonSymptoms && getCommonSymptoms();
  95. this.setState({
  96. symptom:true
  97. })
  98. }
  99. }
  100. }
  101. /*handleShow(e,show){
  102. e.stopPropagation();
  103. if(e.target.tagName=="INPUT"){
  104. return ;
  105. }
  106. }*/
  107. handleSelect(item){//选中的常见症状
  108. if(item.select.length>0){
  109. const {clearCommS,insertMain,getData} = this.props;
  110. // 获取主诉模板
  111. getData && getData();
  112. // 让模板出现
  113. this.setState({
  114. showModule:true,
  115. symptom: false,
  116. })
  117. //选中后清空下拉结果
  118. insertMain && insertMain(item);
  119. clearCommS && clearCommS();
  120. }else{//没有选中点确定-关闭
  121. this.setState({
  122. symptom: false
  123. })
  124. }
  125. }
  126. handleSearchSelect(item){
  127. const {clearSearch,insertSearch,datas,span,saveText} = this.props;
  128. let mainText = filterDataArr(saveText);//主诉字数
  129. const itemL = item.name.length;
  130. let lengths = mainText.length + itemL;
  131. if(lengths>config.limited){
  132. Notify.info(config.limitText);
  133. clearSearch && clearSearch();
  134. return
  135. }
  136. // clearTimeout(this.state.timer);
  137. if(datas.length==0){//没有使用模板时点击搜索结构要展开模板
  138. insertSearch &&insertSearch({item,span});
  139. this.setState({
  140. search: false,
  141. showModule:true,
  142. inpText:''
  143. })
  144. }else{
  145. insertSearch &&insertSearch({item,span});
  146. this.setState({
  147. search: false,
  148. })
  149. }
  150. // 清空搜索结果
  151. clearSearch && clearSearch();
  152. }
  153. handleClick(e){//让搜索框跟随鼠标点击移动
  154. // e.stopPropagation(); //冒泡到最顶层关闭其他下拉
  155. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  156. const {getSearchLocation} = this.props;
  157. let leftL=0; //用焦点元素的左边距替换鼠标点击的左边距,高度还是鼠标点击的位置
  158. let num = this.props.datas.length == 0?0:60
  159. if(isIE()){
  160. leftL = getPageCoordinate(e).boxLeft
  161. }else{
  162. const ele = document.activeElement;
  163. leftL = ele.offsetLeft+num
  164. }
  165. getSearchLocation(getPageCoordinate(e).boxTop,leftL)
  166. this.setState({
  167. // boxLeft:getPageCoordinate(e).boxLeft,
  168. // boxLeft:leftL,
  169. // boxTop:getPageCoordinate(e).boxTop,
  170. tmpScroll: $("#addScrollEvent")[0].scrollTop,
  171. tmpTop:getPageCoordinate(e).boxTop
  172. });
  173. windowEventHandler('scroll',()=>{ //弹窗跟随滚动条滚动或者关闭弹窗
  174. let scrollYs = $("#addScrollEvent")[0].scrollTop;
  175. let boxTop = this.state.tmpTop - scrollYs + this.state.tmpScroll
  176. getSearchLocation(boxTop,this.state.boxLeft)
  177. },$("#addScrollEvent")[0])
  178. }
  179. handleChange(e){
  180. const ev = e || window.event;
  181. const data = ev.target.innerText || ev.target.innerHTML;
  182. const {getSearchData,searchData,datas,pushMessage,reTotalHide,saveText} = this.props;
  183. const {overFlag,inpText} = this.state;
  184. reTotalHide && reTotalHide();//重置homePage中的控制项
  185. const that = this;
  186. if(data&&data.length > config.limited){
  187. Notify.info(config.limitText);
  188. if(overFlag){
  189. ev.target.innerText?(ev.target.innerText = inpText) : (ev.target.innerHTML = inpText);
  190. ev.target.blur();
  191. return
  192. }
  193. ev.target.innerText?(ev.target.innerText = data.substr(0,config.limited)):(ev.target.innerHTML = data.substr(0,config.limited)); //输入法内输入多个字再按enter的情况
  194. ev.target.blur();
  195. this.setState({
  196. inpText:data.substr(0,config.limited),
  197. overFlag:true
  198. })
  199. return false;
  200. }
  201. this.setState({
  202. inpText:data,
  203. overFlag:false
  204. })
  205. if(datas && datas.length > 0){//使用模板
  206. return false;
  207. }
  208. // 有输入内容或搜索结果时关闭,否则显示
  209. if(data && data.trim()||searchData.length>0){
  210. this.setState({
  211. symptom:false
  212. })
  213. }else{
  214. this.setState({
  215. symptom:true
  216. })
  217. }
  218. clearTimeout(this.state.timer);
  219. const timer = setTimeout(function(){
  220. pushMessage && pushMessage(data);
  221. //调搜索接口 使用模板走EditableSpan里的搜索方法
  222. getSearchData && getSearchData({inpStr:data,boxMark:1,itemType:0});
  223. },config.delayTime);
  224. this.setState({
  225. timer
  226. });
  227. }
  228. handleBlur(e){//隐藏常见症状下拉、存自由输入的值
  229. const {freeText,saveText,datas,clearSearch,getSymptomFeature,currentData,saveChronic} = this.props;
  230. const that = this;
  231. let data = this.state.inpText;
  232. if(!isIE()){
  233. if(currentData&&currentData.length==0){//现病史没有模板的时候才去获取
  234. getSymptomFeature && getSymptomFeature(e.target.innerText);
  235. }
  236. e.target.innerText?(e.target.innerText=""):(e.target.innerHTML="")
  237. freeText && freeText(data.trim());
  238. // 慢病模板获取:精确匹配"糖尿病复诊",储存慢病字段
  239. // 页面有模板数据 就不在请求
  240. let baseList = store.getState();
  241. let jsonData = getAllDataList(baseList);
  242. let jsonStr = getAllDataStringList(baseList);
  243. let flg = ifOtherClear(jsonData,jsonStr,baseList);//除主诉外 其他是否为空
  244. if(data.trim()=='糖尿病复诊' && !flg){
  245. saveChronic && saveChronic({name:'糖尿病',id:21773});
  246. }
  247. }else{
  248. if(datas.length==0){
  249. const ev = e || window.event;
  250. const data = ev.target.innerText;
  251. // freeText && freeText(data.trim());
  252. freeText && freeText(data);
  253. }
  254. }
  255. // 延时关闭常见症状下拉、清空搜索结果,不延时会影响选中
  256. const clearTimer = setTimeout(function(){
  257. clearSearch && clearSearch();
  258. clearTimeout(clearTimer);
  259. // that.setState({
  260. // symptom:false
  261. // })
  262. },config.delayTime-200);
  263. }
  264. // 慢病
  265. referRecord() {//是否引用历史病例弹窗--是
  266. const { chronicDesease,closeHisBox } = this.props
  267. closeHisBox&&closeHisBox();//关闭
  268. this.setState({
  269. showHistoryCase:true
  270. })
  271. store.dispatch(initItemList(chronicDesease));
  272. }
  273. noReferRecord() {//否
  274. const {closeHisBox,autoFillMoudles} = this.props;
  275. closeHisBox&&closeHisBox();
  276. // 不引用病例 -直接分发模板进行填充
  277. autoFillMoudles && autoFillMoudles()
  278. }
  279. referCase() {
  280. const { items ,pureSaveChronic} = this.props
  281. this.setState({
  282. showHistoryCase:false
  283. })
  284. if (this.state.activeHistory === -1) {
  285. return
  286. }
  287. // let baseList = store.getState();
  288. let baseObj = items[this.state.activeHistory];
  289. pushAllDataList(baseObj.sign,'push',baseObj,'history') //引用
  290. pureSaveChronic && pureSaveChronic({name:'糖尿病',id:21773}); //储存慢病疾病
  291. this.props.getBilling();
  292. this.setState({
  293. activeHistory: -1
  294. })
  295. }
  296. closeHistoryCaseModal() {//关闭病例列表
  297. const {autoFillMoudles} = this.props;
  298. this.setState({
  299. activeHistory: -1,
  300. showHistoryCase:false
  301. })
  302. // 不引用病例直接分发模板进行填充
  303. autoFillMoudles&&autoFillMoudles();
  304. }
  305. handleQuoteClick(item, index) {
  306. console.log('asadsd', item)
  307. this.setState({
  308. activeHistory: index
  309. })
  310. }
  311. getHistoryCase() {
  312. const { items } = this.props
  313. return (<div className={style['history-info']}>
  314. {items.map((item, index) => {
  315. return<div onClick={this.handleQuoteClick.bind(this, item, index)} style={this.state.activeHistory === index ? {color: '#abcdef'} : ''}>
  316. <img src={this.state.activeHistory === index ? iconRadioActive : iconRadioDefault}/>{item.diagnose}
  317. </div>
  318. })}
  319. </div>)
  320. }
  321. render(){
  322. const {type,CommonSymptoms,searchData,fetchPushInfos,isRead,totalHide,handleInput,fuzhen,saveText,editClear,datas,commSymHide,boxLeft,boxTop,showHisBox} = this.props;
  323. const {showModule,show,symptom,search,showHistoryCase} = this.state;
  324. const symptomFlag = CommonSymptoms.length>0 ? true : false;
  325. const searchFlag = searchData.length>0 ? true : false;
  326. const boxTop1 = datas.length>0?boxTop:45;
  327. const boxLeft1 = datas.length>0?boxLeft:85;
  328. if(+type===1){ //文本模式
  329. return <Textarea title='主诉' boxMark='1' isRead={isRead} value={saveText[0]} handlePush={fetchPushInfos} handleInput={handleInput} />;
  330. }
  331. return <div className={`${'mainsuit-box'} ${style['main-suit']}`} id="mainsuitBox">
  332. <ItemBox
  333. fuzhen={fuzhen}
  334. title='主诉'
  335. editable={editClear||datas.length==0?true:false}
  336. boxLineHeight="24px"
  337. handleFocus={this.handleFocus}
  338. onchange={(e)=>{this.handleChange(e)}}
  339. handleClick={this.handleClick}
  340. handleBlur={this.handleBlur}
  341. data={datas}
  342. boxId="mainSuit">
  343. {datas.length>0?<div style={{display:'inline-block'}}>{this.getInlineTag()}</div>:(saveText[0]?saveText[0]:'')}
  344. </ItemBox>
  345. {/*没有推送结果就不显示*/}
  346. {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}/>:"")}
  347. <ConfirmModal visible={showHisBox} okText='是' cancelText='否' confirm={this.referRecord} cancel={this.noReferRecord} close={this.noReferRecord}>
  348. <div className={style['confirm-info']}>是否引用往期病历</div>
  349. </ConfirmModal>
  350. <ConfirmModal visible={showHistoryCase} noFooter='true' title='请选择历史病历' close={this.closeHistoryCaseModal} titleBg="#DFEAFE" icon={tableIcon} height={300}>
  351. {this.getHistoryCase()}
  352. <div className={style['confirm-history']}><span className={style['confirm-history-btn']} onClick={this.referCase}>确定</span></div>
  353. </ConfirmModal>
  354. </div>
  355. }
  356. }
  357. export default MainSuit;