checkBody.js 18 KB

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