store.js 13 KB

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