otherHistory.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import config from '@config/index';
  2. import {getLabelIndex,fullfillText} from '@common/js/func.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.update=Math.random();
  35. return res;
  36. }
  37. //有,伴,无随配
  38. //arr.splice(ikey-1,1);
  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. //arr[ikey-1].value = text;
  49. res.saveText[ikey+items.length] = text;
  50. res.update=Math.random(); //用于触发组件更新(data变化了因在对象中无法被组件检测到)
  51. return res;
  52. };
  53. //单选下拉选中
  54. export function setRadioValue(state,action){
  55. let res = Object.assign({},state);
  56. const {ikey,id,text} = action;
  57. let labelInx = getLabelIndex(ikey);
  58. const subInx = ikey.substr(ikey.length-1);
  59. let item = res.data[labelInx];
  60. if(typeof text != 'string'){ //需要展开项--有无治疗类型
  61. const len = +item.copyType === 0?1:0;
  62. res.data.splice(labelInx,len,text);
  63. return res;
  64. }
  65. if(+item.tagType===1){
  66. item.value = text;
  67. res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
  68. item.questionDetailList.map((its)=>{
  69. if(its.id === id){
  70. its.selected = true;
  71. }else{
  72. its.selected = false;
  73. }
  74. });
  75. }else{
  76. item.questionMapping[subInx].value = text;
  77. let hasValue = false;
  78. const sub = item.questionMapping.map((it)=>{
  79. //添加选中状态
  80. it.questionDetailList.map((its)=>{
  81. if(its.id === id){
  82. its.selected = true;
  83. }else{
  84. its.selected = false;
  85. }
  86. });
  87. if(it.value){ //至少有一个子值才黑显
  88. hasValue = true;
  89. }
  90. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  91. });
  92. res.saveText[labelInx] = hasValue?sub.join(''):'';
  93. }
  94. res.update = Math.random();
  95. return res;
  96. }
  97. //数字键盘选中事件
  98. export function setNumberValue(state,action){
  99. let res = Object.assign({},state);
  100. const param = action.params;
  101. const ikey = param.ikey;
  102. let labelInx = getLabelIndex(ikey);
  103. const subInx = ikey.substr(ikey.length-1);
  104. let item = res.data[labelInx];
  105. if(+item.tagType===1){
  106. item.value = param.text;
  107. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  108. }else{
  109. item.questionMapping[subInx].value = param.text;
  110. let hasValue = false;
  111. const sub = item.questionMapping.map((it)=>{
  112. if(it.value){ //至少有一个子值才黑显
  113. hasValue = true;
  114. }
  115. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  116. });
  117. res.saveText[labelInx] = hasValue?sub.join(''):'';
  118. }
  119. res.update = Math.random();
  120. return res;
  121. }
  122. //自由文本
  123. export function setCheckText(state,action) {
  124. let res = Object.assign({},state);
  125. const {i,text} = action;
  126. if(res.data[i]){
  127. res.data[i].value=text;
  128. //res.data[i].name=''; //默认显示的文字
  129. }
  130. res.saveText[i] = text;
  131. res.update = Math.random();
  132. return res;
  133. }
  134. //文本输入标签
  135. export function setOtherInput(state,action){
  136. let res = Object.assign({},state);
  137. const {i,text,prefix,suffix} = action;
  138. if(res.data[i]){
  139. res.data[i].value=text;
  140. }
  141. res.saveText[i] = prefix+text+suffix;
  142. res.update = Math.random();
  143. return res;
  144. }
  145. //多选文字,如杂音
  146. export function setCheckBoxValue(state,action) {
  147. let res = Object.assign({},state);
  148. const {labelInx,excluName,existsName,nones,withsName} = action.data;
  149. let showText = (excluName||'')+(existsName||'')+(nones||'')+(withsName||'');
  150. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  151. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  152. if(pattern.test(showText)){
  153. showText = showText.substr(0,showText.length-1);
  154. }
  155. res.data[labelInx].value = showText;
  156. res.saveText[labelInx] = showText;
  157. res.selecteds[labelInx] = action.data;
  158. res.update = Math.random();
  159. return res;
  160. }
  161. //搜索结果
  162. export function setSearchData(state,action){
  163. let res = Object.assign({},state);
  164. res.searchData = action.data;
  165. res.searchStr = action.inpStr;
  166. return res;
  167. }
  168. //插入标签数据
  169. export function insertLabelData(state,action){
  170. let res = Object.assign({},state);
  171. const text = Object.assign({},JSON.parse(config.textLabel));
  172. const searchStr = res.searchStr;
  173. const {index,data,isReplace,span}=action;
  174. const showText = res.saveText[index];
  175. const spreadLabels = data;
  176. const toEnd = showText.indexOf(searchStr)>0; //替换前或后的搜索词(中间不可搜)
  177. let reg = toEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  178. const newText=showText.replace(reg,'')||' ';
  179. if(!isReplace){
  180. span.current.innerText = newText;
  181. const pText = Object.assign({},text,{value:newText});
  182. res.data.splice(index,1,pText,spreadLabels,text);
  183. res.saveText.splice(index,1,newText,'','');
  184. }else{
  185. span.current.innerText = ' ';
  186. res.data.splice(index+1,0,spreadLabels,text);
  187. res.saveText.splice(index+1,0,'','');
  188. }
  189. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  190. res.update = Math.random();
  191. return res;
  192. }
  193. export function changeTextLabel(state,action) {
  194. const res = Object.assign({},state);
  195. const index = action.data.ikey;
  196. const newVal = action.data.changeVal;
  197. let item = res.data[index];
  198. if(item){
  199. item.value = newVal;
  200. }
  201. res.saveText[index] = newVal;
  202. res.update = Math.random();
  203. return res;
  204. }
  205. export function clearOtherHistory(state,action){ //清空数据
  206. let res = Object.assign({},state);
  207. res.data = action.data;
  208. res.saveText = action.saveText;
  209. res.selecteds = action.selecteds;
  210. res.editClear = action.editClear;
  211. return res;
  212. }
  213. //文本模式下值保存
  214. export const setTextModeValue = (state,action)=>{
  215. const res = Object.assign({},state);
  216. res.saveText[0] = action.text;
  217. return res;
  218. };
  219. //复制标签(如血压)事件
  220. export function addLabelItem(state,action){
  221. let res = Object.assign({},state);
  222. const {data,i} = action;
  223. const textLabel = JSON.parse(config.textLabel);
  224. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  225. if(!data) return res;
  226. res.data.splice(i+1,0,JSON.parse(data),textLabel);
  227. res.update = Math.random();
  228. return res;
  229. }
  230. export const otherEditClear = (state,action)=>{
  231. const res = Object.assign({},state);
  232. res.editClear = action.bool;
  233. return res;
  234. };
  235. // backspace删除
  236. export function backspaceText(state,action){
  237. let res = Object.assign({},state);
  238. const {delIndex} = action;
  239. const data = res.data;
  240. if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  241. // 前一个是文本标签或者子模板 不做处理
  242. }else{
  243. data.splice(delIndex-1,2);
  244. }
  245. res.saveText = fullfillText(data).saveText;
  246. res.update = Math.random();
  247. return res;
  248. }