SpreadDrop.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. import React ,{Component} from 'react';
  2. import {connect} from 'react-redux';
  3. import SpreadDrop from '@components/SpreadDrop';
  4. import {SETSELECTED,CLEARSELECTED,CONFIRMSELECTED,SETOTHERCHECKBOX,CHANGEOTHERTEXTLABEL} from '@types/otherHistory';
  5. import {RESET,SETDROPSHOW,HIDEDROP,CLICKCOUNT,ISREAD} from '@store/types/homePage.js';
  6. import {getModules as fetchModules} from '@store/async-actions/fetchModules.js';
  7. import {getCommSymptomPush} from '@store/async-actions/mainSuit.js'
  8. import {GET_BIGDATAPUSH,MIX_CONFIRM,COMM_CONFIRM,CHANGE_LABELVAL} from '@store/types/mainSuit';
  9. import {SETCHECKBOX,CHANGECHECKTEXTLABEL,CHECKCONFIRMSELECTED} from '@types/checkBody';
  10. import {CURRENT_CONFIRM,SETMAINCHECKBOX,CURRENT_TEXT_LABEL,CURRENT_GET_BIGDATAPUSH} from '@types/currentIll';
  11. import {getLabelIndex,fullfillText,getIds} from '@common/js/func.js';
  12. import {billing} from '@store/async-actions/pushMessage';
  13. import {Notify} from '@commonComp';
  14. import {filterArr,didPushParamChange,filterDataArr} from '@utils/tools.js';
  15. import config from '@config/index.js';
  16. function mapStateToProps(state) {//console.log(state);
  17. return {
  18. mainSaveText:state.mainSuit.saveText,
  19. mainData:state.mainSuit.data,
  20. }
  21. }
  22. function getNames(data,order){//从exist withs 中获取name字段
  23. let nameData = "";
  24. if(+order===1){ //成文默认按点选顺序排序,指定textGenerate=1按从上到下从左到右排序
  25. data.sort(function(a,b){
  26. return a.listIndex-b.listIndex;
  27. });
  28. }
  29. data&&data.forEach((it,i)=>{
  30. nameData += it.name;
  31. });
  32. return nameData;
  33. }
  34. function addPoint(data,num){//给伴随添加顿号
  35. for(let i=num; i<data.length; i++){
  36. data[i].name = '、'+ data[i].name;
  37. }
  38. return data;
  39. }
  40. /***********************标签展开确定事件***************************/
  41. // 主诉--不用展开标签
  42. function mainSuitModule(dispatch,store,params){
  43. const {nones,exists,withs,exclusion,excluName,ban,mainSaveText,mainData} = params;
  44. let text = filterDataArr(mainSaveText);
  45. if(text.length >= config.limited){
  46. Notify.info(config.limitText);
  47. return
  48. }
  49. // 给主症状伴随添加exists字段
  50. if(exists.length>0){
  51. for(let k=0; k<exists.length; k++){
  52. exists[k].value=exists[k].name;
  53. exists[k].exist=1;
  54. }
  55. }
  56. if(withs.length>0){
  57. for(let n=0; n<withs.length; n++){
  58. withs[n].value=withs[n].name;
  59. withs[n].exist=2;
  60. }
  61. }
  62. // let existsName = getNames(exists);
  63. // let withsName = getNames(withs);
  64. const copExists = JSON.parse(JSON.stringify(exists));
  65. const copWiths = JSON.parse(JSON.stringify(withs));
  66. let banName = ban.name;
  67. const index = params.ikey;
  68. let ikey = getLabelIndex(index);
  69. let num = 0;
  70. let existNum = 0;
  71. let forwardId;
  72. let mainText;
  73. for(let n=ikey-1; n>0; n--){
  74. if(mainData[n].flag && mainData[n].flag==1){
  75. forwardId = n;
  76. continue;
  77. }
  78. }
  79. if(forwardId){
  80. mainText = mainSaveText.slice(forwardId,ikey);
  81. const mainSlice = mainData.slice(forwardId,ikey);
  82. let banIndex = mainText.indexOf('伴');
  83. if(banIndex==-1){
  84. num = 1;
  85. }
  86. // ikey前的data里没有exist=1的数据,则existNum=1
  87. if(exists.length>0){
  88. for(let i=0; i<mainSlice.length; i++){
  89. if(!mainSlice[i].exist && mainSlice[i].exist!==1){
  90. existNum = 1;
  91. continue;
  92. }
  93. }
  94. }
  95. }else{
  96. let banIndex = mainSaveText.indexOf("伴");
  97. if(banIndex==-1){
  98. num = 1;
  99. }
  100. }
  101. let withsName = getNames(addPoint(copWiths,num));
  102. let existsName = getNames(addPoint(copExists,existNum));
  103. let names;
  104. if(banName){
  105. names = existsName + banName + withsName;
  106. }else{
  107. names = existsName + withsName;
  108. }
  109. // num==0 说明有“伴”,减1;
  110. let lengths = num==0?text.length + names.length - 1:text.length + names.length;
  111. // console.log(5656,num,existNum,text,text.length,names,lengths);
  112. if(lengths > config.limited){
  113. Notify.info(config.limitText);
  114. return
  115. }
  116. // const index = params.ikey;
  117. // let ikey = getLabelIndex(index);
  118. dispatch({
  119. type: MIX_CONFIRM,
  120. data: {exists:exists,withs:withs,withsName:withsName,existsName:existsName,ikey,ban}
  121. });
  122. dispatch({ //自由文本标签数据更新
  123. type:ISREAD
  124. });
  125. dispatch({//隐藏下拉
  126. type:HIDEDROP
  127. })
  128. }
  129. // 现病史
  130. function currentIll(dispatch,store,params){
  131. const {nones,exists,withs,exclusion,excluName,ban,noneIds} = params;
  132. const index = params.ikey;
  133. let ikey = getLabelIndex(index);
  134. let existsId = exists && exists.length>0?getIds(exists):[];
  135. let withsId = withs && withs.length>0?getIds(withs):[];
  136. const ids = (existsId.concat(withsId)).join(",");
  137. let has = [],wes=[];
  138. //获取选中项目模板
  139. fetchModules(ids).then((res)=>{
  140. if(+res.data.code===0){
  141. const list = res.data.data;
  142. // if(list&&list.length>0){
  143. if(list&&JSON.stringify(list) !== '{}'){
  144. existsId.map((i)=>{
  145. // has.push(...list[i].questionMapping);
  146. has.push(list[i]);
  147. });
  148. withsId.map((i)=>{
  149. // wes.push(...list[i].questionMapping);
  150. wes.push(list[i]);
  151. });
  152. dispatch({
  153. type: CURRENT_CONFIRM,
  154. data: {exists:has,withs:wes,nones:nones,ikey,ban,noneIds}
  155. });
  156. }else{
  157. dispatch({
  158. type: CURRENT_CONFIRM,
  159. data: {exists,withs,nones,ikey,ban,noneIds}
  160. });
  161. }
  162. dispatch({ //自由文本标签数据更新
  163. type:ISREAD
  164. });
  165. }else{
  166. console.log(res);
  167. }
  168. });
  169. }
  170. //其他史多选标签确定事件
  171. function otherHisConfirm(dispatch,store,params){
  172. const {nones,exists,withs,exclusion,excluName,copyType} = params;
  173. // const ikey = params.ikey.substr(1,1);
  174. const index = params.ikey;
  175. let ikey = getLabelIndex(index);
  176. if(params.exclusion){
  177. dispatch({
  178. type: CONFIRMSELECTED,
  179. data:{exclusion,excluName,ikey,copyType}
  180. });
  181. return ;
  182. }
  183. let existsId = getIds(exists);
  184. let withsId = getIds(withs);
  185. const ids = existsId.length>0?existsId.join(",")+','+withsId.join(","):withsId.join(",");
  186. if(!ids&&nones){ //只有无的项目
  187. dispatch({
  188. type: CONFIRMSELECTED,
  189. data: {exists:[],withs:[],nones:nones,ikey,copyType}
  190. });
  191. dispatch({
  192. type:ISREAD
  193. });
  194. return;
  195. }
  196. // const ids = exists.join(",")+withs.join(",");
  197. let has = [],wes=[];
  198. //获取选中项目模板
  199. fetchModules(ids).then((res)=>{
  200. if(+res.data.code===0){
  201. const list = res.data.data;
  202. existsId.map((i)=>{
  203. has.push(...list[i].questionMapping);
  204. });
  205. withsId.map((i)=>{
  206. wes.push(...list[i].questionMapping);
  207. });
  208. dispatch({
  209. type: CONFIRMSELECTED,
  210. data: {exists:fullfillText(has,false,true).newArr,withs:fullfillText(wes,false,true).newArr,nones:nones,ikey,copyType}
  211. });
  212. dispatch({
  213. type:ISREAD
  214. });
  215. }
  216. });
  217. }
  218. function checkBodyConfirm(dispatch,store,params){
  219. const {nones,exists,withs,exclusion,excluName,copyType} = params;
  220. // const ikey = params.ikey.substr(1,1);
  221. const index = params.ikey;
  222. let ikey = getLabelIndex(index);
  223. if(params.exclusion){
  224. dispatch({
  225. type: CHECKCONFIRMSELECTED,
  226. data:{exclusion,excluName,ikey,copyType}
  227. });
  228. return ;
  229. }
  230. let existsId = getIds(exists);
  231. let withsId = getIds(withs);
  232. const ids = existsId.join(",")+','+withsId.join(",");
  233. if(!ids&&nones){ //只有无的项目
  234. dispatch({
  235. type: CHECKCONFIRMSELECTED,
  236. data: {exists:[],withs:[],nones:nones,ikey,copyType}
  237. });
  238. dispatch({
  239. type:ISREAD
  240. });
  241. return;
  242. }
  243. // const ids = exists.join(",")+withs.join(",");
  244. let has = [],wes=[];
  245. //获取选中项目模板
  246. fetchModules(ids).then((res)=>{
  247. if(+res.data.code===0){
  248. const list = res.data.data;
  249. existsId.map((i)=>{
  250. has.push(...list[i].questionMapping);
  251. });
  252. withsId.map((i)=>{
  253. wes.push(...list[i].questionMapping);
  254. });
  255. dispatch({
  256. type: CHECKCONFIRMSELECTED,
  257. data: {exists:fullfillText(has,false,false).newArr,withs:fullfillText(wes,false,false).newArr,nones:nones,ikey,copyType}
  258. });
  259. dispatch({
  260. type:ISREAD
  261. });
  262. }
  263. });
  264. }
  265. //在不同模块(主诉、现病史等)下拉选中调用不同事件
  266. function handleModuleDiff(dispatch,store,params){
  267. const {type,mainSaveText} = params;
  268. switch (+type){
  269. case 1:
  270. /*let text = filterDataArr(mainSaveText);
  271. if(text.length >= config.limited){
  272. Notify.info(config.limitText);
  273. return
  274. }*/
  275. mainSuitModule(dispatch,store,params);
  276. break;
  277. case 2:
  278. currentIll(dispatch,store,params);
  279. break;
  280. case 3:
  281. otherHisConfirm(dispatch,store,params);
  282. break;
  283. case 4:
  284. checkBodyConfirm(dispatch,store,params);
  285. break;
  286. default:
  287. }
  288. }
  289. /*****************普通多选框确定事件**************************/
  290. //主诉普通多选确定
  291. function mainSuitCheck(dispatch,store,params){
  292. const {nones,exists,withs,order,mainSaveText,value,ikey} = params;
  293. let existsName = getNames(exists,order);
  294. let withsName = getNames(withs);
  295. let labelInx = getLabelIndex(ikey);
  296. let text = filterDataArr(mainSaveText);
  297. /*if(text.length >= config.limited){
  298. Notify.info(config.limitText);
  299. return
  300. }*/
  301. // let lengths = text.length + existsName.length;
  302. let lengths = value?(text.length - value.length + existsName.length):(text.length + existsName.length);
  303. if(lengths > config.limited){
  304. Notify.info(config.limitText);
  305. return
  306. }
  307. // const index = params.ikey;
  308. // let ikey = getLabelIndex(index);
  309. dispatch({
  310. type: COMM_CONFIRM,
  311. // data: {exists:exists,existsName:existsName,ikey}
  312. data:Object.assign({},params,{existsName,withsName,labelInx})
  313. });
  314. dispatch({//隐藏下拉
  315. type:HIDEDROP
  316. })
  317. }
  318. //现病史普通多选确定
  319. function currentCheck(dispatch,store,params){
  320. const {ikey,exclusion,excluName,nones,exists,noneIds,noneOn,nowOn,withOn,withs,order} = params;
  321. let existsName = getNames(exists,order);
  322. let withsName = getNames(withs);
  323. let labelInx = getLabelIndex(ikey);
  324. dispatch({
  325. type:SETMAINCHECKBOX,
  326. // data:{labelInx,ikey,exclusion,excluName,nones,exists,existsName,noneIds,noneOn,nowOn,withOn,withs,withsName}
  327. data:Object.assign({},params,{existsName,withsName,labelInx})
  328. })
  329. }
  330. //查体普通多选确定
  331. function checkBodyCheck(dispatch,store,params){
  332. const {ikey,exclusion,excluName,nones,exists,noneIds,noneOn,nowOn,withOn,withs,order} = params;
  333. let existsName = getNames(exists,order);
  334. let withsName = getNames(withs);
  335. let labelInx = getLabelIndex(ikey);
  336. dispatch({
  337. type:SETCHECKBOX,
  338. // data:{labelInx,ikey,exclusion,excluName,nones,exists,existsName,noneIds,noneOn,nowOn,withOn,withs,withsName}
  339. data:Object.assign({},params,{existsName,withsName,labelInx})
  340. })
  341. }
  342. //其他史普通多选确定
  343. function otherHisCheck(dispatch,store,params){
  344. const {ikey,exclusion,excluName,nones,exists,noneIds,noneOn,nowOn,withOn,withs,order} = params;
  345. let existsName = getNames(exists,order);
  346. let withsName = getNames(withs);
  347. let labelInx = getLabelIndex(ikey);
  348. dispatch({
  349. type:SETOTHERCHECKBOX,
  350. // data:{labelInx,ikey,exclusion,excluName,nones,exists,existsName,noneIds,noneOn,nowOn,withOn,withs,withsName}
  351. data:Object.assign({},params,{existsName,withsName,labelInx})
  352. })
  353. }
  354. function handleCheckBox(dispatch,store,params){
  355. const {type,mainSaveText} = params;
  356. switch (+type){
  357. case 1:
  358. /*let text = filterDataArr(mainSaveText);
  359. if(text.length >= config.limited){
  360. Notify.info(config.limitText);
  361. return
  362. }*/
  363. mainSuitCheck(dispatch,store,params);
  364. break;
  365. case 2:
  366. currentCheck(dispatch,store,params);
  367. break;
  368. case 3:
  369. otherHisCheck(dispatch,store,params);
  370. break;
  371. case 4:
  372. checkBodyCheck(dispatch,store,params);
  373. break;
  374. default:
  375. }
  376. }
  377. /**************标签双击输入**************/
  378. //主诉
  379. function mainSuitLabelEdit(dispatch,params){
  380. const index = params.ikey;
  381. let ikey = getLabelIndex(index);
  382. dispatch({
  383. type:CHANGE_LABELVAL,
  384. data:{changeVal:params.changeVal,ikey:ikey}
  385. })
  386. }
  387. //现病史
  388. function currentLabelEdit(dispatch,params){
  389. const index = params.ikey;
  390. let ikey = getLabelIndex(index);
  391. dispatch({
  392. type:CURRENT_TEXT_LABEL,
  393. data:{changeVal:params.changeVal,ikey:ikey}
  394. })
  395. }
  396. //其他史
  397. function otherHisLabelEdit(dispatch,params){
  398. const index = params.ikey;
  399. let ikey = getLabelIndex(index);
  400. dispatch({
  401. type:CHANGEOTHERTEXTLABEL,
  402. data:{changeVal:params.changeVal,ikey:ikey}
  403. })
  404. }
  405. //查体
  406. function checkBodyLabelEdit(dispatch,params){
  407. const index = params.ikey;
  408. let ikey = getLabelIndex(index);
  409. const {changeVal} = params;
  410. dispatch({
  411. type:CHANGECHECKTEXTLABEL,
  412. data:{totalVal:changeVal,ikey:ikey,changeVal}
  413. })
  414. }
  415. function handleLabel(dispatch,params){
  416. const {type} = params;
  417. switch (+type){
  418. case 1:
  419. mainSuitLabelEdit(dispatch,params);
  420. break;
  421. case 2:
  422. currentLabelEdit(dispatch,params);
  423. break;
  424. case 3:
  425. otherHisLabelEdit(dispatch,params);
  426. break;
  427. case 4:
  428. checkBodyLabelEdit(dispatch,params);
  429. break;
  430. default:
  431. }
  432. dispatch(billing());
  433. dispatch({
  434. type:ISREAD
  435. })
  436. }
  437. function mapDispatchToProps(dispatch,store){
  438. return {
  439. handleConfirm(obj){
  440. if(obj.tagType == 6||obj.tagType == 11){//铺开
  441. handleModuleDiff(dispatch,store,obj);
  442. }else if(obj.tagType == 2){//普通多选
  443. handleCheckBox(dispatch,store,obj);
  444. }
  445. //右侧推送
  446. setTimeout(function(){ //延迟待确定后的数据更新后推送,避免获取的参数还是旧的
  447. if(didPushParamChange()){ //操作后内容有变化才推送
  448. dispatch(billing());
  449. }
  450. },500);
  451. },
  452. handleHide(){
  453. dispatch({
  454. type: HIDEDROP
  455. });
  456. },
  457. async handleShow(obj){
  458. // 埋点dispatch
  459. dispatch({
  460. type:CLICKCOUNT,
  461. data:obj,
  462. clickType:'单击',
  463. num:1
  464. });
  465. // 调大数据接口
  466. if(obj.tagType ==11 ){
  467. const bigData = await getCommSymptomPush();
  468. let result = bigData.data;
  469. if(+result.code == 0){
  470. // let pushDataList = result.data.symptom;
  471. let bigDataList = result.data.symptom;
  472. let pushDataList = [];
  473. if(bigDataList&&bigDataList.length>0){//剔除没有id
  474. pushDataList = bigDataList.filter(function(item){
  475. return item.id
  476. });
  477. }else{
  478. pushDataList = bigDataList;
  479. }
  480. /*if(pushDataList.length > 0){
  481. if(obj.type == 1){// 主诉--添加症状
  482. dispatch({
  483. type:GET_BIGDATAPUSH,
  484. data:pushDataList,
  485. info:obj
  486. })
  487. }else if(obj.type == 2){// 现病史--添加其他症状
  488. dispatch({
  489. type:CURRENT_GET_BIGDATAPUSH,
  490. data:pushDataList,
  491. info:obj
  492. })
  493. }
  494. }else{
  495. Notify.info("暂无推送");
  496. // return
  497. }*/
  498. //推送无数据显示空下拉并提示暂无推送--1.9/1.18
  499. if(!pushDataList || pushDataList.length == 0){Notify.info("暂无推送");}
  500. if(obj.type == 1){// 主诉--添加症状
  501. dispatch({
  502. type:GET_BIGDATAPUSH,
  503. data:pushDataList,
  504. info:obj
  505. })
  506. }else if(obj.type == 2){// 现病史--添加其他症状
  507. dispatch({
  508. type:CURRENT_GET_BIGDATAPUSH,
  509. data:pushDataList,
  510. info:obj
  511. })
  512. }
  513. }else{
  514. console.log(result.msg);
  515. Notify.info("暂无推送");
  516. // 接口请求失败,不往下执行显示下拉
  517. return
  518. }
  519. }
  520. dispatch({
  521. type:SETDROPSHOW,
  522. data:obj
  523. });
  524. dispatch({
  525. type: RESET
  526. });
  527. },
  528. handleDbclick(obj){//双击统计
  529. dispatch({
  530. type:CLICKCOUNT,
  531. data:obj,
  532. clickType:'双击',
  533. num:1
  534. });
  535. },
  536. handleLabelChange(obj){//标签内输入
  537. handleLabel(dispatch,obj);
  538. }
  539. }
  540. }
  541. const SpreadDropCont = connect(
  542. mapStateToProps,
  543. mapDispatchToProps
  544. )(SpreadDrop);
  545. export default SpreadDropCont;