otherHistory.js 9.9 KB

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