checkBody.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import config from '@config/index.js';
  2. import {formatContinueDots,getLabelIndex,handleLocalDelTag,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,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 setCheckBoxValue(state,action) {
  84. let res = Object.assign({},state);
  85. const {labelInx,excluName,existsName,nones,withsName,ban} = action.data;
  86. let showText = (excluName||'')+(existsName||'')+(ban.name||'')+(withsName||'')+(nones&&nones.replace('、','')||'');
  87. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  88. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  89. if(pattern.test(showText)){
  90. showText = showText.substr(0,showText.length-1);
  91. }
  92. res.data[labelInx].value = showText;
  93. res.selecteds[labelInx] = action.data;
  94. res.saveText = checkFullfillText(res.data).saveText;
  95. res.update = Math.random();
  96. return res;
  97. }
  98. //搜索结果
  99. export function setSearchData(state,action){
  100. let res = Object.assign({},state);
  101. res.searchData = action.data;
  102. res.searchStr = action.inpStr;
  103. res.searchInEnd = action.isEnd;
  104. return res;
  105. }
  106. //插入标签数据-搜索
  107. export function insertLabelData(state,action){
  108. let res = Object.assign({},state);
  109. const searchStr = res.searchStr;
  110. const {index,data,isReplace,span,searchInEnd}=action;
  111. const showText = res.saveText[index];
  112. let tempLabels = data.tagType==4?checkFullfillText(data.questionMapping).newArr:[data];
  113. tempLabels = formatContinueDots(tempLabels);
  114. //查体中,默认显示区域搜索出来的标签要默认显示,隐藏区域搜索出的默认隐藏
  115. let hideAreaIndex = [...res.data].reverse().findIndex((it)=>it.showInCheck);
  116. hideAreaIndex = res.data.length-hideAreaIndex-1; //默认显示的最后一个标签的位置
  117. const text = Object.assign({},JSON.parse(config._textLabel),{showInCheck:index>hideAreaIndex?false:true});
  118. let spreadLabels =tempLabels.map((it)=>{
  119. return Object.assign({},it,{showInCheck:index>hideAreaIndex?false:true});
  120. });
  121. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  122. const newText=showText.replace(reg,'')||'';
  123. if(!isReplace){
  124. span.current.innerText?(span.current.innerText = newText):(span.current.innerHTML = newText);
  125. const pText = Object.assign({},text,{value:newText});
  126. if(searchInEnd){
  127. res.data.splice(index,1,pText,...spreadLabels,text);
  128. res.saveText = checkFullfillText(res.data).saveText;
  129. //res.saveText.splice(index,1,newText,'','');
  130. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  131. }else{
  132. res.data.splice(index,1,text,...spreadLabels,pText);
  133. res.saveText = checkFullfillText(res.data).saveText;
  134. //res.saveText.splice(index,1,'','',newText);
  135. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  136. }
  137. }else{
  138. span.current.innerText?(span.current.innerText = ' '):(span.current.innerHTML = ' ');
  139. if(searchInEnd){
  140. res.data.splice(index+1,0,spreadLabels,text);
  141. res.saveText.splice(index+1,0,'','');
  142. res.selecteds.splice(index+1,0,null,null);
  143. }else{
  144. res.data.splice(index,0,text,spreadLabels);
  145. res.saveText.splice(index,0,'','');
  146. res.selecteds.splice(index,0,null,null);
  147. }
  148. }
  149. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  150. res.update = Math.random();
  151. return res;
  152. }
  153. export const changeLabelVal = (state,action)=>{//双击标签输入改变值
  154. const res = Object.assign({},state);
  155. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  156. const index = ikey;
  157. const newVal = changeVal; //下拉修改的内容
  158. let labText = totalVal?totalVal:newVal; //如单选没有前后缀
  159. let item = res.data[index];
  160. const next = res.data[+index+1];
  161. const nextVal = next.value||next.name;
  162. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  163. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  164. // if(newVal && newVal.trim()){
  165. if(labText && labText.trim()){
  166. if(item){
  167. item.value = newVal;
  168. const canAdd=hasNoSame(item.questionDetailList,labText);
  169. //单选双击编辑的内容自动加到下拉选项中,双击编辑但未修改不添加
  170. if(canAdd&&+item.tagType===1&&(+item.controlType===1||+item.controlType===0)){
  171. const li = {
  172. id:-Math.floor(Math.random()*1000),
  173. name:labText,
  174. questionId:item.id,
  175. orderNo:0,
  176. code:0,
  177. defaultSelect:"0",
  178. remark:null,
  179. abnormal:0,
  180. selected:true
  181. };
  182. const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
  183. //console.log(exist)
  184. if(exist&&typeof exist=='object'){ //已添加过编辑的数据
  185. //exist.push(li);
  186. exist[0]=li; //暂限添1条
  187. localStorage.setItem('radio'+item.id,JSON.stringify(exist));
  188. }else{
  189. localStorage.setItem('radio'+item.id,JSON.stringify([li]));
  190. }
  191. //取消原选中状态
  192. item.questionDetailList.find((it)=>it.selected==true).selected=false;
  193. }
  194. item.labelPrefix = prefix||'';
  195. item.labelSuffix = suffix||'';
  196. // res.saveText[index] = totalVal;
  197. res.saveText[index] = labText;
  198. }
  199. }else{//删除完标签内容则删除该标签
  200. const num = nextIsDot?2:1;
  201. handleLocalDelTag('4',index,res.data[index]);
  202. res.data.splice(index,num);
  203. res.selecteds.splice(index,num);//杂音类样式选中状态对应
  204. res.saveText = checkFullfillText(res.data).saveText;
  205. }
  206. res.update = Math.random();
  207. return res;
  208. }
  209. function hasNoSame(arr,text){
  210. return arr.findIndex((it)=>text==it.name)==-1;
  211. }
  212. export function clearCheckBody(state,action){ //清空
  213. let res = Object.assign({},state);
  214. res.data = action.data;
  215. res.preData = [];
  216. res.saveText = action.saveText;
  217. res.isEmpty = action.isEmpty;
  218. res.selecteds = action.selecteds?action.selecteds:[];
  219. if(action.flg){res.showAll = true}
  220. return res;
  221. }
  222. // backspace删除
  223. export function backspaceText(state,action){
  224. let res = Object.assign({},state);
  225. const {delIndex,flag} = action;
  226. const data = res.data;
  227. if(flag == 'backsp'){
  228. // 前一个是文本标签或者子模板,只改变值
  229. if(data[delIndex-1].flag&&data[delIndex-1].flag==3){//子模板不删
  230. // data[delIndex].value = text;
  231. }else if(data[delIndex-1].tagType==8){
  232. data.splice(delIndex,1);
  233. res.selecteds.splice(delIndex,1); //杂音类样式选中状态对应
  234. res.saveText.splice(delIndex,1);
  235. }
  236. else{
  237. handleLocalDelTag(4,delIndex-1,data[delIndex-1]);
  238. data.splice(delIndex-1,2);
  239. res.selecteds.splice(delIndex-1,2);
  240. res.saveText.splice(delIndex-1,2);
  241. }
  242. }else if(flag == 'del'){
  243. if(data[delIndex+1] && data[delIndex+1].flag&&data[delIndex+1].flag==3){//子模板不删
  244. }else if(data[delIndex+1] && data[delIndex+1].tagType==8){
  245. data.splice(delIndex,1);
  246. res.selecteds.splice(delIndex,1); //杂音类样式选中状态对应
  247. res.saveText.splice(delIndex,1);
  248. }else if(!data[delIndex+1]){//最后一个文本标签不删除
  249. }
  250. else{
  251. handleLocalDelTag(4,delIndex,data[delIndex+1]);
  252. data.splice(delIndex,2);
  253. res.selecteds.splice(delIndex,2);
  254. res.saveText.splice(delIndex,2);
  255. }
  256. }
  257. // res.saveText = fullfillText(data).saveText;
  258. res.update = Math.random();
  259. return res;
  260. }
  261. // 单列多选
  262. export function multipleComfirn(state,action){
  263. let res = Object.assign({},state);
  264. const {ikey,seleData,fullIkey} = action.data;
  265. let data = res.data;//console.log(action,data[ikey])
  266. let index = fullIkey.substr(fullIkey.length-1,1);
  267. if(data[ikey].tagType==3){ //在组合项中
  268. let item = data[ikey].questionMapping;
  269. let arr=[];
  270. item[index].value = seleData;
  271. item.map((it)=>{
  272. if(it.value){
  273. arr.push(it.labelPrefix+it.value+it.labelSuffix);
  274. }
  275. });
  276. res.saveText[ikey] = arr.join("");
  277. res.update = Math.random();
  278. res.selecteds[ikey] = {[index]:action.data};
  279. return res;
  280. }
  281. data[ikey].value = seleData;
  282. res.saveText[ikey] = seleData;
  283. res.selecteds[ikey] = action.data;
  284. res.update = Math.random();
  285. return res;
  286. }
  287. export function delSingleLable(state,action){
  288. let res = Object.assign({},state);
  289. const {index} = action;
  290. let data = res.data;
  291. // 前一个不是文本标签 并且不是子模板,则删除
  292. if(data[index-1].flag&&data[index-1].flag==3){
  293. }
  294. else if(data[index-1].tagType != 8){
  295. data.splice(index-1,1);
  296. res.saveText.splice(index-1,1);
  297. }
  298. res.update = Math.random();
  299. return res;
  300. }
  301. //查体推送高亮标签
  302. export function setImportCheckbodyLabel(state,action) {
  303. let res = Object.assign({},state);
  304. res.importLabel = action.labels;
  305. res.update = Math.random();
  306. return res;
  307. }