checkBody.js 16 KB

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