checkBody.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 = action.isEmpty;
  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 const setRadioInputValue = (state,action)=>{
  138. const res = Object.assign({},state);
  139. const {ikey,values,id} = action.data;
  140. const item = res.data[ikey];
  141. let str='',temp='',obj=res.data[ikey].questionDetailList;
  142. if(!values){ //清空
  143. let sld=obj.find((item)=>{
  144. return item.selected==true;
  145. });
  146. sld?sld.selected=false:'';
  147. item.vals = null;
  148. item.value = '';
  149. res.saveText[ikey] = '';
  150. res.update = Math.random();
  151. return res;
  152. }
  153. for(let i in values){
  154. temp = values[i];
  155. if(typeof temp=='object'){
  156. str+=temp.value;
  157. }else{
  158. str+=temp;
  159. }
  160. }
  161. //选中状态
  162. if(id){
  163. obj.map((its)=>{
  164. if(its.id === id){
  165. its.selected = true;
  166. }else{
  167. its.selected = false;
  168. }
  169. });
  170. }
  171. item.vals = values;
  172. item.value = str;
  173. res.saveText[ikey] = str;
  174. res.update = Math.random();
  175. return res;
  176. }
  177. //复制标签(如血压)事件
  178. export function addLabelItem(state,action){
  179. let res = Object.assign({},state);
  180. const {data,i} = action;
  181. const textLabel = JSON.parse(config.textLabel);
  182. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  183. if(!data) return res;
  184. res.data.splice(+i+2,0,JSON.parse(data),textLabel);
  185. res.saveText.splice(+i+2,0,'','');
  186. res.selecteds.splice(+i+2,0,null,null);
  187. res.update = Math.random();
  188. return res;
  189. }
  190. //自由文本
  191. export function setCheckText(state,action) {
  192. let res = Object.assign({},state);
  193. const {i,text} = action;
  194. if(res.data[i]){
  195. res.data[i].value=text;
  196. //res.data[i].name=''; //默认显示的文字
  197. }
  198. res.saveText[i] = text;
  199. res.update = Math.random();
  200. return res;
  201. }
  202. //多选文字,如杂音
  203. export function setCheckBoxValue(state,action) {
  204. let res = Object.assign({},state);
  205. const {labelInx,excluName,existsName,nones,withsName,ban} = action.data;
  206. let showText = (excluName||'')+(existsName||'')+(ban.name||'')+(withsName||'')+(nones||'');
  207. // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
  208. let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
  209. if(pattern.test(showText)){
  210. showText = showText.substr(0,showText.length-1);
  211. }
  212. res.data[labelInx].value = showText;
  213. res.selecteds[labelInx] = action.data;
  214. res.saveText = fullfillText(res.data).saveText;
  215. res.update = Math.random();
  216. return res;
  217. }
  218. //搜索结果
  219. export function setSearchData(state,action){
  220. let res = Object.assign({},state);
  221. res.searchData = action.data;
  222. res.searchStr = action.inpStr;
  223. res.searchInEnd = action.isEnd;
  224. return res;
  225. }
  226. //插入标签数据-搜索
  227. export function insertLabelData(state,action){
  228. let res = Object.assign({},state);
  229. const text = Object.assign({},JSON.parse(config.textLabel));
  230. const searchStr = res.searchStr;
  231. const {index,data,isReplace,span,searchInEnd}=action;console.log("查体",data);
  232. const showText = res.saveText[index];
  233. const spreadLabels = data.tagType==4?fullfillText(data.questionMapping).newArr:[data];
  234. let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
  235. const newText=showText.replace(reg,'')||'';
  236. if(!isReplace){
  237. span.current.innerText?(span.current.innerText = newText):(span.current.innerHTML = newText);
  238. const pText = Object.assign({},text,{value:newText});
  239. if(searchInEnd){
  240. res.data.splice(index,1,pText,...spreadLabels,text);
  241. res.saveText = fullfillText(res.data).saveText;
  242. //res.saveText.splice(index,1,newText,'','');
  243. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  244. }else{
  245. res.data.splice(index,1,text,...spreadLabels,pText);
  246. res.saveText = fullfillText(res.data).saveText;
  247. //res.saveText.splice(index,1,'','',newText);
  248. res.selecteds.splice(index,1,null,...new Array(spreadLabels.length).fill(null),null);
  249. }
  250. }else{
  251. span.current.innerText?(span.current.innerText = ' '):(span.current.innerHTML = ' ');
  252. if(searchInEnd){
  253. res.data.splice(index+1,0,spreadLabels,text);
  254. res.saveText.splice(index+1,0,'','');
  255. res.selecteds.splice(index+1,0,null,null);
  256. }else{
  257. res.data.splice(index,0,text,spreadLabels);
  258. res.saveText.splice(index,0,'','');
  259. res.selecteds.splice(index,0,null,null);
  260. }
  261. }
  262. res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
  263. res.update = Math.random();
  264. return res;
  265. }
  266. export const changeLabelVal = (state,action)=>{//双击标签输入改变值
  267. const res = Object.assign({},state);
  268. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  269. const index = ikey;
  270. const newVal = changeVal; //下拉修改的内容
  271. let labText = totalVal?totalVal:newVal; //如单选没有前后缀
  272. let item = res.data[index];
  273. const next = res.data[+index+1];
  274. const nextVal = next.value||next.name;
  275. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  276. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  277. // if(newVal && newVal.trim()){
  278. if(labText && labText.trim()){
  279. if(item){
  280. item.value = newVal;
  281. item.labelPrefix = prefix||'';
  282. item.labelSuffix = suffix||'';
  283. // res.saveText[index] = totalVal;
  284. res.saveText[index] = labText;
  285. }
  286. }else{//删除完标签内容则删除该标签
  287. const num = nextIsDot?2:1;
  288. res.data.splice(index,num);
  289. res.selecteds.splice(index,num);//杂音类样式选中状态对应
  290. res.saveText = fullfillText(res.data).saveText;
  291. }
  292. res.update = Math.random();
  293. return res;
  294. }
  295. // 数字键盘较特殊,有直接输入
  296. export const changeNumLabelVal = (state,action)=>{
  297. const res = Object.assign({},state);
  298. const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
  299. const index = ikey;
  300. const newVal = changeVal;
  301. let item = res.data[index];
  302. const next = res.data[+index+1];
  303. const nextVal = next.value||next.name;
  304. //标签后是不是标点符号标签,是的话删除本标签时一起删除
  305. let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
  306. if(totalVal.trim()){
  307. if(item){
  308. item.value = newVal;
  309. item.labelPrefix = prefix||'';
  310. item.labelSuffix = suffix||'';
  311. }
  312. res.saveText[index] = totalVal;
  313. }else{//删除完标签内容则删除该标签
  314. const num = nextIsDot?2:1;
  315. res.data.splice(index,num);
  316. res.selecteds.splice(index,num); //杂音类样式选中状态对应
  317. res.saveText = fullfillText(res.data).saveText;
  318. }
  319. res.update = Math.random();
  320. return res;
  321. }
  322. export function clearCheckBody(state,action){ //清空
  323. let res = Object.assign({},state);
  324. res.data = action.data;
  325. res.saveText = action.saveText;
  326. res.isEmpty = action.isEmpty;
  327. res.selecteds = action.selecteds?action.selecteds:[];
  328. return res;
  329. }
  330. //文本输入标签
  331. export function setInputLabel(state,action){
  332. let res = Object.assign({},state);//console.log(state,action)
  333. const {i,text,prefix,suffix,subIndex} = action;
  334. const item = res.data[i];
  335. if(+item.tagType===3){ //multSpred标签
  336. item.questionMapping[subIndex].value = text;
  337. let texts = item.questionMapping.map((it)=>{
  338. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  339. });
  340. res.saveText[i] = texts.join('');
  341. res.update = Math.random();
  342. return res;
  343. }else{
  344. if(item){
  345. item.value=text;
  346. }
  347. }
  348. res.saveText[i] = prefix+text+suffix;//console.log(res)
  349. res.update = Math.random();
  350. return res;
  351. }
  352. // backspace删除
  353. export function backspaceText(state,action){
  354. let res = Object.assign({},state);
  355. const {delIndex} = action;
  356. const data = res.data;
  357. if(data[delIndex-1].flag&&data[delIndex-1].flag==3){
  358. // if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
  359. // 前一个是文本标签或者子模板 不做处理
  360. }else if(data[delIndex-1].tagType==8){
  361. data.splice(delIndex,1);
  362. res.saveText.splice(delIndex,1);
  363. }
  364. else{
  365. data.splice(delIndex-1,2);
  366. res.saveText.splice(delIndex-1,2);
  367. }
  368. // res.saveText = fullfillText(data).saveText;
  369. res.update = Math.random();
  370. return res;
  371. }
  372. // 单列多选
  373. export function multipleComfirn(state,action){
  374. let res = Object.assign({},state);
  375. const {ikey,seleData} = action.data;
  376. let data = res.data;
  377. data[ikey].value = seleData;
  378. res.saveText[ikey] = seleData;
  379. res.selecteds[ikey] = action.data;
  380. res.update = Math.random();
  381. return res;
  382. }
  383. export function delSingleLable(state,action){
  384. let res = Object.assign({},state);
  385. const {index} = action;
  386. let data = res.data;
  387. // 前一个不是文本标签 并且不是子模板,则删除
  388. if(data[index-1].flag&&data[index-1].flag==3){
  389. }
  390. else if(data[index-1].tagType != 8){
  391. data.splice(index-1,1);
  392. res.saveText.splice(index-1,1);
  393. }
  394. res.update = Math.random();
  395. return res;
  396. }