currentIll.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. import {getLabelIndex,fullfillText,getIds} from '@common/js/func.js';
  2. import config from '@config/index.js';
  3. //插入病程变化模板
  4. function insertPro(data,processModule){
  5. let index;
  6. for(let i=0; i<data.length; i++){
  7. if(data[i].flag && data[i].flag==3 ){
  8. index = i;
  9. }
  10. }
  11. for(let j=0; j<processModule.length; j++){
  12. let pos = index + j;
  13. data.splice(pos,0,processModule[j]);
  14. }
  15. return data;
  16. }
  17. //设置模板
  18. export const setModule = (state,action)=>{
  19. const res = Object.assign({},state);
  20. res.moduleData = action.data;
  21. res.processModule = action.processModule;//病程变化模板
  22. res.processModuleName = action.processModuleName;//模板名称
  23. res.emptyData = action.emptyData;//空模板
  24. let data = action.data;
  25. let sliceIdx;
  26. data.map((v,i)=>{
  27. if(v.flag && v.flag==2){
  28. sliceIdx = i;
  29. }
  30. })
  31. res.addModule = data.slice(0,sliceIdx+1);//截取到flag=2 有无治疗
  32. res.update=Math.random();
  33. return res;
  34. }
  35. //插入病程变化
  36. export const insertProcess = (state,action)=>{
  37. const res = Object.assign({},state);
  38. const processModule = JSON.parse(JSON.stringify(res.processModule));
  39. let data = res.data;
  40. res.data = insertPro(data,processModule);
  41. res.saveText = fullfillText(res.data).saveText;
  42. res.update=Math.random();
  43. return res;
  44. }
  45. function addPos(data,num){
  46. let newData = JSON.parse(JSON.stringify(data));
  47. newData.forEach((it,i)=>{
  48. it.pos = num;
  49. })
  50. return newData;
  51. }
  52. //聚焦时设置 现病史模板
  53. export const setData = (state,action) =>{
  54. let res = Object.assign({},state);
  55. res.editClear = false;
  56. const mainIds = action.info.mainIds;
  57. res.symptomIds = JSON.parse(JSON.stringify(mainIds));
  58. const num = action.info.num;//点击了几次添加病情变化
  59. const symptomFeature = action.info.symptomFeature;//分词
  60. // const useEmpty = action.info.useEmpty;
  61. let useEmpty,mainData;
  62. // let mainData = JSON.parse(JSON.stringify(action.info.mainData));//主诉模板数据
  63. let mainModleData = JSON.parse(JSON.stringify(action.info.mainData));//主诉模板数据
  64. let moduleData = JSON.parse(JSON.stringify(res.moduleData));//现病史模板
  65. let addModule = JSON.parse(JSON.stringify(res.addModule));//拷贝的模板
  66. let current = JSON.parse(JSON.stringify(moduleData));
  67. let newMain = [];
  68. let mainLabelModule = res.mainLabelModule;//主诉选中的症状id获取到的模板
  69. let objToArr = [];
  70. let keyArr = Object.keys(mainLabelModule);
  71. for(let i=0; i<keyArr.length; i++){
  72. objToArr.push(mainLabelModule[JSON.parse(keyArr[i])]);
  73. }
  74. /*for(let m in mainLabelModule){
  75. objToArr.push(mainLabelModule[m]);
  76. }*/
  77. // 过滤掉没有mapping的数据
  78. let mainLabelModuleArr = objToArr;
  79. /*let mainLabelModuleArr = objToArr.filter((item)=>{
  80. return item.questionMapping.length>0;
  81. })*/
  82. // 是否使用空模板:num=0时判断mainIds,num>=1,截取第一病程遍历是否有症状exist
  83. if(num==0){
  84. useEmpty = mainIds.length>0 ? false:true;
  85. mainData = mainModleData;
  86. }else{
  87. let sliceIdx;
  88. for(let j=0; j<mainModleData.length; j++){
  89. if(mainModleData[j].id==config.tongYId && mainModleData[j].pos==1){
  90. sliceIdx = j;
  91. }
  92. }
  93. mainData = mainModleData.slice(0,sliceIdx);
  94. let existData = mainData.filter((item)=>{
  95. return item.exist;
  96. })
  97. useEmpty = existData&&existData.length>0?false:true;
  98. }
  99. // console.log(888,useEmpty);
  100. if (useEmpty) {
  101. // res.data = res.emptyData;
  102. res.data = JSON.parse(JSON.stringify(res.emptyData));
  103. } else {
  104. if(mainData&&mainData.length>0){//主诉使用模板
  105. // 目前只需要将第一个主诉病程移植到现病史
  106. let tongYong = "";
  107. let main = [];//主症状
  108. let withs = [];//伴随
  109. let firstT = 0;
  110. for(let i=0; i<mainData.length; i++){
  111. if(mainData[i].id==config.tongYId && !mainData[i].pos){//第一个通用特征描述
  112. if(mainData[i].value){
  113. tongYong = mainData[i].value;
  114. }
  115. }
  116. else if(mainData[i].exist){
  117. mainData[i].exist==1?main.push(mainData[i]):withs.push(mainData[i])
  118. }
  119. // 处理时间和主诉通用症状--现病史模板无“主诉通用症状” 1-7
  120. for(let j=0; j<current.length; j++){
  121. if(mainData[i].id==current[j].id && mainData[i].controlType==5){//处理时间,避免手动输入的值
  122. firstT++
  123. if(mainData[i].value && firstT==1){
  124. current[j] = {id:mainData[i].id,name:mainData[i].value,value:mainData[i].value,tagType:config.tagType}
  125. }
  126. }
  127. }
  128. }
  129. // 主症状添加tongYong标签选中文字
  130. let tongYText = tongYong?{name:tongYong,value:tongYong,tagType:config.tagType}:'';
  131. let mainCopy = JSON.parse(JSON.stringify(main));
  132. /*if(tongYText){
  133. for(let j=0; j<mainCopy.length; j++){
  134. mainCopy[j].name = tongYong + (mainCopy[j].name).replace('、',"");
  135. mainCopy[j].value = tongYong + (mainCopy[j].value).replace('、',"");
  136. }
  137. }*/
  138. for(let j=0; j<mainCopy.length; j++){
  139. if(tongYText){
  140. mainCopy[j].name = tongYong + (mainCopy[j].name).replace('、',"");
  141. mainCopy[j].value = tongYong + (mainCopy[j].value).replace('、',"");
  142. }else{
  143. mainCopy[j].name = (mainCopy[j].name).replace('、',"");
  144. mainCopy[j].value = (mainCopy[j].value).replace('、',"");
  145. }
  146. }
  147. // 将ids接口获取到的模板匹配到对应主症状后面
  148. // 主症状
  149. let newMainCopy = JSON.parse(JSON.stringify(mainCopy));
  150. let ind = 0;
  151. let insertInd = 0;
  152. // let preLength = 0;
  153. let lengArr=[];
  154. for(let k=0; k <mainCopy.length;k++){
  155. mainLabelModuleArr.map((v,i)=>{
  156. if(mainCopy[k].id==v.id){
  157. ind++;
  158. let items = v.questionMapping.filter((item)=>{
  159. return item.symptomType==0||item.symptomType==1;
  160. })
  161. lengArr[k] = items.length; //每一个主诉尾巴长度
  162. if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
  163. for(let j=0; j<newMainCopy.length; j++){
  164. if(newMainCopy[j].id==mainCopy[k].id){
  165. newMainCopy[j].value = newMainCopy[j].name = mainCopy[k].value+',';
  166. }
  167. }
  168. }
  169. /*if(ind==1){
  170. preLength = items.length;
  171. }else{
  172. insertInd += preLength;
  173. }*/
  174. if(ind>1){
  175. insertInd += lengArr[k-1];
  176. }
  177. newMainCopy.splice(k+insertInd+1,0,...items);
  178. }
  179. })
  180. }
  181. // 伴随
  182. // 去掉顿号
  183. /* for(let b=0; b<withs.length; b++){
  184. withs[b].name = withs[b].name.replace('、',"");
  185. }*/
  186. // let newWiths = JSON.parse(JSON.stringify(withs));
  187. let newWiths = [];
  188. if(withs.length>0){
  189. for(let b=0; b<withs.length; b++){
  190. withs[b].name = withs[b].name.replace('、',"");
  191. withs[b].value = withs[b].value.replace('、',"");
  192. }
  193. newWiths = JSON.parse(JSON.stringify(withs));
  194. let withInd = 0;
  195. let withInsertInd = 0;
  196. let withLengArr=[];
  197. for(let d=0; d <withs.length;d++){
  198. mainLabelModuleArr.map((v,i)=>{
  199. if(withs[d].id==v.id){
  200. withInd++;
  201. let items = v.questionMapping.filter((item)=>{
  202. return item.symptomType==0||item.symptomType==2;
  203. })
  204. /*if(withInd==1){
  205. withPreLength = items.length;
  206. }else{
  207. withInsertInd += withPreLength;
  208. }*/
  209. withLengArr[d] = items.length;
  210. if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
  211. for(let j=0; j<newWiths.length; j++){
  212. if(newWiths[j].id==mainCopy[d].id){
  213. newWiths[j].value = newWiths[j].name = withs[d].value+',';
  214. }
  215. }
  216. }
  217. if(withInd>1){
  218. withInsertInd += withLengArr[d-1];
  219. }
  220. newWiths.splice(d+withInsertInd+1,0,...items);
  221. }
  222. })
  223. }
  224. }
  225. let symptomArr = newMainCopy.concat(newWiths);
  226. let newSymptomArr = JSON.parse(JSON.stringify(symptomArr));
  227. //组装好的主症状和伴随症状插入现病史模板(flag=4前)
  228. let insertIdx = null;
  229. for(let j=0; j<current.length; j++){
  230. if(current[j].flag && current[j].flag==4){
  231. insertIdx = j;
  232. }
  233. }
  234. for(let k=0; k<newSymptomArr.length; k++){
  235. let pos = insertIdx+k;
  236. current.splice(pos,0,newSymptomArr[k]);
  237. }
  238. let currentData = JSON.parse(JSON.stringify(current));
  239. res.data = fullfillText(currentData).newArr;
  240. }else{//分词
  241. if(symptomFeature&&symptomFeature.length>0){
  242. let featureData = JSON.parse(JSON.stringify(symptomFeature));
  243. let ind = 0;
  244. let insertInd = 0;
  245. let lengArr=[];
  246. for(let k=0; k <symptomFeature.length;k++){
  247. mainLabelModuleArr.map((v,i)=>{
  248. if(symptomFeature[k].id==v.id){
  249. ind++;
  250. let items = v.questionMapping.filter((item)=>{
  251. return item.symptomType==0||item.symptomType==1;
  252. })
  253. lengArr[k] = items.length; //每一个主诉尾巴长度
  254. if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
  255. for(let j=0; j<featureData.length; j++){
  256. if(featureData[j].id==symptomFeature[k].id){
  257. featureData[j].value = featureData[j].name = symptomFeature[k].value+',';
  258. }
  259. }
  260. }
  261. if(ind>1){
  262. insertInd += lengArr[k-1];
  263. }
  264. featureData.splice(k+insertInd+1,0,...items);
  265. }
  266. })
  267. }
  268. //组装好的主症状和伴随症状插入现病史模板(flag=4前)
  269. let endFeatureData = JSON.parse(JSON.stringify(featureData));
  270. let insertIdx = null;
  271. for(let j=0; j<current.length; j++){
  272. if(current[j].flag && current[j].flag==4){
  273. insertIdx = j;
  274. }
  275. }
  276. for(let k=0; k<endFeatureData.length; k++){
  277. let pos = insertIdx+k;
  278. current.splice(pos,0,endFeatureData[k]);
  279. }
  280. let currentData = JSON.parse(JSON.stringify(current));
  281. res.data = fullfillText(currentData).newArr;
  282. }
  283. }
  284. }
  285. let resData = JSON.parse(JSON.stringify(res.data));
  286. res.saveText = fullfillText(resData).saveText;
  287. res.update=Math.random();
  288. return res;
  289. }
  290. function getLabel(lid,lname){
  291. return {id:lid,name:lname,value:lname,tagType:config.tagType}
  292. }
  293. // 多选展开确定事件--主、伴、无
  294. export const confirm = (state,action) =>{
  295. let res = Object.assign({},state);
  296. let length1 = res.data.length;
  297. let arr = JSON.parse(JSON.stringify(res.data));
  298. const {nones,exists,withs,ikey,exclusion,excluName,ban,noneIds} = action.data;
  299. let existsId = exists && exists.length>0?getIds(exists):[];
  300. let withsId = withs && withs.length>0?getIds(withs):[];
  301. res.symptomIds = res.symptomIds.concat(existsId,withsId,noneIds);//搜索去重
  302. // 伴 标签
  303. const banText = JSON.stringify(ban)=='{}'?'':{id:ban.id,name:ban.name,value:ban.name,tagType:config.tagType};
  304. // 处理主症状标签及尾巴展开symptomType=1
  305. if(exists && exists.length>0){
  306. // for(let i in exists){//ie8不支持for in循环
  307. for(let i=0;i<exists.length; i++){
  308. arr.splice(ikey,0,getLabel(exists[i].id,exists[i].questionMapping && exists[i].questionMapping.length==0?exists[i].name+',':exists[i].name),...(exists[i].questionMapping && exists[i].questionMapping.filter((item)=>{return item.symptomType==0||item.symptomType==1;})));
  309. }
  310. }
  311. let length = arr.length - length1;
  312. let withsArr = JSON.parse(JSON.stringify(arr));
  313. // 伴 伴随症状标签及尾巴展开symptomType=2
  314. if(withs && withs.length>0){
  315. // for(let i in withs){
  316. for(let i=0;i<withs.length; i++){
  317. withsArr.splice(parseInt(ikey)+length,0,banText,getLabel(withs[i].id,withs[i].questionMapping && withs[i].questionMapping.length==0?(withs[i].name+','):(withs[i].name)),...(withs[i].questionMapping.filter((item)=>{return item.symptomType==0||item.symptomType==2;})));
  318. /*withsArr.splice(parseInt(ikey)+length,0,getLabel(withs[i].id,withs[i].questionMapping && withs[i].questionMapping.length==0?(ban.name+withs[i].name+','):(ban.name+withs[i].name)),...(withs[i].questionMapping && withs[i].questionMapping.filter((item)=>{return item.symptomType==0||item.symptomType==2;})));*/
  319. }
  320. }
  321. // 无 不用展开
  322. let lengthN = withsArr.length - length1;
  323. let noneArr = JSON.parse(JSON.stringify(withsArr));
  324. if(nones.length>1){//只点无不上去
  325. const nonesName = nones.slice(0,nones.length-1)+',';
  326. const noneObj = Object.assign({},JSON.parse(config.textLabel),{name:nonesName,value:nonesName});
  327. const none = nones?noneObj:'';
  328. noneArr.splice(parseInt(ikey)+lengthN,0,none);
  329. }
  330. let resData = JSON.parse(JSON.stringify(noneArr));
  331. // res.data = resData;
  332. res.data = fullfillText(resData).newArr;
  333. res.saveText = fullfillText(resData).saveText;
  334. res.update=Math.random();
  335. return res;
  336. };
  337. //普通多选确定事件-主诉通用特征、初为后为等
  338. export const setCheckBox = (state,action)=>{
  339. const res = Object.assign({},state);
  340. const {exists,labelInx,existsName} = action.data;
  341. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  342. let names=existsName;
  343. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  344. if(pattern.test(existsName)){
  345. names = existsName.substr(0,existsName.length-1);
  346. }
  347. let arr = res.data;
  348. arr[labelInx].value = names;
  349. res.saveText[labelInx] = names;
  350. res.selecteds[labelInx] = action.data;
  351. res.update=Math.random();
  352. return res;
  353. }
  354. //数字键盘选中事件
  355. export function setNumberValue(state,action){
  356. let res = Object.assign({},state);
  357. const param = action.params;
  358. const index = param.ikey;
  359. let labelInx = getLabelIndex(index);
  360. const subInx = index.substr(index.length-1);
  361. let item = res.data[labelInx];
  362. // if(param.text.trim()){
  363. if(+item.tagType===1){
  364. item.value = param.text;
  365. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  366. }else{
  367. item.questionMapping[subInx].value = param.text;
  368. let hasValue = false;
  369. const sub = item.questionMapping.map((it)=>{
  370. if(it.value){ //至少有一个子值才黑显
  371. hasValue = true;
  372. }
  373. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  374. });
  375. // res.saveText[labelInx] = sub.join(',');
  376. res.saveText[labelInx] = hasValue?sub.join(''):'';
  377. item.value = sub.join('');
  378. }
  379. /*}else{//删除完标签内容则删除该标签
  380. res.data.splice(labelInx,1);
  381. res.saveText = fullfillText(res.data).saveText;
  382. }*/
  383. res.update = Math.random();
  384. return res;
  385. }
  386. //单选下拉选中
  387. export function setRadioValue(state,action){
  388. let res = Object.assign({},state);
  389. const {ikey,id,text} = action;
  390. let labelInx = getLabelIndex(ikey);
  391. const subInx = ikey.substr(ikey.length-1);
  392. let item = res.data[labelInx];
  393. if(typeof text != 'string'){ //需要展开项--有无治疗类型
  394. const len = +item.copyType === 0?1:0;
  395. res.data.splice(labelInx,len,text);
  396. return res;
  397. }
  398. if(+item.tagType===1){
  399. item.value = text;
  400. res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
  401. item.questionDetailList.map((its)=>{
  402. if(its.id === id){
  403. its.selected = true;
  404. }else{
  405. its.selected = false;
  406. }
  407. });
  408. }else{
  409. item.questionMapping[subInx].value = text;
  410. /*if(item.questionMapping[subInx].controlType==1){//例如:有无治疗-未经治疗
  411. item.value = text;
  412. }else{
  413. item.questionMapping[subInx].value = text;
  414. }*/
  415. let hasValue = false;
  416. const sub = item.questionMapping.map((it)=>{
  417. //添加选中状态
  418. it.questionDetailList.map((its)=>{
  419. if(its.id === id){
  420. its.selected = true;
  421. }else{
  422. its.selected = false;
  423. }
  424. });
  425. if(it.value){ //至少有一个子值才黑显
  426. hasValue = true;
  427. }
  428. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  429. });
  430. res.saveText[labelInx] = hasValue?sub.join(''):'';
  431. }
  432. res.update = Math.random();
  433. return res;
  434. }
  435. //双击标签输入改变值
  436. export const changeLabelVal = (state,action)=>{
  437. const res = Object.assign({},state);
  438. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  439. const index = ikey;
  440. const newVal = changeVal;
  441. let labText = totalVal?totalVal:newVal;
  442. let item = res.data[index];
  443. const next = res.data[+index+1];
  444. const nextVal = next.value||next.name;
  445. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  446. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  447. if(labText.trim()){
  448. if(item){
  449. item.value = newVal;
  450. item.labelPrefix = prefix||'';
  451. item.labelSuffix = suffix||'';
  452. res.saveText[index] = labText;
  453. }
  454. }else{//删除完标签内容则删除该标签
  455. const num = nextIsDot?2:1;
  456. res.data.splice(index,num);
  457. res.saveText = fullfillText(res.data).saveText;
  458. }
  459. res.update = Math.random();
  460. return res;
  461. }
  462. // 数字键盘较特殊,有直接输入
  463. export const changeNumLabelVal = (state,action)=>{
  464. const res = Object.assign({},state);
  465. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  466. const index = ikey;
  467. const newVal = changeVal;
  468. let item = res.data[index];
  469. const next = res.data[+index+1];
  470. const nextVal = next.value||next.name;
  471. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  472. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  473. let labText = totalVal?totalVal:newVal; //如单选没有前后缀
  474. if(labText.trim()){
  475. if(item){
  476. item.value = newVal;
  477. item.labelPrefix = prefix||'';
  478. item.labelSuffix = suffix||'';
  479. }
  480. res.saveText[index] = labText;
  481. }else{//删除完标签内容则删除该标签
  482. const num = nextIsDot?2:1;
  483. res.data.splice(index,num);
  484. res.saveText = fullfillText(res.data).saveText;
  485. }
  486. res.update = Math.random();
  487. return res;
  488. }
  489. export const clearCurrentIll = (state,action)=>{
  490. const res = Object.assign({},state);
  491. res.data = action.data;
  492. res.saveText = action.saveText;
  493. res.selecteds = action.selecteds?action.selecteds:[];
  494. res.symptomIds = action.symptomIds;
  495. res.symptomIds = action.symptomIds;
  496. if(action.editClear){
  497. res.editClear = action.editClear;
  498. }
  499. if(res.data.length>0){
  500. res.editClear = false;
  501. }
  502. res.update = Math.random();
  503. return res;
  504. }
  505. //文本模式下值保存
  506. export const setTextModeValue = (state,action)=>{
  507. const res = Object.assign({},state);
  508. res.saveText[0] = action.text;
  509. return res;
  510. };
  511. //获取大数据推送症状
  512. export const bigDataSymptom = (state,action) => {
  513. const res = Object.assign({},state);
  514. res.bigDataSymptom = action.data;//推送数据
  515. let inlineDatas = res.data;
  516. const index = action.info.ikey;
  517. let labelInx = getLabelIndex(index);
  518. // 添加症状 暂时剔除没有id、questionMapping字段的数据
  519. let pushDataList = action.data;
  520. /*let pushDataList = action.data.filter(function(item){
  521. return item.id
  522. });*/
  523. let dataList = inlineDatas[labelInx].questionMapping;
  524. for(let k=0; k<dataList.length; k++){
  525. if(dataList[k].controlType == 99){
  526. dataList[k].questionDetailList = pushDataList;
  527. }
  528. }
  529. res.update = Math.random();
  530. return res;
  531. }
  532. //自由文本
  533. export function setCheckText(state,action) {
  534. let res = Object.assign({},state);
  535. const {i,text} = action;
  536. if(res.data[i]){
  537. res.data[i].value=text;
  538. //res.data[i].name=''; //默认显示的文字
  539. }
  540. res.saveText[i] = text;
  541. res.update = Math.random();
  542. return res;
  543. }
  544. //搜索 插入标签数据
  545. export function insertLabelData(state,action){
  546. let res = Object.assign({},state);
  547. const {index,data,isReplace,span}=action;console.log('现病史搜索数据',action);
  548. let id = data.id;
  549. let searchData = action.name;
  550. // res.symptomIds.push(id);
  551. const text = Object.assign(JSON.parse(config.textLabel),{name:searchData},{id:id});
  552. const textEmpty = Object.assign({},JSON.parse(config.textLabel));
  553. let focusIndex = res.focusIndex;
  554. let saveText = res.saveText;
  555. let banIdx = saveText.indexOf("伴");
  556. if(isReplace){
  557. span.current.innerText?(span.current.innerText = ''):(span.current.innerHTML = '');
  558. // res.data.splice(focusIndex,1,text,data);
  559. // 搜索结果展开伴随symptomType==2的尾巴
  560. let resData = JSON.parse(JSON.stringify(res.data));
  561. resData.splice(focusIndex,1,text,...(data.questionMapping.filter((item)=>{
  562. return item.symptomType==0||item.symptomType==2;
  563. })));
  564. res.data = fullfillText(resData).newArr;
  565. res.saveText[focusIndex] = searchData;
  566. }else{
  567. let resData;
  568. const searchStr = res.searchStr;
  569. let innerText = span.current.innerText || span.current.innerHTML;
  570. let strIndex = innerText.indexOf(searchStr);
  571. const value = innerText.replace(searchStr,"");
  572. if(data.itemType==0){//症状
  573. res.symptomIds.push(id);
  574. // 没有伴展开主诉symptomType=0/1的尾巴,有伴一>第一个点选上去的伴为依据,伴前展开主诉,伴后展开伴随;多余的伴以及手动输入的伴不做处理(2-25)
  575. if(banIdx==-1){
  576. // if(strIndex <= 1){//前
  577. if(strIndex < 1){//前
  578. res.data.splice(focusIndex,0,text);
  579. res.saveText.splice(focusIndex,0,searchData);
  580. res.data[focusIndex+1].value = value;
  581. res.saveText[focusIndex+1] = value;
  582. resData = JSON.parse(JSON.stringify(res.data));
  583. resData.splice(focusIndex+1,0,...(data.questionMapping.filter((item)=>{
  584. return item.symptomType==0||item.symptomType==1;
  585. })));
  586. }else{
  587. res.data.splice(focusIndex+1,0,text);
  588. res.saveText.splice(focusIndex+1,0,searchData);
  589. res.data[focusIndex].value = value;
  590. res.saveText[focusIndex] = value;
  591. resData = JSON.parse(JSON.stringify(res.data));
  592. // +2是因为插入一个文本标签
  593. resData.splice(focusIndex+2,0,...(data.questionMapping.filter((item)=>{
  594. return item.symptomType==0||item.symptomType==1;
  595. })));
  596. }
  597. }else{
  598. if(focusIndex > banIdx){//伴后
  599. if(strIndex < 1){//前
  600. res.data.splice(focusIndex,0,text);
  601. res.saveText.splice(focusIndex,0,searchData);
  602. res.data[focusIndex+1].value = value;
  603. res.saveText[focusIndex+1] = value;
  604. resData = JSON.parse(JSON.stringify(res.data));
  605. resData.splice(focusIndex+1,0,...(data.questionMapping.filter((item)=>{
  606. return item.symptomType==0||item.symptomType==2;
  607. })));
  608. }else{
  609. res.data.splice(focusIndex+1,0,text);
  610. res.saveText.splice(focusIndex+1,0,searchData);
  611. res.data[focusIndex].value = value;
  612. resData = JSON.parse(JSON.stringify(res.data));
  613. // +2是因为插入一个文本标签
  614. resData.splice(focusIndex+2,0,...(data.questionMapping.filter((item)=>{
  615. return item.symptomType==0||item.symptomType==2;
  616. })));
  617. }
  618. }else{//伴前
  619. if(strIndex < 1){//前
  620. res.data.splice(focusIndex,0,text);
  621. res.saveText.splice(focusIndex,0,searchData);
  622. res.data[focusIndex+1].value = value;
  623. res.saveText[focusIndex+1] = value;
  624. resData = JSON.parse(JSON.stringify(res.data));
  625. resData.splice(focusIndex+1,0,...(data.questionMapping.filter((item)=>{
  626. return item.symptomType==0||item.symptomType==1;
  627. })));
  628. }else{
  629. res.data.splice(focusIndex+1,0,text);
  630. res.saveText.splice(focusIndex+1,0,searchData);
  631. res.data[focusIndex].value = value;
  632. resData = JSON.parse(JSON.stringify(res.data));
  633. // +2是因为插入一个文本标签
  634. resData.splice(focusIndex+2,0,...(data.questionMapping.filter((item)=>{
  635. return item.symptomType==0||item.symptomType==1;
  636. })));
  637. }
  638. }
  639. }
  640. res.data = fullfillText(resData).newArr;
  641. res.saveText = fullfillText(resData).saveText;
  642. }else{//标签
  643. if(strIndex < 1){//前
  644. res.data.splice(focusIndex,0,data,textEmpty);
  645. res.saveText.splice(focusIndex,0,'','');
  646. res.selecteds.splice(focusIndex,0,null,null);
  647. res.data[focusIndex+1].value = value;
  648. res.saveText[focusIndex+1] = value;
  649. }else{
  650. res.data.splice(focusIndex+1,0,data,textEmpty);
  651. res.saveText.splice(focusIndex+1,0,'','');
  652. res.selecteds.splice(focusIndex+1,0,null,null);
  653. res.data[focusIndex].value = value;
  654. res.saveText[focusIndex] = value;
  655. }
  656. }
  657. // span.current.innerText?(span.current.innerText = value):(span.current.innerHTML = value);
  658. // res.data = fullfillText(resData).newArr;
  659. // res.saveText = fullfillText(resData).saveText;
  660. }
  661. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  662. res.update = Math.random();
  663. return res;
  664. }
  665. export const clearCurrentEdit = (state,action)=>{
  666. const res = Object.assign({},state);
  667. res.editClear = action.editClear
  668. return res;
  669. }
  670. //复制标签(如血压)事件
  671. export function addLabelItem(state,action){
  672. let res = Object.assign({},state);
  673. const {data,i} = action;
  674. const textLabel = JSON.parse(config.textLabel);
  675. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  676. if(!data) return res;
  677. res.data.splice(i+1,0,JSON.parse(data),textLabel);
  678. res.update = Math.random();
  679. return res;
  680. }
  681. //文本输入标签
  682. export function setInputLabel(state,action){
  683. let res = Object.assign({},state);
  684. const {i,text,prefix,suffix,subIndex} = action;
  685. const item = res.data[i];
  686. if(+item.tagType===3){ //multSpred标签
  687. item.questionMapping[subIndex].value = text;
  688. let texts = item.questionMapping.map((it)=>{
  689. return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):'';
  690. });
  691. res.saveText[i] = texts.join('');
  692. res.update = Math.random();
  693. return res;
  694. }else{
  695. if(item){
  696. item.value=text;
  697. }
  698. }
  699. res.saveText[i] = prefix+text+suffix;
  700. res.update = Math.random();
  701. return res;
  702. }
  703. // backspace删除
  704. export function backspaceText(state,action){
  705. let res = Object.assign({},state);
  706. const {delIndex,text} = action;
  707. const data = res.data;
  708. // if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  709. // 前一个是文本标签或者子模板,只改变值
  710. if(data[delIndex-1].flag&&data[delIndex-1].flag==3){//子模板不删
  711. // data[delIndex].value = text;
  712. }else if(data[delIndex-1].tagType==8){
  713. data.splice(delIndex,1);
  714. res.saveText.splice(delIndex,1);
  715. }
  716. else{
  717. data.splice(delIndex-1,2);
  718. res.saveText.splice(delIndex-1,2);
  719. }
  720. // res.saveText = fullfillText(data).saveText;
  721. res.update = Math.random();
  722. return res;
  723. }
  724. //删除后移除id
  725. export function removeId(state,action){
  726. let res = Object.assign({},state);
  727. const {index,text} = action;
  728. const data = res.data;
  729. const id = data[index].id;
  730. let ids = res.symptomIds;
  731. if(ids.includes(id)){
  732. ids.splice(ids.indexOf(id),1);
  733. }
  734. if(!data[index].value && data[index-1].tagType==8){
  735. data.splice(index,1);
  736. res.saveText.splice(index,1);
  737. }else{
  738. data[index].id = "";
  739. data[index].name = text;
  740. data[index].value = text;
  741. }
  742. //console.log(345,action,res);
  743. res.update = Math.random();
  744. return res;
  745. }
  746. // 单列多选
  747. export function multipleComfirn(state,action){
  748. let res = Object.assign({},state);
  749. const {ikey,seleData} = action.data;
  750. let data = res.data;
  751. data[ikey].value = seleData;
  752. res.saveText[ikey] = seleData;
  753. res.selecteds[ikey] = action.data;
  754. res.update = Math.random();
  755. return res;
  756. }
  757. export function delSingleLable(state,action){
  758. let res = Object.assign({},state);
  759. const {index} = action;
  760. let data = res.data;
  761. // 前一个不是文本标签 并且不是子模板,则删除
  762. if(data[index-1].flag&&data[index-1].flag==3){
  763. }
  764. else if(data[index-1].tagType != 8){
  765. data.splice(index-1,1);
  766. res.saveText.splice(index-1,1);
  767. }
  768. res.update = Math.random();
  769. return res;
  770. }