checkBody.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 = [...data];
  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. res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
  108. item.questionDetailList.map((its)=>{
  109. if(its.id === id){
  110. its.selected = true;
  111. }else{
  112. its.selected = false;
  113. }
  114. });
  115. }else{ //组合组件中的单选组件
  116. item.questionMapping[subInx].value = text;
  117. let hasValue = false;
  118. const sub = item.questionMapping.map((it)=>{
  119. //添加选中状态
  120. it.questionDetailList.map((its)=>{
  121. if(its.id === id){
  122. its.selected = true;
  123. }else{
  124. its.selected = false;
  125. }
  126. });
  127. if(it.value){ //至少有一个子值才黑显
  128. hasValue = true;
  129. }
  130. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  131. });
  132. res.saveText[labelInx] = hasValue?sub.join(''):'';
  133. }
  134. // res.saveText = fullfillText(res.data).saveText;
  135. res.update = Math.random();
  136. return res;
  137. }
  138. //单选带输入值保存
  139. export const setRadioInputValue = (state,action)=>{
  140. const res = Object.assign({},state);
  141. const {ikey,values,id} = action.data;
  142. let index = getLabelIndex(ikey);
  143. let innerInx = ikey.substr(ikey.length-1);
  144. let item = res.data[index];
  145. if(item.tagType==3){ //在组合项中
  146. item = res.data[index].questionMapping[innerInx];
  147. }
  148. let str='',temp='',obj=item.questionDetailList;
  149. if(!values){ //清空
  150. let sld=obj.find((item)=>{
  151. return item.selected==true;
  152. });
  153. sld?sld.selected=false:'';
  154. item.vals = null;
  155. item.value = '';
  156. if(res.data[index].tagType==3){
  157. let hasValue = false;
  158. const sub = res.data[index].questionMapping.map((it)=>{
  159. if(it.value){ //至少有一个子值才黑显
  160. hasValue = true;
  161. }
  162. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  163. });
  164. res.saveText[index] = hasValue?sub.join(''):'';
  165. }else{
  166. res.saveText[index] = '';
  167. }
  168. res.update = Math.random();
  169. return res;
  170. }
  171. for(let i in values){
  172. temp = values[i];
  173. if(typeof temp=='object'){
  174. str+=temp.value;
  175. }else{
  176. str+=temp;
  177. }
  178. }
  179. //选中状态
  180. if(id){
  181. obj.map((its)=>{
  182. if(its.id === id){
  183. its.selected = true;
  184. }else{
  185. its.selected = false;
  186. }
  187. });
  188. }
  189. item.vals = values;
  190. item.value = str;
  191. if(res.data[index].tagType==3){
  192. let hasValue = false;
  193. const sub = res.data[index].questionMapping.map((it)=>{
  194. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  195. });
  196. res.saveText[index] = sub.join('');
  197. }else {
  198. res.saveText[ikey] = str;
  199. }
  200. res.update = Math.random();
  201. return res;
  202. }
  203. //复制标签(如血压)事件
  204. export function addLabelItem(state,action){
  205. let res = Object.assign({},state);
  206. const {data,i} = action;
  207. const textLabel = JSON.parse(config.textLabel);
  208. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  209. if(!data) return res;
  210. res.data.splice(+i+2,0,JSON.parse(data),textLabel);
  211. res.saveText.splice(+i+2,0,'','');
  212. res.selecteds.splice(+i+2,0,null,null);
  213. res.update = Math.random();
  214. return res;
  215. }
  216. //自由文本
  217. export function setCheckText(state,action) {
  218. let res = Object.assign({},state);
  219. const {i,text} = action;
  220. if(res.data[i]){
  221. res.data[i].value=text;
  222. //res.data[i].name=''; //默认显示的文字
  223. }
  224. res.saveText[i] = text;
  225. res.update = Math.random();
  226. return res;
  227. }
  228. //多选文字,如杂音
  229. export function setCheckBoxValue(state,action) {
  230. let res = Object.assign({},state);
  231. const {labelInx,excluName,existsName,nones,withsName,ban} = action.data;
  232. let showText = (excluName||'')+(existsName||'')+(ban.name||'')+(withsName||'')+(nones||'');
  233. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  234. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  235. if(pattern.test(showText)){
  236. showText = showText.substr(0,showText.length-1);
  237. }
  238. res.data[labelInx].value = showText;
  239. res.selecteds[labelInx] = action.data;
  240. res.saveText = fullfillText(res.data).saveText;
  241. res.update = Math.random();
  242. return res;
  243. }
  244. //搜索结果
  245. export function setSearchData(state,action){
  246. let res = Object.assign({},state);
  247. res.searchData = action.data;
  248. res.searchStr = action.inpStr;
  249. res.searchInEnd = action.isEnd;
  250. return res;
  251. }
  252. //插入标签数据-搜索
  253. export function insertLabelData(state,action){
  254. let res = Object.assign({},state);
  255. const searchStr = res.searchStr;
  256. const {index,data,isReplace,span,searchInEnd}=action;
  257. const showText = res.saveText[index];
  258. let tempLabels = data.tagType==4?fullfillText(data.questionMapping).newArr:[data];
  259. //查体中,默认显示区域搜索出来的标签要默认显示,隐藏区域搜索出的默认隐藏
  260. let hideAreaIndex = [...res.data].reverse().findIndex((it)=>it.showInCheck);
  261. hideAreaIndex = res.data.length-hideAreaIndex-1; //默认显示的最后一个标签的位置
  262. const text = Object.assign({},JSON.parse(config.textLabel),{showInCheck:index>hideAreaIndex?false:true});
  263. let spreadLabels =tempLabels.map((it)=>{
  264. return Object.assign({},it,{showInCheck:index>hideAreaIndex?false:true});
  265. });
  266. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  267. const newText=showText.replace(reg,'')||'';
  268. if(!isReplace){
  269. span.current.innerText?(span.current.innerText = newText):(span.current.innerHTML = newText);
  270. const pText = Object.assign({},text,{value:newText});
  271. if(searchInEnd){
  272. res.data.splice(index,1,pText,...spreadLabels,text);
  273. res.saveText = fullfillText(res.data).saveText;
  274. //res.saveText.splice(index,1,newText,'','');
  275. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  276. }else{
  277. res.data.splice(index,1,text,...spreadLabels,pText);
  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. }
  282. }else{
  283. span.current.innerText?(span.current.innerText = ' '):(span.current.innerHTML = ' ');
  284. if(searchInEnd){
  285. res.data.splice(index+1,0,spreadLabels,text);
  286. res.saveText.splice(index+1,0,'','');
  287. res.selecteds.splice(index+1,0,null,null);
  288. }else{
  289. res.data.splice(index,0,text,spreadLabels);
  290. res.saveText.splice(index,0,'','');
  291. res.selecteds.splice(index,0,null,null);
  292. }
  293. }
  294. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  295. res.update = Math.random();
  296. return res;
  297. }
  298. export const changeLabelVal = (state,action)=>{//双击标签输入改变值
  299. const res = Object.assign({},state);
  300. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  301. const index = ikey;
  302. const newVal = changeVal; //下拉修改的内容
  303. let labText = totalVal?totalVal:newVal; //如单选没有前后缀
  304. let item = res.data[index];
  305. const next = res.data[+index+1];
  306. const nextVal = next.value||next.name;
  307. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  308. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  309. // if(newVal && newVal.trim()){
  310. if(labText && labText.trim()){
  311. if(item){
  312. item.value = newVal;
  313. item.labelPrefix = prefix||'';
  314. item.labelSuffix = suffix||'';
  315. // res.saveText[index] = totalVal;
  316. res.saveText[index] = labText;
  317. }
  318. }else{//删除完标签内容则删除该标签
  319. const num = nextIsDot?2:1;
  320. res.data.splice(index,num);
  321. res.selecteds.splice(index,num);//杂音类样式选中状态对应
  322. res.saveText = fullfillText(res.data).saveText;
  323. }
  324. res.update = Math.random();
  325. return res;
  326. }
  327. // 数字键盘较特殊,有直接输入
  328. export const changeNumLabelVal = (state,action)=>{
  329. const res = Object.assign({},state);
  330. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  331. const index = ikey;
  332. const newVal = changeVal;
  333. let item = res.data[index];
  334. const next = res.data[+index+1];
  335. const nextVal = next.value||next.name;
  336. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  337. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  338. if(totalVal.trim()){
  339. if(item){
  340. item.value = newVal;
  341. item.labelPrefix = prefix||'';
  342. item.labelSuffix = suffix||'';
  343. }
  344. res.saveText[index] = totalVal;
  345. }else{//删除完标签内容则删除该标签
  346. const num = nextIsDot?2:1;
  347. res.data.splice(index,num);
  348. res.selecteds.splice(index,num); //杂音类样式选中状态对应
  349. res.saveText = fullfillText(res.data).saveText;
  350. }
  351. res.update = Math.random();
  352. return res;
  353. }
  354. export function clearCheckBody(state,action){ //清空
  355. let res = Object.assign({},state);
  356. res.data = action.data;
  357. res.saveText = action.saveText;
  358. res.isEmpty = action.isEmpty;
  359. res.selecteds = action.selecteds?action.selecteds:[];
  360. return res;
  361. }
  362. //文本输入标签
  363. export function setInputLabel(state,action){
  364. let res = Object.assign({},state);//console.log(state,action)
  365. const {i,text,prefix,suffix,subIndex} = action;
  366. const item = res.data[i];
  367. if(+item.tagType===3){ //multSpred标签
  368. item.questionMapping[subIndex].value = text;
  369. let texts = item.questionMapping.map((it)=>{
  370. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  371. });
  372. res.saveText[i] = texts.join('');
  373. res.update = Math.random();
  374. return res;
  375. }else{
  376. if(item){
  377. item.value=text;
  378. }
  379. }
  380. res.saveText[i] = prefix+text+suffix;//console.log(res)
  381. res.update = Math.random();
  382. return res;
  383. }
  384. // backspace删除
  385. export function backspaceText(state,action){
  386. let res = Object.assign({},state);
  387. const {delIndex} = action;
  388. const data = res.data;
  389. if(data[delIndex-1].flag&&data[delIndex-1].flag==3){
  390. // if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  391. // 前一个是文本标签或者子模板 不做处理
  392. }else if(data[delIndex-1].tagType==8){
  393. data.splice(delIndex,1);
  394. res.saveText.splice(delIndex,1);
  395. }
  396. else{
  397. data.splice(delIndex-1,2);
  398. res.saveText.splice(delIndex-1,2);
  399. }
  400. // res.saveText = fullfillText(data).saveText;
  401. res.update = Math.random();
  402. return res;
  403. }
  404. // 单列多选
  405. export function multipleComfirn(state,action){
  406. let res = Object.assign({},state);
  407. const {ikey,seleData,fullIkey} = action.data;
  408. let data = res.data;//console.log(action,data[ikey])
  409. let index = fullIkey.substr(fullIkey.length-1,1);
  410. if(data[ikey].tagType==3){ //在组合项中
  411. let item = data[ikey].questionMapping;
  412. let arr=[];
  413. item[index].value = seleData;
  414. item.map((it)=>{
  415. if(it.value){
  416. arr.push(it.labelPrefix+it.value+it.labelSuffix);
  417. }
  418. });
  419. res.saveText[ikey] = arr.join("");
  420. res.update = Math.random();
  421. res.selecteds[ikey] = {[index]:action.data};
  422. return res;
  423. }
  424. data[ikey].value = seleData;
  425. res.saveText[ikey] = seleData;
  426. res.selecteds[ikey] = action.data;
  427. res.update = Math.random();
  428. return res;
  429. }
  430. export function delSingleLable(state,action){
  431. let res = Object.assign({},state);
  432. const {index} = action;
  433. let data = res.data;
  434. // 前一个不是文本标签 并且不是子模板,则删除
  435. if(data[index-1].flag&&data[index-1].flag==3){
  436. }
  437. else if(data[index-1].tagType != 8){
  438. data.splice(index-1,1);
  439. res.saveText.splice(index-1,1);
  440. }
  441. res.update = Math.random();
  442. return res;
  443. }
  444. //查体推送高亮标签
  445. export function setImportCheckbodyLabel(state,action) {console.log(action)
  446. let res = Object.assign({},state);
  447. res.importLabel = action.labels;
  448. res.update = Math.random();
  449. return res;
  450. }