mainSuit.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. import {getLabelIndex,fullfillText,getIds} from '@common/js/func.js';
  2. import config from '@config/index.js';
  3. function insertPro(data,processModule){//插入添加病情变化模板
  4. let index;
  5. for(let i=0; i<data.length; i++){
  6. if(data[i].flag && data[i].flag==3 ){
  7. index = i;
  8. }
  9. }
  10. for(let j=0; j<processModule.length; j++){
  11. let pos = index + j;
  12. data.splice(pos,0,processModule[j]);
  13. }
  14. return data;
  15. }
  16. //获取主诉模板
  17. export const setMainMoudle = (state,action) => {
  18. const res = Object.assign({},state);
  19. // const emptySpan = JSON.parse(config.textLabel);
  20. // let data = action.data.push(emptySpan);
  21. res.moduleData = action.data;
  22. res.saveText = res.save||[];
  23. res.addSmoduleData = action.addSymptom;
  24. res.addModuleName = action.addModuleName;
  25. res.update=Math.random();
  26. return res;
  27. }
  28. //获取常见症状
  29. export const getCommSymptoms = (state,action) => {
  30. const res = Object.assign({},state);
  31. res.CommonSymptoms = action.data;
  32. return res;
  33. }
  34. //清除常见症状
  35. export const clearCommSymptoms = (state,action) => {
  36. const res = Object.assign({},state);
  37. res.CommonSymptoms = [];
  38. return res;
  39. }
  40. //获取大数据推送症状
  41. export const getBigSymptom = (state,action) => {
  42. const res = Object.assign({},state);
  43. res.showDrop = !res.showDrop;
  44. res.bigDataSymptom = action.data;//推送数据
  45. let inlineDatas = res.data;
  46. const index = action.info.ikey;
  47. let labelInx = getLabelIndex(index);
  48. // 添加症状 暂时剔除没有id、questionMapping字段的数据
  49. let pushDataList = action.data.filter(function(item){
  50. return item.id
  51. });
  52. let dataList = inlineDatas[labelInx].questionMapping;
  53. for(let k=0; k<dataList.length; k++){
  54. if(dataList[k].controlType == 99){
  55. dataList[k].questionDetailList = pushDataList;
  56. }
  57. }
  58. return res;
  59. }
  60. //点击插入新模板--添加病程变化
  61. export const handleTailClick = (state,action)=>{
  62. const res = Object.assign({},state);
  63. res.showDrop = !res.showDrop;
  64. let num = res.moduleNum.num;
  65. num++;
  66. const addSmoduleData = JSON.parse(JSON.stringify(res.addSmoduleData));
  67. // const addDatas = JSON.parse(JSON.stringify(fullfillText(action.info).newArr));
  68. let datas = JSON.parse(JSON.stringify(res.data));
  69. let leng = datas.length;
  70. for(let i=0; i<addSmoduleData.length; i++){
  71. addSmoduleData[i].pos = num;
  72. // let pos = leng-1+i;
  73. /* let pos = leng-2+i;
  74. datas.splice(pos,0,addDatas[i]);*/
  75. }
  76. res.data = insertPro(datas,addSmoduleData);
  77. res.saveText = fullfillText(res.data).saveText;
  78. res.moduleNum.num = num;
  79. return res;
  80. }
  81. //将选择的常见症状插入
  82. export const insertMain = (state,action) => {
  83. const res = Object.assign({},state);
  84. res.showDrop = !res.showDrop;//防止不更新
  85. const item = action.item.name;
  86. const id = action.item.questionId;
  87. // 将选中的id存起,现病史时获取模板
  88. // let data = res.data;
  89. let data = JSON.parse(JSON.stringify(res.moduleData));
  90. // const text = {id:id,name:item,tagType:config.tagType,controlType:3,exist:1};
  91. const text = {id:id,name:item,value:item,tagType:config.tagType,exist:1};
  92. const emptySpan = JSON.parse(config.textLabel);
  93. let inserIndx = null;
  94. data.map((it,i)=>{
  95. if(it.flag == 1){//在此处插入主诉数据
  96. inserIndx = i;
  97. }
  98. })
  99. // data.splice(inserIndx,0,text,emptySpan);
  100. // data.splice(inserIndx,0,text);
  101. data[inserIndx-1] = text;//替换空标签
  102. res.data = data;
  103. res.saveText = [];//将手动输入的值清掉
  104. // res.saveText[inserIndx] = text.name;
  105. res.saveText = fullfillText(res.data).saveText;
  106. res.mainIds.push(id);
  107. res.editClear = false;//主诉框编辑状态
  108. res.update=Math.random();
  109. return res;
  110. }
  111. function getTextLabel(id,name,flag){
  112. // exist 主症状1,伴随2
  113. return {id:id,name:name,value:name,tagType:config.tagType,exist:flag};
  114. }
  115. //多选标签选中确定处理
  116. export const confirm = (state,action) =>{
  117. const res = Object.assign({},state);
  118. let arr = res.data;
  119. let saveText = JSON.parse(JSON.stringify(res.saveText));
  120. const {exists,withs,ikey,withsName,existsName,ban} = action.data;
  121. let existsId = getIds(exists);
  122. let withsId = getIds(withs);
  123. let banText = JSON.stringify(ban) == "{}" ? '':{id:ban.id,name:ban.name,value:ban.name,tagType:config.tagType};
  124. res.mainIds = res.mainIds?res.mainIds.concat(existsId,withsId):[];
  125. let length = exists.length;
  126. let labelIndx = parseInt(ikey);//当前点击标签的index
  127. let text = saveText.slice(0,labelIndx);
  128. let index = text.indexOf('伴');
  129. if(index==-1){//没有伴,直接插入ikey前
  130. if(exists.length > 0){
  131. for(let i=0; i<exists.length; i++){
  132. let pos = labelIndx + i;
  133. arr.splice(pos,0,getTextLabel(exists[i].id,exists[i].name,1));
  134. res.saveText[pos] = exists[i].name;
  135. }
  136. }
  137. if(withs.length > 0){
  138. let newWiths = JSON.parse(JSON.stringify(withs));
  139. if(banText){
  140. newWiths.unshift(banText);
  141. }
  142. for(let j=0; j<newWiths.length; j++){
  143. let withsPos = labelIndx +length + j;
  144. arr.splice(withsPos,0,getTextLabel(newWiths[j].id,newWiths[j].name,2));
  145. res.saveText[withsPos] = newWiths[j].name;
  146. }
  147. }
  148. }else{//有伴
  149. if(exists.length > 0){
  150. for(let i=0; i<exists.length; i++){
  151. let pos = index + i;
  152. arr.splice(pos,0,getTextLabel(exists[i].id,exists[i].name,1));
  153. res.saveText[pos] = exists[i].name;
  154. }
  155. }
  156. if(withs.length>0){//有伴插到ikey前既可
  157. for(let j=0; j<withs.length; j++){
  158. // let withsPos = labelIndx + j;
  159. let withsPos = labelIndx +length + j;
  160. arr.splice(withsPos,0,getTextLabel(withs[j].id,withs[j].name,2));
  161. res.saveText[withsPos] = withs[j].name;
  162. }
  163. }
  164. }
  165. res.data = arr;
  166. res.saveText = fullfillText(arr).saveText;
  167. res.update=Math.random();
  168. return res;
  169. };
  170. // 普通多选确定事件
  171. export const commConfirm=(state,action)=>{
  172. const res = Object.assign({},state);
  173. const {exists,ikey,existsName} = action.data;
  174. let arr = res.data;
  175. arr[ikey].value = existsName;
  176. res.saveText[ikey] = existsName;
  177. res.selecteds[ikey] = action.data;
  178. res.update=Math.random();
  179. return res;
  180. }
  181. export const setSearch = (state,action)=>{
  182. const res = Object.assign({},state);
  183. res.showDrop = !res.showDrop;//防止不更新
  184. let searchData = action.data;
  185. res.searchDatas = searchData;
  186. res.searchStr = action.inpStr;
  187. return res;
  188. }
  189. //将选中的搜索结果插入
  190. export const insertSearch = (state,action)=>{
  191. // 如果没有模板就插入模板,有模板则只插入所传文字
  192. const res = Object.assign({},state);
  193. let data = res.data;
  194. let moduleData = JSON.parse(JSON.stringify(res.moduleData));
  195. let searchData = action.info.name;
  196. const id = action.info.questionId;
  197. let focusIndex = res.focusIndex;
  198. let span = action.span;
  199. let text = {id:id,name:searchData,value:searchData,tagType:config.tagType};
  200. const emptySpan = JSON.parse(config.textLabel);
  201. if(data.length==0){
  202. let inserIndx = null;
  203. moduleData.map((it,i)=>{
  204. if(it.flag == 1){//在此处插入主诉数据
  205. inserIndx = i;
  206. }
  207. })
  208. // flag=1前是文本标签就替换,否则插入
  209. const iftext = moduleData[inserIndx-1].tagType;
  210. if(iftext==config.tagType){
  211. moduleData.splice(inserIndx-1,1,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1});
  212. }else{
  213. moduleData.splice(inserIndx,0,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1});
  214. }
  215. // moduleData.splice(inserIndx,0,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1},emptySpan);
  216. res.saveText = [];//将手动输入的值清掉
  217. res.data = moduleData;
  218. // res.saveText[inserIndx] = searchData;
  219. res.saveText = fullfillText(res.data).saveText;
  220. res.mainIds.push(id);
  221. res.editClear = false;//主诉框编辑状态
  222. }else{
  223. // 替换
  224. /*span.current.innerText = '';
  225. res.data.splice(focusIndex,1,text);
  226. res.saveText[focusIndex] = searchData;
  227. res.mainIds.push(id);*/
  228. // 追加--前or后?searchStr
  229. const searchStr = res.searchStr;
  230. let innerText = span.current.innerText;
  231. let index = innerText.indexOf(searchStr);
  232. let value;
  233. if(index <= 1){//前
  234. value = innerText.replace(searchStr,searchData);
  235. }else{
  236. let temp = innerText.substring(0,innerText.lastIndexOf(searchStr));
  237. value = temp + searchData;
  238. }
  239. // let value = innerText + searchData;
  240. span.current.innerText = value;
  241. res.data[focusIndex].value = value;
  242. res.saveText[focusIndex] = value;
  243. res.mainIds.push(id);
  244. }
  245. // console.log(456,res,action);
  246. res.update=Math.random();
  247. return res;
  248. }
  249. //数字键盘选中事件
  250. export function setNumberValue(state,action){
  251. let res = Object.assign({},state);
  252. const param = action.params;
  253. const index = param.ikey;
  254. let labelInx = getLabelIndex(index);
  255. const subInx = index.substr(-1,1);
  256. let item = res.data[labelInx];
  257. if(+item.tagType===1){
  258. item.value = param.text;
  259. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  260. }else{
  261. item.questionMapping[subInx].value = param.text;
  262. let hasValue = false;
  263. const sub = item.questionMapping.map((it)=>{
  264. if(it.value){ //至少有一个子值才黑显
  265. hasValue = true;
  266. }
  267. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  268. });
  269. // res.saveText[labelInx] = sub.join(',');
  270. res.saveText[labelInx] = hasValue?sub.join(''):'';
  271. item.value = sub.join('');
  272. }
  273. res.update = Math.random();
  274. return res;
  275. }
  276. //单选下拉选中
  277. export function setRadioValue(state,action){
  278. let res = Object.assign({},state);
  279. const {ikey,id,text} = action;
  280. let labelInx = getLabelIndex(ikey);
  281. const subInx = ikey.substr(-1,1);
  282. let item = res.data[labelInx];
  283. if(typeof text != 'string'){ //需要展开项--有无治疗类型
  284. const len = +item.copyType === 0?1:0;
  285. res.data.splice(labelInx,len,text);
  286. return res;
  287. }
  288. if(+item.tagType===1){
  289. item.value = text;
  290. res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
  291. item.questionDetailList.map((its)=>{
  292. if(its.id === id){
  293. its.selected = true;
  294. }else{
  295. its.selected = false;
  296. }
  297. });
  298. }else{
  299. item.questionMapping[subInx].value = text;
  300. let hasValue = false;
  301. const sub = item.questionMapping.map((it)=>{
  302. //添加选中状态
  303. it.questionDetailList.map((its)=>{
  304. if(its.id === id){
  305. its.selected = true;
  306. }else{
  307. its.selected = false;
  308. }
  309. });
  310. if(it.value){ //至少有一个子值才黑显
  311. hasValue = true;
  312. }
  313. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  314. });
  315. // res.saveText[labelInx] = sub.join(',');
  316. res.saveText[labelInx] = hasValue?sub.join(''):'';
  317. item.value = sub.join('');
  318. }
  319. res.update = Math.random();
  320. return res;
  321. }
  322. //双击标签输入改变值
  323. export const changeLabelVal = (state,action)=>{
  324. const res = Object.assign({},state);
  325. const index = action.data.ikey;
  326. const newVal = action.data.changeVal;
  327. let item = res.data[index];
  328. if(item){
  329. item.value = newVal;
  330. }
  331. res.saveText[index] = newVal;
  332. res.update = Math.random();
  333. return res;
  334. }
  335. // 保存自由输入文本--无模板
  336. export const saveFreeVal = (state,action)=>{
  337. const res = Object.assign({},state);
  338. let data = action.data;
  339. res.saveText[0] = data;
  340. /*if(data.trim()){
  341. res.saveText[0] = data;
  342. }else{
  343. res.saveText = [];
  344. }*/
  345. res.update = Math.random();
  346. return res;
  347. }
  348. export const clearMainSuit = (state,action)=>{//回读和清除
  349. const res = Object.assign({},state);
  350. res.data = action.data;
  351. res.saveText = action.saveText;
  352. // res.saveText = fullfillText(action.data).saveText;//解决删除data里的值保存,回读后页面上有内容saveText里没有的情况
  353. res.selecteds = action.selecteds?action.selecteds:[];
  354. res.mainIds = action.mainIds
  355. if(action.editClear){
  356. res.editClear = action.editClear;
  357. }
  358. if(res.data.length>0){//回读
  359. res.editClear = false;
  360. }
  361. return res;
  362. }
  363. //文本模式下值保存
  364. export const setTextModeValue = (state,action)=>{
  365. const res = Object.assign({},state);
  366. res.saveText[0] = action.text;
  367. return res;
  368. };
  369. //自由文本
  370. export function setCheckText(state,action) {
  371. let res = Object.assign({},state);
  372. const {i,text} = action;
  373. res.data[i].value=text;
  374. res.saveText[i] = text;
  375. /*if(res.data[i]){
  376. res.data[i].value=text;
  377. }
  378. res.saveText[i] = text;*/
  379. res.update = Math.random();
  380. return res;
  381. }
  382. //复制标签(如血压)事件
  383. export function addLabelItem(state,action){
  384. let res = Object.assign({},state);
  385. const {data,i} = action;
  386. const textLabel = JSON.parse(config.textLabel);
  387. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  388. if(!data) return res;
  389. res.data.splice(i+1,0,JSON.parse(data),textLabel);
  390. res.update = Math.random();
  391. return res;
  392. }
  393. //文本输入标签
  394. export function setInputLabel(state,action){
  395. let res = Object.assign({},state);//console.log(state,action)
  396. const {i,text,prefix,suffix,subIndex} = action;
  397. const item = res.data[i];
  398. if(+item.tagType===3){ //multSpred标签
  399. item.questionMapping[subIndex].value = text;
  400. let texts = item.questionMapping.map((it)=>{
  401. return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):'';
  402. });
  403. res.saveText[i] = texts.join('');
  404. res.update = Math.random();
  405. return res;
  406. }else{
  407. if(item){
  408. item.value=text;
  409. }
  410. }
  411. res.saveText[i] = prefix+text+suffix;//console.log(res)
  412. res.update = Math.random();
  413. return res;
  414. }