checkBody.js 8.7 KB

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