checkBody.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.saveText[labelInx] = showText;
  121. res.selecteds[labelInx] = action.data;
  122. res.saveText = fullfillText(res.data).saveText;
  123. res.update = Math.random();
  124. return res;
  125. }
  126. //搜索结果
  127. export function setSearchData(state,action){
  128. let res = Object.assign({},state);
  129. res.searchData = action.data;
  130. res.searchStr = action.inpStr;
  131. res.searchInEnd = action.isEnd;
  132. return res;
  133. }
  134. //插入标签数据-搜索
  135. export function insertLabelData(state,action){
  136. let res = Object.assign({},state);
  137. const text = Object.assign({},JSON.parse(config.textLabel));
  138. const searchStr = res.searchStr;
  139. const {index,data,isReplace,span,searchInEnd}=action;
  140. const showText = res.saveText[index];
  141. const spreadLabels = data;
  142. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  143. const newText=showText.replace(reg,'')||'';
  144. if(!isReplace){
  145. span.current.innerText = newText;
  146. const pText = Object.assign({},text,{value:newText});
  147. if(searchInEnd){
  148. res.data.splice(index,1,pText,spreadLabels,text);
  149. res.saveText.splice(index,1,newText,'','');
  150. res.selecteds.splice(index,1,null,null,null);
  151. }else{
  152. res.data.splice(index,1,text,spreadLabels,pText);
  153. res.saveText.splice(index,1,'','',newText);
  154. res.selecteds.splice(index,1,null,null,null);
  155. }
  156. }else{
  157. span.current.innerText = ' ';
  158. if(searchInEnd){
  159. res.data.splice(index+1,0,spreadLabels,text);
  160. res.saveText.splice(index+1,0,'','');
  161. res.selecteds.splice(index+1,0,null,null);
  162. }else{
  163. res.data.splice(index,0,text,spreadLabels);
  164. res.saveText.splice(index,0,'','');
  165. res.selecteds.splice(index,0,null,null);
  166. }
  167. }
  168. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  169. res.update = Math.random();
  170. return res;
  171. }
  172. export const changeLabelVal = (state,action)=>{//双击标签输入改变值
  173. const res = Object.assign({},state);
  174. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  175. const index = ikey;
  176. const newVal = changeVal; //下拉修改的内容
  177. let labText = totalVal?totalVal:newVal;
  178. let item = res.data[index];
  179. // if(newVal && newVal.trim()){
  180. if(labText && labText.trim()){
  181. if(item){
  182. item.value = newVal;
  183. item.labelPrefix = prefix;
  184. item.labelSuffix = suffix;
  185. // res.saveText[index] = totalVal;
  186. res.saveText[index] = labText;
  187. }
  188. }else{//删除完标签内容则删除该标签
  189. res.data.splice(index,1);
  190. res.saveText = fullfillText(res.data).saveText;
  191. }
  192. res.update = Math.random();
  193. return res;
  194. }
  195. // 数字键盘较特殊,有直接输入
  196. export const changeNumLabelVal = (state,action)=>{
  197. const res = Object.assign({},state);
  198. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  199. const index = ikey;
  200. const newVal = changeVal;
  201. let item = res.data[index];
  202. if(totalVal.trim()){
  203. if(item){
  204. item.value = newVal;
  205. item.labelPrefix = prefix;
  206. item.labelSuffix = suffix;
  207. }
  208. res.saveText[index] = totalVal;
  209. }else{//删除完标签内容则删除该标签
  210. res.data.splice(index,1);
  211. res.saveText = fullfillText(res.data).saveText;
  212. }
  213. res.update = Math.random();
  214. return res;
  215. }
  216. export function clearCheckBody(state,action){ //清空
  217. let res = Object.assign({},state);
  218. res.data = action.data;
  219. res.saveText = action.saveText;
  220. res.isEmpty = action.isEmpty;
  221. res.selecteds = action.selecteds?action.selecteds:[];
  222. return res;
  223. }
  224. //文本输入标签
  225. export function setInputLabel(state,action){
  226. let res = Object.assign({},state);//console.log(state,action)
  227. const {i,text,prefix,suffix,subIndex} = action;
  228. const item = res.data[i];
  229. if(+item.tagType===3){ //multSpred标签
  230. item.questionMapping[subIndex].value = text;
  231. let texts = item.questionMapping.map((it)=>{
  232. return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):'';
  233. });
  234. res.saveText[i] = texts.join('');
  235. res.update = Math.random();
  236. return res;
  237. }else{
  238. if(item){
  239. item.value=text;
  240. }
  241. }
  242. res.saveText[i] = prefix+text+suffix;//console.log(res)
  243. res.update = Math.random();
  244. return res;
  245. }
  246. // backspace删除
  247. export function backspaceText(state,action){
  248. let res = Object.assign({},state);
  249. const {delIndex} = action;
  250. const data = res.data;
  251. if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  252. // 前一个是文本标签或者子模板 不做处理
  253. }else{
  254. data.splice(delIndex-1,2);
  255. }
  256. res.saveText = fullfillText(data).saveText;
  257. res.update = Math.random();
  258. return res;
  259. }