otherHistory.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. import config from '@config/index';
  2. import {formatContinueDots,getLabelIndex,fullfillText,handleLocalDelTag,shiftLocalDelTag} from '@utils/tools.js';
  3. //多选标签选中确定处理
  4. export const confirm = (state,action) =>{
  5. let res = Object.assign({},state);
  6. let arr = res.data;
  7. const {nones,exists,withs,ikey,exclusion,excluName,copyType} = action.data;
  8. const items = [...exists||[],...withs||[]];
  9. if((!exists||!withs||items.length==0)&&!nones&&!exclusion){ //取消无殊的选中,空白提交
  10. arr[ikey].value = '';
  11. res.saveText[ikey] = '';
  12. res.selecteds.splice(ikey,1);
  13. res.update=Math.random();
  14. return res;
  15. }
  16. //选中互斥项
  17. if(exclusion){
  18. arr[ikey].value = excluName;
  19. res.saveText[ikey] = excluName;
  20. res.selecteds[ikey] = action.data;
  21. res.update=Math.random();
  22. return res;
  23. }
  24. //只有无的项目选中
  25. if(+copyType===0) { //原标签保留
  26. arr.splice(ikey,1);
  27. }
  28. if(arr[ikey].value) arr[ikey].value= '';
  29. let preText = arr[ikey-1].value!==undefined?arr[ikey-1].value:arr[ikey-1].name||'';
  30. let newPreText =preText +nones;//console.log(arr[ikey-1],newPreText)
  31. if(items.length==0&&nones){
  32. arr[ikey-1].value = newPreText;
  33. res.saveText[ikey-1] = newPreText;
  34. res.selecteds[ikey] = null; //无殊选中状态遗留bug修改
  35. res.update=Math.random();
  36. return res;
  37. }
  38. //有,伴,无随配
  39. let flabel = items[items.length-1]; //要插入的最后一个标签
  40. let labelText = flabel.value!==undefined?flabel.value:flabel.name;
  41. let text = labelText;
  42. //要插入的最后一个标签为自由文本,则和后面的文本标签文字合并
  43. if(flabel.tagType==8){
  44. flabel.value = labelText+nones;
  45. text = flabel.value;
  46. }
  47. arr.splice(ikey,0,...exists,...withs);
  48. res.saveText = fullfillText(arr).saveText;
  49. res.update=Math.random(); //用于触发组件更新(data变化了因在对象中无法被组件检测到)
  50. return res;
  51. };
  52. //自由文本
  53. export function setCheckText(state,action) {
  54. let res = Object.assign({},state);
  55. const {i,text} = action;
  56. if(res.data[i]){
  57. res.data[i].value=text;
  58. //res.data[i].name=''; //默认显示的文字
  59. }
  60. res.saveText[i] = text;
  61. res.update = Math.random();
  62. return res;
  63. }
  64. //多选文字,如杂音
  65. export function setCheckBoxValue(state,action) {
  66. const res = Object.assign({},state);
  67. const {labelInx,excluName,existsName,nones,withsName,ban} = action.data;
  68. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  69. let showText = (excluName||'')+(existsName||'')+(ban.name||'')+(withsName||'')+(nones&&nones.replace('、','')||'');
  70. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  71. if(pattern.test(showText)){
  72. showText = showText.substr(0,showText.length-1);
  73. }
  74. res.data[labelInx].value = showText;
  75. res.saveText[labelInx] = showText;
  76. res.selecteds[labelInx] = action.data;
  77. res.update=Math.random();
  78. return res;
  79. }
  80. //搜索结果
  81. export function setSearchData(state,action){
  82. let res = Object.assign({},state);
  83. res.searchData = action.data;
  84. res.searchStr = action.inpStr;
  85. res.searchInEnd = action.isEnd;
  86. return res;
  87. }
  88. //插入标签数据-搜索
  89. export function insertLabelData(state,action){
  90. let res = Object.assign({},state);
  91. const text = Object.assign({},JSON.parse(config.textLabel));
  92. const searchStr = res.searchStr;
  93. const {index,data,isReplace,span,searchInEnd}=action;
  94. const showText = res.saveText[index];
  95. let searchLabels = data.tagType==4?fullfillText(data.questionMapping).newArr:[data];
  96. const spreadLabels = formatContinueDots(searchLabels);
  97. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  98. const newText=showText.replace(reg,'')||' ';
  99. if(!isReplace){
  100. span.current.innerText?(span.current.innerText = newText):(span.current.innerHTML = newText);
  101. const pText = Object.assign({},text,{value:newText});
  102. if(searchInEnd){
  103. res.data.splice(index,1,pText,...spreadLabels,text);
  104. res.saveText = fullfillText(res.data).saveText;
  105. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  106. //res.saveText.splice(index,1,newText,'','');
  107. }else{
  108. res.data.splice(index,1,...spreadLabels,pText,text);
  109. res.saveText = fullfillText(res.data).saveText;//.splice(index,1,'',newText,'');
  110. res.selecteds.splice(index,1,...new Array(spreadLabels.length).fill(null),null,null);
  111. }
  112. }else{
  113. span.current.innerText?(span.current.innerText = ' '):(span.current.innerHTML = ' ');
  114. if(searchInEnd){
  115. res.data.splice(index+1,0,spreadLabels,text);
  116. res.saveText.splice(index+1,0,'','');
  117. res.selecteds.splice(index+1,0,...new Array(spreadLabels.length).fill(null),null);
  118. }else{
  119. res.data.splice(index,0,text,spreadLabels);
  120. res.saveText.splice(index,0,'','');
  121. res.selecteds.splice(index,0,null,...new Array(spreadLabels.length).fill(null));
  122. }
  123. }
  124. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  125. res.update = Math.random();
  126. return res;
  127. }
  128. export function changeTextLabel(state,action) {
  129. const res = Object.assign({},state);
  130. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  131. const index = ikey;
  132. const newVal = changeVal;
  133. let item = res.data[index];
  134. const next = res.data[+index+1];
  135. const nextVal = next.value||next.name;
  136. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  137. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  138. let labText = totalVal?totalVal:newVal;
  139. if(labText.trim()){
  140. if(item){
  141. item.value = newVal;
  142. //月经史特殊处理
  143. if(item.formulaCode){
  144. res[item.formulaCode] = newVal;
  145. }
  146. const canAdd=hasNoSame(item.questionDetailList,labText);
  147. //单选双击编辑的内容自动加到下拉选项中,双击编辑但未修改不添加
  148. if(canAdd&&+item.tagType===1&&(+item.controlType===1||+item.controlType===0)){
  149. const li = {
  150. id:-Math.floor(Math.random()*1000),
  151. name:labText,
  152. questionId:item.id,
  153. orderNo:0,
  154. code:0,
  155. defaultSelect:"0",
  156. remark:null,
  157. abnormal:0,
  158. selected:true
  159. };
  160. const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
  161. //console.log(exist)
  162. if(exist&&typeof exist=='object'){ //已添加过编辑的数据
  163. //exist.push(li);
  164. exist[0]=li; //暂限添1条
  165. localStorage.setItem('radio'+item.id,JSON.stringify(exist));
  166. }else{
  167. localStorage.setItem('radio'+item.id,JSON.stringify([li]));
  168. }
  169. //取消原选中状态
  170. item.questionDetailList.find((it)=>it.selected==true).selected=false;
  171. }
  172. item.labelPrefix = prefix||'';
  173. item.labelSuffix = suffix||'';
  174. res.saveText[index] = labText;
  175. }
  176. }else{//删除完标签内容则删除该标签
  177. const num = nextIsDot?2:1;
  178. handleLocalDelTag('3',index,res.data[index]);
  179. //月经史特殊处理
  180. if(res.data[index].formulaCode){
  181. res[res.data[index].formulaCode]=undefined;
  182. }
  183. res.data.splice(index,num);
  184. res.selecteds.splice(index,num);//杂音类样式选中状态对应
  185. res.saveText = fullfillText(res.data).saveText;
  186. }
  187. res.update = Math.random();//console.log(888,res,action);
  188. return res;
  189. }
  190. function hasNoSame(arr,text){
  191. return arr.findIndex((it)=>text==it.name)==-1;
  192. }
  193. export function clearOtherHistory(state,action){ //清空数据
  194. let res = Object.assign({},state);
  195. for(let it in action){
  196. if(it!='type'){
  197. res[it] = action[it];
  198. }
  199. }
  200. /*res.data = action.data;
  201. res.saveText = action.saveText;
  202. res.selecteds = action.selecteds;
  203. res.editClear = action.editClear;
  204. res.isEmpty = action.isEmpty;*/
  205. return res;
  206. }
  207. //文本模式下值保存
  208. export const setTextModeValue = (state,action)=>{
  209. const res = Object.assign({},state);
  210. res.saveText[0] = action.text;
  211. return res;
  212. };
  213. //数字键盘选中事件
  214. export function setNumberValue(state,action){
  215. let res = Object.assign({},state);
  216. const param = action.params;
  217. const ikey = param.ikey;
  218. const code = param.formulaCode;
  219. let labelInx = getLabelIndex(ikey);
  220. const subInx = ikey.substr(ikey.length-1);
  221. let item = res.data[labelInx];
  222. if(+item.tagType===1){
  223. item.value = param.text;
  224. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  225. }else{
  226. item.questionMapping[subInx].value = param.text;
  227. let hasValue = false;
  228. const sub = item.questionMapping.map((it)=>{
  229. if(it.value){ //至少有一个子值才黑显
  230. hasValue = true;
  231. }
  232. if(it.tagType===8){ //维护时的连接词无value
  233. return it.name;
  234. }else{
  235. //组合中未填值的子标签预览中不显示
  236. if(!it.value){
  237. return '';
  238. }
  239. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  240. }
  241. });
  242. res.saveText[labelInx] = hasValue?sub.join(''):'';
  243. }
  244. res[code] = param.text;
  245. res.update = Math.random();
  246. return res;
  247. }
  248. export const otherEditClear = (state,action)=>{
  249. const res = Object.assign({},state);
  250. res.editClear = action.bool;
  251. return res;
  252. };
  253. // backspace删除
  254. export function backspaceText(state,action){
  255. let res = Object.assign({},state);
  256. const {delIndex,flag} = action;
  257. const data = res.data;
  258. if(flag == 'backsp'){
  259. if(data[delIndex-1].flag&&data[delIndex-1].flag==3){
  260. // if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  261. // 前一个是文本标签或者子模板 不做处理
  262. }else if(data[delIndex-1].tagType==8){
  263. data.splice(delIndex,1);
  264. res.selecteds.splice(delIndex,1); //杂音类样式选中状态对应
  265. res.saveText.splice(delIndex,1);
  266. }
  267. else{
  268. //月经史删除处理
  269. if(data[delIndex-1].formulaCode){
  270. res[data[delIndex-1].formulaCode]=undefined;
  271. }
  272. handleLocalDelTag(3,delIndex-1,data[delIndex-1]); //记录被删除的标签
  273. data.splice(delIndex-1,action.text.length>0?1:2);
  274. res.selecteds.splice(delIndex-1,action.text.length>0?1:2); //杂音类样式选中状态对应
  275. res.saveText.splice(delIndex-1,action.text.length>0?1:2);
  276. }
  277. }else if(flag == 'del'){
  278. if(data[delIndex+1] && data[delIndex+1].flag&&data[delIndex+1].flag==3){//子模板不删
  279. }else if(data[delIndex+1] && data[delIndex+1].tagType==8){
  280. data.splice(delIndex,1);
  281. res.selecteds.splice(delIndex,1); //杂音类样式选中状态对应
  282. res.saveText.splice(delIndex,1);
  283. }else if(!data[delIndex+1]){//最后一个文本标签不删除
  284. }
  285. else{
  286. //月经史删除处理
  287. if(data[delIndex+1] &&data[delIndex+1].formulaCode){
  288. res[data[delIndex+1].formulaCode]=undefined;
  289. }
  290. handleLocalDelTag(3,delIndex,data[delIndex+1]);
  291. data.splice(delIndex,2);
  292. res.selecteds.splice(delIndex,2);
  293. res.saveText.splice(delIndex,2);
  294. }
  295. }
  296. // res.saveText = fullfillText(data).saveText;
  297. res.update = Math.random();
  298. return res;
  299. }
  300. //删除后移除空标签
  301. export function removeId(state,action){
  302. let res = Object.assign({},state);
  303. const {index,flag} = action;
  304. const data = res.data;
  305. if(flag == 'del'){//delete
  306. if(!data[index].value && data[index+1] && data[index+1].tagType==8){
  307. data.splice(index,1);
  308. res.saveText.splice(index,1);
  309. }
  310. }else{ //backspace
  311. if(!data[index].value && data[index-1].tagType==8){
  312. data.splice(index,1);
  313. res.saveText.splice(index,1);
  314. }
  315. }
  316. res.update = Math.random();
  317. return res;
  318. }
  319. // 单列多选
  320. export function multipleComfirn(state,action){
  321. let res = Object.assign({},state);
  322. const {ikey,seleData,fullIkey} = action.data;
  323. let data = res.data;//console.log(action,data[ikey])
  324. let index = fullIkey.substr(fullIkey.length-1,1);
  325. if(data[ikey].tagType==3){ //在组合项中
  326. let item = data[ikey].questionMapping;
  327. let arr=[];
  328. item[index].value = seleData;
  329. item.map((it)=>{
  330. if(it.value){
  331. arr.push(it.labelPrefix+it.value+it.labelSuffix);
  332. }
  333. });
  334. res.saveText[ikey] = arr.join("");
  335. res.update = Math.random();
  336. res.selecteds[ikey] = {[index]:action.data};
  337. return res;
  338. }
  339. data[ikey].value = seleData;
  340. res.saveText[ikey] = seleData;
  341. res.selecteds[ikey] = action.data;
  342. return res;
  343. }
  344. export function delSingleLable(state,action){
  345. let res = Object.assign({},state);
  346. const {index} = action;
  347. let data = res.data;
  348. // 前一个不是文本标签 并且不是子模板,则删除
  349. if(data[index-1].flag&&data[index-1].flag==3){
  350. }
  351. else if(data[index-1].tagType != 8){
  352. data.splice(index-1,1);
  353. res.saveText.splice(index-1,1);
  354. }
  355. res.update = Math.random();
  356. return res;
  357. }