checkBody.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. res.data = [...data];
  8. res.saveText = fullfillText(res.data).saveText;//存逗号
  9. res.update = Math.random();
  10. res.isEmpty = false;
  11. return res;
  12. }
  13. //多选标签选中确定处理
  14. export const confirm = (state,action) =>{
  15. let res = Object.assign({},state);
  16. let arr = res.data;
  17. const {nones,exists,withs,ikey,exclusion,excluName,copyType} = action.data;
  18. const items = [...exists||[],...withs||[]];
  19. if((!exists||!withs||items.length==0)&&!nones&&!exclusion){ //取消无殊的选中,空白提交
  20. arr[ikey].value = '';
  21. res.saveText[ikey] = '';
  22. res.selecteds.splice(ikey,1);
  23. res.update=Math.random();
  24. return res;
  25. }
  26. //选中互斥项
  27. if(exclusion){
  28. arr[ikey].value = excluName;
  29. res.saveText[ikey] = excluName;
  30. res.selecteds[ikey] = action.data;
  31. res.update=Math.random();
  32. return res;
  33. }
  34. //只有无的项目选中
  35. if(+copyType===0) { //原标签保留
  36. arr.splice(ikey,1);
  37. }
  38. if(arr[ikey].value) arr[ikey].value= '';
  39. let preText = arr[ikey-1].value!==undefined?arr[ikey-1].value:arr[ikey-1].name||'';
  40. let newPreText =preText +nones;//console.log(arr[ikey-1],newPreText)
  41. if(items.length==0&&nones){
  42. arr[ikey-1].value = newPreText;
  43. res.saveText[ikey-1] = newPreText;
  44. res.selecteds[ikey] = null; //无殊选中状态遗留bug修改
  45. res.update=Math.random();
  46. return res;
  47. }
  48. //有,伴,无随配
  49. //arr.splice(ikey-1,1);
  50. let flabel = items[items.length-1]; //要插入的最后一个标签
  51. let labelText = flabel.value!==undefined?flabel.value:flabel.name;
  52. let text = labelText;
  53. //要插入的最后一个标签为自由文本,则和后面的文本标签文字合并
  54. if(flabel.tagType==8){
  55. flabel.value = labelText+nones;
  56. text = flabel.value;
  57. }
  58. arr.splice(ikey,0,...exists,...withs);
  59. //arr[ikey-1].value = text;
  60. //res.saveText[ikey+items.length] = text;
  61. res.saveText = fullfillText(arr).saveText;
  62. res.update=Math.random(); //用于触发组件更新(data变化了因在对象中无法被组件检测到)
  63. return res;
  64. };
  65. //查体中数字键盘选中事件
  66. export function setNumberValue(state,action){
  67. let res = Object.assign({},state);
  68. const param = action.params;
  69. const ikey = param.ikey;
  70. let labelInx = getLabelIndex(ikey);
  71. const subInx = ikey.substr(ikey.length-1);
  72. let item = res.data[labelInx];
  73. if(+item.tagType===1){
  74. item.value = param.text;
  75. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  76. }else{
  77. item.questionMapping[subInx].value = param.text;
  78. let hasValue = false;
  79. const sub = item.questionMapping.map((it)=>{
  80. if(it.value){ //至少有一个子值才黑显
  81. hasValue = true;
  82. }
  83. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  84. });
  85. res.saveText[labelInx] = hasValue?sub.join(''):'';
  86. }
  87. // res.saveText = fullfillText(res.data).saveText;
  88. res.update = Math.random();
  89. return res;
  90. }
  91. //查体单选下拉选中
  92. export function setRadioValue(state,action){
  93. let res = Object.assign({},state);
  94. const {ikey,id,text} = action;
  95. let labelInx = getLabelIndex(ikey);
  96. const subInx = ikey.substr(ikey.length-1);
  97. let item = res.data[labelInx];
  98. if(typeof text != 'string'){ //需要展开项--有无治疗类型
  99. const len = +item.copyType === 0?1:0;
  100. res.data.splice(labelInx,len,text);
  101. return res;
  102. }
  103. if(+item.tagType===1){ //独立单选组件
  104. item.value = text;
  105. res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
  106. item.questionDetailList.map((its)=>{
  107. if(its.id === id){
  108. its.selected = true;
  109. }else{
  110. its.selected = false;
  111. }
  112. });
  113. }else{ //组合组件中的单选组件
  114. item.questionMapping[subInx].value = text;
  115. let hasValue = false;
  116. const sub = item.questionMapping.map((it)=>{
  117. //添加选中状态
  118. it.questionDetailList.map((its)=>{
  119. if(its.id === id){
  120. its.selected = true;
  121. }else{
  122. its.selected = false;
  123. }
  124. });
  125. if(it.value){ //至少有一个子值才黑显
  126. hasValue = true;
  127. }
  128. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  129. });
  130. res.saveText[labelInx] = hasValue?sub.join(''):'';
  131. }
  132. // res.saveText = fullfillText(res.data).saveText;
  133. res.update = Math.random();
  134. return res;
  135. }
  136. //复制标签(如血压)事件
  137. export function addLabelItem(state,action){
  138. let res = Object.assign({},state);
  139. const {data,i} = action;
  140. const textLabel = JSON.parse(config.textLabel);
  141. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  142. if(!data) return res;
  143. res.data.splice(+i+2,0,JSON.parse(data),textLabel);
  144. res.saveText.splice(+i+2,0,'','');
  145. res.selecteds.splice(+i+2,0,null,null);
  146. res.update = Math.random();
  147. return res;
  148. }
  149. //自由文本
  150. export function setCheckText(state,action) {
  151. let res = Object.assign({},state);
  152. const {i,text} = action;
  153. if(res.data[i]){
  154. res.data[i].value=text;
  155. //res.data[i].name=''; //默认显示的文字
  156. }
  157. res.saveText[i] = text;
  158. res.update = Math.random();
  159. return res;
  160. }
  161. //多选文字,如杂音
  162. export function setCheckBoxValue(state,action) {
  163. let res = Object.assign({},state);
  164. const {labelInx,excluName,existsName,nones,withsName} = action.data;
  165. let showText = (excluName||'')+(existsName||'')+(nones||'')+(withsName||'');
  166. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  167. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  168. if(pattern.test(showText)){
  169. showText = showText.substr(0,showText.length-1);
  170. }
  171. res.data[labelInx].value = showText;
  172. res.selecteds[labelInx] = action.data;
  173. res.saveText = fullfillText(res.data).saveText;
  174. res.update = Math.random();
  175. return res;
  176. }
  177. //搜索结果
  178. export function setSearchData(state,action){
  179. let res = Object.assign({},state);
  180. res.searchData = action.data;
  181. res.searchStr = action.inpStr;
  182. res.searchInEnd = action.isEnd;
  183. return res;
  184. }
  185. //插入标签数据-搜索
  186. export function insertLabelData(state,action){
  187. let res = Object.assign({},state);
  188. const text = Object.assign({},JSON.parse(config.textLabel));
  189. const searchStr = res.searchStr;
  190. const {index,data,isReplace,span,searchInEnd}=action;
  191. const showText = res.saveText[index];
  192. const spreadLabels = data.tagType==4?fullfillText(data.questionMapping).newArr:[data];
  193. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  194. const newText=showText.replace(reg,'')||'';
  195. if(!isReplace){
  196. span.current.innerText = newText;
  197. const pText = Object.assign({},text,{value:newText});
  198. if(searchInEnd){
  199. res.data.splice(index,1,pText,...spreadLabels,text);
  200. res.saveText = fullfillText(res.data).saveText;
  201. //res.saveText.splice(index,1,newText,'','');
  202. res.selecteds.splice(index,1,null,new Array(spreadLabels.length).fill(null),null);
  203. }else{
  204. res.data.splice(index,1,text,...spreadLabels,pText);
  205. res.saveText = fullfillText(res.data).saveText;
  206. //res.saveText.splice(index,1,'','',newText);
  207. res.selecteds.splice(index,1,null,new Array(spreadLabels.length).fill(null),null);
  208. }
  209. }else{
  210. span.current.innerText = ' ';
  211. if(searchInEnd){
  212. res.data.splice(index+1,0,spreadLabels,text);
  213. res.saveText.splice(index+1,0,'','');
  214. res.selecteds.splice(index+1,0,null,null);
  215. }else{
  216. res.data.splice(index,0,text,spreadLabels);
  217. res.saveText.splice(index,0,'','');
  218. res.selecteds.splice(index,0,null,null);
  219. }
  220. }
  221. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  222. res.update = Math.random();
  223. return res;
  224. }
  225. export const changeLabelVal = (state,action)=>{//双击标签输入改变值
  226. const res = Object.assign({},state);
  227. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  228. const index = ikey;
  229. const newVal = changeVal; //下拉修改的内容
  230. let labText = totalVal?totalVal:newVal; //如单选没有前后缀
  231. let item = res.data[index];
  232. // if(newVal && newVal.trim()){
  233. if(labText && labText.trim()){
  234. if(item){
  235. item.value = newVal;
  236. item.labelPrefix = prefix||'';
  237. item.labelSuffix = suffix||'';
  238. // res.saveText[index] = totalVal;
  239. res.saveText[index] = labText;
  240. }
  241. }else{//删除完标签内容则删除该标签
  242. res.data.splice(index,1);
  243. res.saveText = fullfillText(res.data).saveText;
  244. }
  245. res.update = Math.random();
  246. return res;
  247. }
  248. // 数字键盘较特殊,有直接输入
  249. export const changeNumLabelVal = (state,action)=>{
  250. const res = Object.assign({},state);
  251. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  252. const index = ikey;
  253. const newVal = changeVal;
  254. let item = res.data[index];
  255. if(totalVal.trim()){
  256. if(item){
  257. item.value = newVal;
  258. item.labelPrefix = prefix||'';
  259. item.labelSuffix = suffix||'';
  260. }
  261. res.saveText[index] = totalVal;
  262. }else{//删除完标签内容则删除该标签
  263. res.data.splice(index,1);
  264. res.saveText = fullfillText(res.data).saveText;
  265. }
  266. res.update = Math.random();
  267. return res;
  268. }
  269. export function clearCheckBody(state,action){ //清空
  270. let res = Object.assign({},state);
  271. res.data = action.data;
  272. res.saveText = action.saveText;
  273. res.isEmpty = action.isEmpty;
  274. res.selecteds = action.selecteds?action.selecteds:[];
  275. return res;
  276. }
  277. //文本输入标签
  278. export function setInputLabel(state,action){
  279. let res = Object.assign({},state);//console.log(state,action)
  280. const {i,text,prefix,suffix,subIndex} = action;
  281. const item = res.data[i];
  282. if(+item.tagType===3){ //multSpred标签
  283. item.questionMapping[subIndex].value = text;
  284. let texts = item.questionMapping.map((it)=>{
  285. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  286. });
  287. res.saveText[i] = texts.join('');
  288. res.update = Math.random();
  289. return res;
  290. }else{
  291. if(item){
  292. item.value=text;
  293. }
  294. }
  295. res.saveText[i] = prefix+text+suffix;//console.log(res)
  296. res.update = Math.random();
  297. return res;
  298. }
  299. // backspace删除
  300. export function backspaceText(state,action){
  301. let res = Object.assign({},state);
  302. const {delIndex} = action;
  303. const data = res.data;
  304. if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  305. // 前一个是文本标签或者子模板 不做处理
  306. }else{
  307. data.splice(delIndex-1,2);
  308. }
  309. res.saveText = fullfillText(data).saveText;
  310. res.update = Math.random();
  311. return res;
  312. }