store.js 12 KB

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