checkBody.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. import config from '@config/index.js';
  2. import {formatContinueDots,getLabelIndex,checkFullfillText,handleLocalDelTag,shiftLocalDelTag} from '@utils/tools.js';
  3. export function preSetCheckbody(state,action) {
  4. let res = Object.assign({},state);
  5. const {data} = action;
  6. res.preData = data;
  7. return res;
  8. }
  9. //设置查体数据
  10. export function set(state,action){
  11. let res = Object.assign({},state);
  12. const {data,isText,isEmpty} = action;
  13. if(isText){ //查体只显示文本时(引用预问诊)
  14. const label = Object.assign(JSON.parse(config.textLabel),{value:data,noSearch:true});
  15. res.data = [label];
  16. res.saveText = [data];
  17. res.showAll = true;
  18. res.update = Math.random();
  19. res.isEmpty = isEmpty;
  20. return res;
  21. }
  22. const obj = checkFullfillText(data);
  23. res.data = obj.newArr;
  24. res.saveText = obj.saveText;//存逗号
  25. res.showAll = obj.checkHiddenDefault;
  26. res.update = Math.random();
  27. res.isEmpty = isEmpty;
  28. return res;
  29. }
  30. //多选标签选中确定处理
  31. export const confirm = (state,action) =>{
  32. let res = Object.assign({},state);
  33. let arr = res.data;
  34. const {nones,exists,withs,ikey,exclusion,excluName,copyType} = action.data;
  35. const items = [...exists||[],...withs||[]];
  36. if((!exists||!withs||items.length==0)&&!nones&&!exclusion){ //取消无殊的选中,空白提交
  37. arr[ikey].value = '';
  38. res.saveText[ikey] = '';
  39. res.selecteds.splice(ikey,1);
  40. res.update=Math.random();
  41. return res;
  42. }
  43. //选中互斥项
  44. if(exclusion){
  45. arr[ikey].value = excluName;
  46. res.saveText[ikey] = excluName;
  47. res.selecteds[ikey] = action.data;
  48. res.update=Math.random();
  49. return res;
  50. }
  51. //只有无的项目选中
  52. if(+copyType===0) { //原标签保留
  53. arr.splice(ikey,1);
  54. }
  55. if(arr[ikey].value) arr[ikey].value= '';
  56. let preText = arr[ikey-1].value!==undefined?arr[ikey-1].value:arr[ikey-1].name||'';
  57. let newPreText =preText +nones;//console.log(arr[ikey-1],newPreText)
  58. if(items.length==0&&nones){
  59. arr[ikey-1].value = newPreText;
  60. res.saveText[ikey-1] = newPreText;
  61. res.selecteds[ikey] = null; //无殊选中状态遗留bug修改
  62. res.update=Math.random();
  63. return res;
  64. }
  65. //有,伴,无随配
  66. //arr.splice(ikey-1,1);
  67. let flabel = items[items.length-1]; //要插入的最后一个标签
  68. let labelText = flabel.value!==undefined?flabel.value:flabel.name;
  69. let text = labelText;
  70. //要插入的最后一个标签为自由文本,则和后面的文本标签文字合并
  71. if(flabel.tagType==8){
  72. flabel.value = labelText+nones;
  73. text = flabel.value;
  74. }
  75. arr.splice(ikey,0,...exists,...withs);
  76. //arr[ikey-1].value = text;
  77. //res.saveText[ikey+items.length] = text;
  78. res.saveText = checkFullfillText(arr).saveText;
  79. res.update=Math.random(); //用于触发组件更新(data变化了因在对象中无法被组件检测到)
  80. return res;
  81. };
  82. //查体中数字键盘选中事件
  83. export function setNumberValue(state,action){
  84. let res = Object.assign({},state);
  85. const param = action.params;
  86. const ikey = param.ikey;
  87. let labelInx = getLabelIndex(ikey);
  88. // const subInx = ikey.substr(ikey.length-1);
  89. const subInx = ikey.split("-")[2];
  90. let item = res.data[labelInx];
  91. if(+item.tagType===1){ //独立数字键盘组件
  92. item.value = param.text;
  93. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  94. }else{ //内嵌血压类型组件的数字键盘组件
  95. item.questionMapping[subInx].value = param.text;
  96. let hasValue = false;
  97. const sub = item.questionMapping.map((it)=>{
  98. if(it.value){ //至少有一个子值才黑显
  99. hasValue = true;
  100. }
  101. if(it.tagType===8){
  102. return it.name;
  103. }else{
  104. if(!it.value){
  105. return '';
  106. }
  107. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  108. }
  109. });
  110. res.saveText[labelInx] = hasValue?sub.join(''):'';
  111. }
  112. // res.saveText = fullfillText(res.data).saveText;
  113. res.update = Math.random();
  114. return res;
  115. }
  116. //查体单选下拉选中
  117. export function setRadioValue(state,action){
  118. let res = Object.assign({},state);
  119. const {ikey,id,text} = action;
  120. let labelInx = getLabelIndex(ikey);
  121. const subInx = ikey.split("-")[2];
  122. let item = res.data[labelInx];
  123. if(typeof text != 'string'){ //需要展开项--有无治疗类型
  124. const len = +item.copyType === 0?1:0;
  125. res.data.splice(labelInx,len,text);
  126. return res;
  127. }
  128. if(+item.tagType===1){ //独立单选组件
  129. item.value = text;
  130. const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
  131. if(exist){ //选中状态处理
  132. exist[0].selected=exist[0].id==id;
  133. localStorage.setItem('radio'+item.id,JSON.stringify(exist));
  134. }
  135. item.questionDetailList.map((its)=>{
  136. if(its.id === id){
  137. its.selected = true;
  138. }else{
  139. its.selected = false;
  140. }
  141. });
  142. res.saveText[labelInx] = text; //单选没有前后缀
  143. }else{ //组合组件中的单选组件
  144. item.questionMapping[subInx].value = text;
  145. let hasValue = false;
  146. const sub = item.questionMapping.map((it)=>{
  147. //添加选中状态
  148. it.questionDetailList.map((its)=>{
  149. if(its.id === id){
  150. its.selected = true;
  151. }else{
  152. its.selected = false;
  153. }
  154. });
  155. if(it.value){ //至少有一个子值才黑显
  156. hasValue = true;
  157. }
  158. if(it.tagType===8){
  159. return it.name;
  160. }else {
  161. if(!it.value){
  162. return '';
  163. }
  164. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  165. }
  166. });
  167. res.saveText[labelInx] = hasValue?sub.join(''):'';
  168. }
  169. // res.saveText = fullfillText(res.data).saveText;
  170. res.update = Math.random();
  171. return res;
  172. }
  173. //复制标签(如血压)事件
  174. export function addLabelItem(state,action){
  175. let res = Object.assign({},state);
  176. const {data,i} = action;
  177. const textLabel = Object.assign({},JSON.parse(config._textLabel),{showInCheck:JSON.parse(data).showInCheck});
  178. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  179. if(!data) return res;
  180. res.data.splice(+i+2,0,JSON.parse(data),textLabel);
  181. res.saveText.splice(+i+2,0,'','');
  182. res.selecteds.splice(+i+2,0,null,null);
  183. res.update = Math.random();
  184. return res;
  185. }
  186. //自由文本
  187. export function setCheckText(state,action) {
  188. let res = Object.assign({},state);
  189. const {i,text} = action;
  190. if(res.data[i]){
  191. res.data[i].value=text;
  192. //res.data[i].name=''; //默认显示的文字
  193. }
  194. res.saveText[i] = text;
  195. res.update = Math.random();
  196. return res;
  197. }
  198. //多选文字,如杂音
  199. export function setCheckBoxValue(state,action) {
  200. let res = Object.assign({},state);
  201. const {labelInx,excluName,existsName,nones,withsName,ban} = action.data;
  202. let showText = (excluName||'')+(existsName||'')+(ban.name||'')+(withsName||'')+(nones&&nones.replace('、','')||'');
  203. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  204. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  205. if(pattern.test(showText)){
  206. showText = showText.substr(0,showText.length-1);
  207. }
  208. res.data[labelInx].value = showText;
  209. res.selecteds[labelInx] = action.data;
  210. res.saveText = checkFullfillText(res.data).saveText;
  211. res.update = Math.random();
  212. return res;
  213. }
  214. //搜索结果
  215. export function setSearchData(state,action){
  216. let res = Object.assign({},state);
  217. res.searchData = action.data;
  218. res.searchStr = action.inpStr;
  219. res.searchInEnd = action.isEnd;
  220. return res;
  221. }
  222. //插入标签数据-搜索
  223. export function insertLabelData(state,action){
  224. let res = Object.assign({},state);
  225. const searchStr = res.searchStr;
  226. const {index,data,isReplace,span,searchInEnd}=action;
  227. const showText = res.saveText[index];
  228. let tempLabels = data.tagType==4?checkFullfillText(data.questionMapping).newArr:[data];
  229. tempLabels = formatContinueDots(tempLabels);
  230. //查体中,默认显示区域搜索出来的标签要默认显示,隐藏区域搜索出的默认隐藏
  231. let hideAreaIndex = [...res.data].reverse().findIndex((it)=>it.showInCheck);
  232. hideAreaIndex = res.data.length-hideAreaIndex-1; //默认显示的最后一个标签的位置
  233. const text = Object.assign({},JSON.parse(config._textLabel),{showInCheck:index>hideAreaIndex?false:true});
  234. let spreadLabels =tempLabels.map((it)=>{
  235. return Object.assign({},it,{showInCheck:index>hideAreaIndex?false:true});
  236. });
  237. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  238. const newText=showText.replace(reg,'')||'';
  239. if(!isReplace){
  240. span.current.innerText?(span.current.innerText = newText):(span.current.innerHTML = newText);
  241. const pText = Object.assign({},text,{value:newText});
  242. if(searchInEnd){
  243. res.data.splice(index,1,pText,...spreadLabels,text);
  244. res.saveText = checkFullfillText(res.data).saveText;
  245. //res.saveText.splice(index,1,newText,'','');
  246. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  247. }else{
  248. res.data.splice(index,1,text,...spreadLabels,pText);
  249. res.saveText = checkFullfillText(res.data).saveText;
  250. //res.saveText.splice(index,1,'','',newText);
  251. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  252. }
  253. }else{
  254. span.current.innerText?(span.current.innerText = ' '):(span.current.innerHTML = ' ');
  255. if(searchInEnd){
  256. res.data.splice(index+1,0,spreadLabels,text);
  257. res.saveText.splice(index+1,0,'','');
  258. res.selecteds.splice(index+1,0,null,null);
  259. }else{
  260. res.data.splice(index,0,text,spreadLabels);
  261. res.saveText.splice(index,0,'','');
  262. res.selecteds.splice(index,0,null,null);
  263. }
  264. }
  265. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  266. res.update = Math.random();
  267. return res;
  268. }
  269. export const changeLabelVal = (state,action)=>{//双击标签输入改变值
  270. const res = Object.assign({},state);
  271. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  272. const index = ikey;
  273. const newVal = changeVal; //下拉修改的内容
  274. let labText = totalVal?totalVal:newVal; //如单选没有前后缀
  275. let item = res.data[index];
  276. const next = res.data[+index+1];
  277. const nextVal = next.value||next.name;
  278. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  279. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  280. // if(newVal && newVal.trim()){
  281. if(labText && labText.trim()){
  282. if(item){
  283. item.value = newVal;
  284. const canAdd=hasNoSame(item.questionDetailList,labText);
  285. //单选双击编辑的内容自动加到下拉选项中,双击编辑但未修改不添加
  286. if(canAdd&&+item.tagType===1&&(+item.controlType===1||+item.controlType===0)){
  287. const li = {
  288. id:-Math.floor(Math.random()*1000),
  289. name:labText,
  290. questionId:item.id,
  291. orderNo:0,
  292. code:0,
  293. defaultSelect:"0",
  294. remark:null,
  295. abnormal:0,
  296. selected:true
  297. };
  298. const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
  299. //console.log(exist)
  300. if(exist&&typeof exist=='object'){ //已添加过编辑的数据
  301. //exist.push(li);
  302. exist[0]=li; //暂限添1条
  303. localStorage.setItem('radio'+item.id,JSON.stringify(exist));
  304. }else{
  305. localStorage.setItem('radio'+item.id,JSON.stringify([li]));
  306. }
  307. //取消原选中状态
  308. item.questionDetailList.find((it)=>it.selected==true).selected=false;
  309. }
  310. item.labelPrefix = prefix||'';
  311. item.labelSuffix = suffix||'';
  312. // res.saveText[index] = totalVal;
  313. res.saveText[index] = labText;
  314. }
  315. }else{//删除完标签内容则删除该标签
  316. const num = nextIsDot?2:1;
  317. handleLocalDelTag('4',index,res.data[index]);
  318. res.data.splice(index,num);
  319. res.selecteds.splice(index,num);//杂音类样式选中状态对应
  320. res.saveText = checkFullfillText(res.data).saveText;
  321. }
  322. res.update = Math.random();
  323. return res;
  324. }
  325. function hasNoSame(arr,text){
  326. return arr.findIndex((it)=>text==it.name)==-1;
  327. }
  328. // 数字键盘较特殊,有直接输入
  329. export const changeNumLabelVal = (state,action)=>{
  330. const res = Object.assign({},state);
  331. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  332. const index = ikey;
  333. const newVal = changeVal;
  334. let item = res.data[index];
  335. const next = res.data[+index+1];
  336. const next2 = res.data[+index + 2];
  337. const nextVal = next.value||next.name;
  338. //下一个非文本标签是数字组件
  339. const next2IsNum = +next2.tagType === 1 && +next2.controlType === 7;
  340. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  341. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  342. if(totalVal.trim()){
  343. if(item){
  344. item.value = newVal;
  345. item.labelPrefix = prefix||'';
  346. item.labelSuffix = suffix||'';
  347. }
  348. if(newVal){
  349. res.saveText[index] = totalVal;
  350. }else{
  351. res.saveText[index] = "";
  352. }
  353. }else{//删除完标签内容则删除该标签
  354. let num = nextIsDot ? 2 : 1;
  355. if (nextIsDot && next2IsNum) { //解决连续2个相同的数字组件删除第一个,第二个显示异常bug--临时方案
  356. next.value = '';
  357. num = 1;
  358. }
  359. res.data.splice(index,num);
  360. res.selecteds.splice(index,num); //杂音类样式选中状态对应
  361. res.saveText = checkFullfillText(res.data).saveText;
  362. }
  363. res.update = Math.random();
  364. return res;
  365. }
  366. export function clearCheckBody(state,action){ //清空
  367. let res = Object.assign({},state);
  368. res.data = action.data;
  369. res.preData = [];
  370. res.saveText = action.saveText;
  371. res.isEmpty = action.isEmpty;
  372. res.selecteds = action.selecteds?action.selecteds:[];
  373. if(action.flg){res.showAll = true}
  374. return res;
  375. }
  376. //文本输入标签
  377. export function setInputLabel(state,action){
  378. let res = Object.assign({}, state);
  379. const {i,text,prefix,suffix,subIndex} = action;
  380. const item = res.data[i];
  381. if(+item.tagType===3){ //multSpred标签
  382. item.questionMapping[subIndex].value = text;
  383. let texts = item.questionMapping.map((it)=>{
  384. if(it.tagType===8){
  385. return it.name;
  386. }else{
  387. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  388. }
  389. });
  390. res.saveText[i] = texts.join('');
  391. res.update = Math.random();
  392. return res;
  393. }else{
  394. if(item){
  395. item.value=text;
  396. }
  397. }
  398. if(text){
  399. res.saveText[i] = prefix+text+suffix;
  400. }else{//删除完要清空
  401. res.saveText[i] = "";
  402. }
  403. res.update = Math.random();
  404. return res;
  405. }
  406. // backspace删除
  407. export function backspaceText(state,action){
  408. let res = Object.assign({},state);
  409. const {delIndex,flag} = action;
  410. const data = res.data;
  411. if(flag == 'backsp'){
  412. // 前一个是文本标签或者子模板,只改变值
  413. if(data[delIndex-1].flag&&data[delIndex-1].flag==3){//子模板不删
  414. // data[delIndex].value = text;
  415. }else if(data[delIndex-1].tagType==8){
  416. data.splice(delIndex,1);
  417. res.selecteds.splice(delIndex,1); //杂音类样式选中状态对应
  418. res.saveText.splice(delIndex,1);
  419. }
  420. else{
  421. handleLocalDelTag(4,delIndex-1,data[delIndex-1]);
  422. data.splice(delIndex-1,2);
  423. res.selecteds.splice(delIndex-1,2);
  424. res.saveText.splice(delIndex-1,2);
  425. }
  426. }else if(flag == 'del'){
  427. if(data[delIndex+1] && data[delIndex+1].flag&&data[delIndex+1].flag==3){//子模板不删
  428. }else if(data[delIndex+1] && data[delIndex+1].tagType==8){
  429. data.splice(delIndex,1);
  430. res.selecteds.splice(delIndex,1); //杂音类样式选中状态对应
  431. res.saveText.splice(delIndex,1);
  432. }else if(!data[delIndex+1]){//最后一个文本标签不删除
  433. }
  434. else{
  435. handleLocalDelTag(4,delIndex,data[delIndex+1]);
  436. data.splice(delIndex,2);
  437. res.selecteds.splice(delIndex,2);
  438. res.saveText.splice(delIndex,2);
  439. }
  440. }
  441. // res.saveText = fullfillText(data).saveText;
  442. res.update = Math.random();
  443. return res;
  444. }
  445. // 单列多选
  446. export function multipleComfirn(state,action){
  447. let res = Object.assign({},state);
  448. const {ikey,seleData,fullIkey} = action.data;
  449. let data = res.data;//console.log(action,data[ikey])
  450. let index = fullIkey.substr(fullIkey.length-1,1);
  451. if(data[ikey].tagType==3){ //在组合项中
  452. let item = data[ikey].questionMapping;
  453. let arr=[];
  454. item[index].value = seleData;
  455. item.map((it)=>{
  456. if(it.value){
  457. arr.push(it.labelPrefix+it.value+it.labelSuffix);
  458. }
  459. });
  460. res.saveText[ikey] = arr.join("");
  461. res.update = Math.random();
  462. res.selecteds[ikey] = {[index]:action.data};
  463. return res;
  464. }
  465. data[ikey].value = seleData;
  466. res.saveText[ikey] = seleData;
  467. res.selecteds[ikey] = action.data;
  468. res.update = Math.random();
  469. return res;
  470. }
  471. export function delSingleLable(state,action){
  472. let res = Object.assign({},state);
  473. const {index} = action;
  474. let data = res.data;
  475. // 前一个不是文本标签 并且不是子模板,则删除
  476. if(data[index-1].flag&&data[index-1].flag==3){
  477. }
  478. else if(data[index-1].tagType != 8){
  479. data.splice(index-1,1);
  480. res.saveText.splice(index-1,1);
  481. }
  482. res.update = Math.random();
  483. return res;
  484. }
  485. //查体推送高亮标签
  486. export function setImportCheckbodyLabel(state,action) {
  487. let res = Object.assign({},state);
  488. res.importLabel = action.labels;
  489. res.update = Math.random();
  490. return res;
  491. }
  492. //恢复已删除的标签
  493. export function recoveTag(state,action) {
  494. let res = Object.assign({},state);
  495. let arr = [...res.data];
  496. //const text = Object.assign({showInCheck:action.data.showInCheck},JSON.parse(config._textLabel));
  497. arr.splice(action.index,0,action.data);
  498. res.data = checkFullfillText(arr).newArr;
  499. res.saveText = checkFullfillText(arr).saveText;
  500. shiftLocalDelTag();
  501. res.update = Math.random();
  502. return res;
  503. }