store.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import {deepClone,getAllStr,moduleCP} from '@utils/tools.js'
  4. Vue.use(Vuex);
  5. const store = new Vuex.Store({
  6. state:{
  7. searchShow:false,
  8. pathInfo:{}, //患者信息-后续提交要用
  9. sysConfig:[], //系统配置项
  10. allMoudles:[], //模板
  11. symptom:{ //症状情况
  12. choose:[],
  13. origin:{},
  14. datas:{},
  15. text:[],
  16. },
  17. diagnose:{ //诊疗
  18. origin:[], //模板数据
  19. datas:[],
  20. text:[],
  21. imgFile:[],//上传图片信息file
  22. imgSrc:{},//上传的图片信息src
  23. },
  24. others:{ //其他情况
  25. origin:[], //模板数据
  26. datas:[],
  27. text:[],
  28. imgFile:[],
  29. imgSrc:{},
  30. },
  31. addContent:{
  32. origin:[],
  33. txt:'',
  34. txtDoc:''
  35. },
  36. loadingShow:false,
  37. detailInfo:{},
  38. detailShow:false
  39. },
  40. mutations:{
  41. initAllData(state){
  42. state.symptom={ //症状情况
  43. choose:[],
  44. origin:{},
  45. datas:{},
  46. text:[],
  47. }
  48. state.diagnose={ //诊疗
  49. origin:[], //模板数据
  50. datas:[],
  51. text:[],
  52. imgFile:[],
  53. imgSrc:{},
  54. }
  55. state.others={ //其他情况
  56. origin:[], //模板数据
  57. datas:[],
  58. text:[],
  59. imgFile:[],
  60. imgSrc:{},
  61. }
  62. state.addContent={
  63. origin:[],
  64. txt:'',
  65. txtDoc:''
  66. }
  67. },
  68. setDetail(state,param){//明细
  69. const detail = param.detail;
  70. if(JSON.stringify(detail)=='{}'){
  71. state.detailShow = false;
  72. }else{
  73. state.detailInfo = Object.assign({},param);
  74. state.detailShow = true;
  75. }
  76. },
  77. setSearchShow(state,flg){//搜索显示与否
  78. state.searchShow = flg;
  79. },
  80. setDataAll(state,param){
  81. let res = state.allMoudles
  82. for(let i = 0;i<res.length;i++){
  83. if(res[i].type == moduleCP['suplement']){
  84. res[i].moduleDetailDTOList[param.idx] = param.data
  85. }
  86. }
  87. state.allMoudles = res
  88. },
  89. savePathInfo(state,param){
  90. state.pathInfo = param;
  91. },
  92. saveSysConfig(state,param){
  93. state.sysConfig = param;
  94. },
  95. saveAll(state,param){
  96. state.allMoudles = param;
  97. for(let k in param){
  98. if(param[k].type == moduleCP['diagT']){
  99. state.diagnose.origin = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  100. state.diagnose.datas = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  101. }else if(param[k].type == moduleCP['other']){
  102. state.others.origin = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  103. state.others.datas = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  104. }
  105. }
  106. },
  107. setOrigin(state,param){//取消选中时用
  108. const type = parseInt(param.type);
  109. const data = param.data;
  110. switch(type){
  111. case moduleCP['symp']: //症状情况
  112. state.symptom.origin = Object.assign({},state.symptom.origin,{[data.id]:data});
  113. break;
  114. case moduleCP['diagT']: //诊疗情况
  115. let diagData = state.diagnose.origin;
  116. for(let i in diagData){
  117. if(diagData[i].id == param.pId){
  118. let questionMapping = diagData[i].questionMapping;
  119. for(let k in questionMapping){
  120. if(questionMapping[k].id == data.id){
  121. questionMapping.splice(k,1,data);
  122. }
  123. }
  124. }
  125. }
  126. break;
  127. case moduleCP['other']:
  128. let otherData = state.others.origin;
  129. for(let i in otherData){
  130. if(otherData[i].id == param.pId){
  131. let questionMapping = otherData[i].questionMapping;
  132. for(let k in questionMapping){
  133. if(questionMapping[k].id == data.id){
  134. questionMapping.splice(k,1,data);
  135. }
  136. }
  137. }
  138. }
  139. break;
  140. case moduleCP['suplement']:
  141. break;
  142. default:
  143. break;
  144. }
  145. },
  146. setDatas(state,param){
  147. // ppId--每一道题的id;pId--每个选项的id
  148. const type = parseInt(param.type);
  149. const data = param.data;
  150. const ppId = param.ppId;
  151. switch(type){
  152. case moduleCP['symp']:
  153. state.symptom.datas = Object.assign({},state.symptom.datas,{[param.pId]:data});
  154. break;
  155. case moduleCP['diagT']: //诊疗情况
  156. let diagData = state.diagnose.datas;
  157. for(let i in diagData){
  158. if(diagData[i].id == ppId){
  159. let questionMapping = diagData[i].questionMapping;
  160. for(let k in questionMapping){
  161. if(questionMapping[k].id == data.id){
  162. // questionMapping[k].questionMapping = data.questionMapping;
  163. questionMapping.splice(k,1,data);
  164. }
  165. }
  166. }
  167. }
  168. break;
  169. case moduleCP['other']:
  170. let otherData = state.others.datas;
  171. for(let i in otherData){
  172. if(otherData[i].id == ppId){
  173. let questionMapping = otherData[i].questionMapping;
  174. for(let k in questionMapping){
  175. if(questionMapping[k].id == data.id){
  176. questionMapping[k].questionMapping = data.questionMapping;
  177. }
  178. }
  179. }
  180. }
  181. break;
  182. case moduleCP['suplement']:
  183. break;
  184. default:
  185. break;
  186. }
  187. },
  188. setText(state,param){
  189. const type = parseInt(param.type);
  190. switch(type){
  191. case moduleCP['symp']:
  192. // 对象易更新但顺序无法控制
  193. // state.symptom.text = Object.assign({},state.symptom.text,{[param.pId]:param.text});
  194. let text = state.symptom.text;
  195. if(text.length > 0){
  196. for(let i in text){
  197. // 点完成时才覆盖,单纯点开再关闭不覆盖flag
  198. if(text[i].pId==param.pId){
  199. if(param.flag){
  200. text.splice(i,1,param);
  201. }
  202. return
  203. }
  204. }
  205. text.push(param);
  206. }else{
  207. text.push(param);
  208. }
  209. break;
  210. case moduleCP['diagT']: //诊疗情况
  211. let diaText = JSON.parse(JSON.stringify(state.diagnose.text));
  212. // 先判断order,然后判断index
  213. let item = diaText[param.order];
  214. if(item){
  215. // 判断是对象还是数组--数组则区分index
  216. if(Array.isArray(item)){
  217. if(param.flag){//详情完成-覆盖
  218. item[param.index] = param;
  219. }else{ //直接点label--无则覆盖
  220. if(!item[param.index]){
  221. item[param.index] = param;
  222. }
  223. }
  224. }else{
  225. if(param.flag){
  226. diaText[param.order] = param;
  227. }
  228. }
  229. }else{
  230. if(param.arrFlag){
  231. let temp = [];
  232. temp[param.index] = param;
  233. diaText[param.order] = temp;
  234. }else{
  235. diaText[param.order] = param;
  236. }
  237. }
  238. state.diagnose.text = diaText;
  239. /*if(diaText.length > 0){
  240. for(let i in diaText){
  241. if(diaText[i].pId==param.pId){
  242. if(param.flag){
  243. diaText.splice(i,1,param);
  244. }
  245. return
  246. }
  247. }
  248. diaText.push(param);
  249. }else{
  250. diaText.push(param);
  251. }*/
  252. break;
  253. case moduleCP['other']: //其他情况
  254. let otherText = JSON.parse(JSON.stringify(state.others.text));
  255. let oitem = otherText[param.order];
  256. if(oitem){
  257. // 判断是对象还是数组--数组则区分index
  258. if(Array.isArray(oitem)){
  259. if(param.flag){//详情完成-覆盖
  260. oitem[param.index] = param;
  261. }else{ //直接点label--无则覆盖
  262. if(!oitem[param.index]){
  263. oitem[param.index] = param;
  264. }
  265. }
  266. }else{
  267. if(param.flag){
  268. otherText[param.order] = param;
  269. }
  270. }
  271. }else{
  272. if(param.arrFlag){
  273. let temp = [];
  274. temp[param.index] = param;
  275. otherText[param.order] = temp;
  276. }else{
  277. otherText[param.order] = param;
  278. }
  279. }
  280. state.others.text = otherText;
  281. /*if(otherText.length > 0){
  282. for(let i in otherText){
  283. if(otherText[i].pId==param.pId){
  284. if(param.flag){
  285. otherText.splice(i,1,param);
  286. }
  287. return
  288. }
  289. }
  290. otherText.push(param);
  291. }else{
  292. otherText.push(param);
  293. }*/
  294. break;
  295. case moduleCP['suplement']:
  296. let addText = state.addContent.txt
  297. state.addContent.origin = param.data
  298. state.addContent.txt = getAllStr(param).allStr
  299. state.addContent.txtDoc = getAllStr(param).allStrDoc
  300. break;
  301. default:
  302. break;
  303. }
  304. },
  305. delText(state,param){
  306. const type = parseInt(param.type);
  307. switch(type){
  308. case moduleCP['symp']:
  309. let text = state.symptom.text;
  310. for(let i in text){
  311. if(text[i].pId==param.pId){
  312. text.splice(i,1)
  313. }
  314. }
  315. break;
  316. case moduleCP['diagT']: //诊疗情况
  317. let diaText = JSON.parse(JSON.stringify(state.diagnose.text));
  318. let temp = diaText[param.order];
  319. temp[param.index] = null;
  320. state.diagnose.text = diaText;
  321. // let diaText = state.diagnose.text;
  322. /*for(let i in diaText){
  323. if(diaText[i].pId==param.pId){
  324. diaText.splice(i,1)
  325. }
  326. }*/
  327. break;
  328. case moduleCP['other']:
  329. let otherText = JSON.parse(JSON.stringify(state.others.text));
  330. let otemp = otherText[param.order];
  331. otemp[param.index] = null;
  332. state.others.text = otherText;
  333. /*let otherText = state.others.text;
  334. for(let i in otherText){
  335. if(otherText[i].pId==param.pId){
  336. otherText.splice(i,1)
  337. }
  338. }*/
  339. break;
  340. case moduleCP['suplement']:
  341. break;
  342. default:
  343. break;
  344. }
  345. },
  346. setChoose(state,param){ //症状情况-已选症状
  347. state.symptom.choose = param.choose;
  348. },
  349. delChoose(state,param){ //详情有必填项未填--移除症状
  350. const id = param.id;
  351. let symp = state.symptom.choose;
  352. for(let i=0; i<symp.length; i++){
  353. if(id == (symp[i].id || symp[i].questionId)){
  354. symp.splice(i,1);
  355. }
  356. }
  357. },
  358. setImgFile(state,param){//区别模块
  359. const type = parseInt(param.type);
  360. switch(type){
  361. case moduleCP['symp']:
  362. break;
  363. case moduleCP['diagT']: //诊疗情况
  364. state.diagnose.imgFile.push(param);
  365. break;
  366. case moduleCP['other']:
  367. break;
  368. case moduleCP['suplement']:
  369. break;
  370. default:
  371. break;
  372. }
  373. },
  374. setImgSrc(state,param){
  375. const key = param.key;
  376. const src = param.src;
  377. const type = parseInt(param.type);
  378. switch(type){
  379. case moduleCP['symp']:
  380. break;
  381. case moduleCP['diagT']:
  382. state.diagnose.imgSrc = Object.assign({},state.diagnose.imgSrc,{[key]:src});
  383. break;
  384. case moduleCP['other']:
  385. break;
  386. case moduleCP['suplement']:
  387. break;
  388. default:
  389. break;
  390. }
  391. },
  392. deleImg(state,param){
  393. const key = param.key;
  394. const type = parseInt(param.type);
  395. switch(type){
  396. case moduleCP['symp']:
  397. break;
  398. case moduleCP['diagT']:
  399. let data = state.diagnose.imgFile;
  400. for(let i=0; i<data.length;i++){
  401. if(data[i].key==key){
  402. data.splice(i,1)
  403. }
  404. }
  405. break;
  406. case moduleCP['other']:
  407. break;
  408. case moduleCP['suplement']:
  409. break;
  410. default:
  411. break;
  412. }
  413. },
  414. deleSrc(state,param){
  415. const key = param.key;
  416. const type = parseInt(param.type);
  417. switch(type){
  418. case moduleCP['symp']:
  419. break;
  420. case moduleCP['diagT']:
  421. let data = state.diagnose.imgFile;
  422. let obj = state.diagnose.imgSrc;
  423. delete(obj[key]);
  424. state.diagnose.imgSrc = Object.assign({},obj);
  425. break;
  426. case moduleCP['other']:
  427. break;
  428. case moduleCP['suplement']:
  429. break;
  430. default:
  431. break;
  432. }
  433. },
  434. handleToggleShow(state,flg){
  435. state.loadingShow = flg
  436. }
  437. }
  438. })
  439. export default store;