store.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. pathInfo:{}, //患者信息-后续提交要用
  8. sysConfig:[], //系统配置项
  9. allMoudles:[], //模板
  10. symptom:{ //症状情况
  11. choose:[],
  12. origin:{},
  13. datas:{},
  14. text:[],
  15. },
  16. diagnose:{ //诊疗
  17. origin:[], //模板数据
  18. datas:[],
  19. text:[],
  20. imgFile:[],//上传图片信息file
  21. imgSrc:{},//上传的图片信息src
  22. },
  23. others:{ //其他情况
  24. origin:[], //模板数据
  25. datas:[],
  26. text:[],
  27. imgFile:[],
  28. imgSrc:{},
  29. },
  30. addContent:{
  31. origin:[],
  32. txt:'',
  33. }
  34. },
  35. mutations:{
  36. initAllData(state){
  37. state.symptom={ //症状情况
  38. choose:[],
  39. origin:{},
  40. datas:{},
  41. text:[],
  42. }
  43. state.diagnose={ //诊疗
  44. origin:[], //模板数据
  45. datas:[],
  46. text:[],
  47. imgFile:[],
  48. imgSrc:{},
  49. }
  50. state.others={ //其他情况
  51. origin:[], //模板数据
  52. datas:[],
  53. text:[],
  54. imgFile:[],
  55. imgSrc:{},
  56. }
  57. state.addContent={
  58. origin:[],
  59. txt:'',
  60. }
  61. },
  62. setDataAll(state,param){
  63. let res = state.allMoudles
  64. for(let i = 0;i<res.length;i++){
  65. if(res[i].type == moduleCP['suplement']){
  66. res[i].moduleDetailDTOList[param.idx] = param.data
  67. }
  68. }
  69. state.allMoudles = res
  70. },
  71. savePathInfo(state,param){
  72. state.pathInfo = param;
  73. },
  74. saveSysConfig(state,param){
  75. state.sysConfig = param;
  76. },
  77. saveAll(state,param){
  78. state.allMoudles = param;
  79. for(let k in param){
  80. if(param[k].type == moduleCP['diagT']){
  81. state.diagnose.origin = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  82. state.diagnose.datas = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  83. }else if(param[k].type == moduleCP['other']){
  84. state.others.origin = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  85. state.others.datas = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList))
  86. }
  87. }
  88. },
  89. setOrigin(state,param){//取消选中时用
  90. const type = parseInt(param.type);
  91. const data = param.data;
  92. switch(type){
  93. case moduleCP['symp']: //症状情况
  94. state.symptom.origin = Object.assign({},state.symptom.origin,{[data.id]:data});
  95. break;
  96. case moduleCP['diagT']: //诊疗情况
  97. let diagData = state.diagnose.origin;
  98. for(let i in diagData){
  99. if(diagData[i].id == param.pId){
  100. let questionMapping = diagData[i].questionMapping;
  101. for(let k in questionMapping){
  102. if(questionMapping[k].id == data.id){
  103. questionMapping.splice(k,1,data);
  104. }
  105. }
  106. }
  107. }
  108. break;
  109. case moduleCP['other']:
  110. let otherData = state.others.origin;
  111. for(let i in otherData){
  112. if(otherData[i].id == param.pId){
  113. let questionMapping = otherData[i].questionMapping;
  114. for(let k in questionMapping){
  115. if(questionMapping[k].id == data.id){
  116. questionMapping.splice(k,1,data);
  117. }
  118. }
  119. }
  120. }
  121. break;
  122. case moduleCP['suplement']:
  123. break;
  124. default:
  125. break;
  126. }
  127. },
  128. setDatas(state,param){
  129. // ppId--每一道题的id;pId--每个选项的id
  130. const type = parseInt(param.type);
  131. const data = param.data;
  132. const ppId = param.ppId;
  133. switch(type){
  134. case moduleCP['symp']:
  135. state.symptom.datas = Object.assign({},state.symptom.datas,{[param.pId]:data});
  136. break;
  137. case moduleCP['diagT']: //诊疗情况
  138. let diagData = state.diagnose.datas;
  139. for(let i in diagData){
  140. if(diagData[i].id == ppId){
  141. let questionMapping = diagData[i].questionMapping;
  142. for(let k in questionMapping){
  143. if(questionMapping[k].id == data.id){
  144. // questionMapping[k].questionMapping = data.questionMapping;
  145. questionMapping.splice(k,1,data);
  146. }
  147. }
  148. }
  149. }
  150. break;
  151. case moduleCP['other']:
  152. let otherData = state.others.datas;
  153. for(let i in otherData){
  154. if(otherData[i].id == ppId){
  155. let questionMapping = otherData[i].questionMapping;
  156. for(let k in questionMapping){
  157. if(questionMapping[k].id == data.id){
  158. questionMapping[k].questionMapping = data.questionMapping;
  159. }
  160. }
  161. }
  162. }
  163. break;
  164. case moduleCP['suplement']:
  165. break;
  166. default:
  167. break;
  168. }
  169. },
  170. setText(state,param){
  171. const type = parseInt(param.type);
  172. switch(type){
  173. case moduleCP['symp']:
  174. // 对象易更新但顺序无法控制
  175. // state.symptom.text = Object.assign({},state.symptom.text,{[param.pId]:param.text});
  176. let text = state.symptom.text;
  177. if(text.length > 0){
  178. for(let i in text){
  179. // 点完成时才覆盖,单纯点开再关闭不覆盖flag
  180. if(text[i].pId==param.pId){
  181. if(param.flag){
  182. text.splice(i,1,param);
  183. }
  184. return
  185. }
  186. }
  187. text.push(param);
  188. }else{
  189. text.push(param);
  190. }
  191. break;
  192. case moduleCP['diagT']: //诊疗情况
  193. let diaText = state.diagnose.text;
  194. if(diaText.length > 0){
  195. for(let i in diaText){
  196. if(diaText[i].pId==param.pId){
  197. if(param.flag){
  198. diaText.splice(i,1,param);
  199. }
  200. return
  201. }
  202. }
  203. diaText.push(param);
  204. }else{
  205. diaText.push(param);
  206. }
  207. break;
  208. case moduleCP['other']: //其他情况
  209. let otherText = state.others.text;
  210. if(otherText.length > 0){
  211. for(let i in otherText){
  212. if(otherText[i].pId==param.pId){
  213. if(param.flag){
  214. otherText.splice(i,1,param);
  215. }
  216. return
  217. }
  218. }
  219. otherText.push(param);
  220. }else{
  221. otherText.push(param);
  222. }
  223. break;
  224. case moduleCP['suplement']:
  225. let addText = state.addContent.txt
  226. state.addContent.origin = param.data
  227. state.addContent.txt = getAllStr(param)
  228. break;
  229. default:
  230. break;
  231. }
  232. },
  233. delText(state,param){
  234. const type = parseInt(param.type);
  235. switch(type){
  236. case moduleCP['symp']:
  237. let text = state.symptom.text;
  238. for(let i in text){
  239. if(text[i].pId==param.pId){
  240. text.splice(i,1)
  241. }
  242. }
  243. break;
  244. case moduleCP['diagT']: //诊疗情况
  245. let diaText = state.diagnose.text;
  246. for(let i in diaText){
  247. if(diaText[i].pId==param.pId){
  248. diaText.splice(i,1)
  249. }
  250. }
  251. break;
  252. case moduleCP['other']:
  253. let otherText = state.others.text;
  254. for(let i in otherText){
  255. if(otherText[i].pId==param.pId){
  256. otherText.splice(i,1)
  257. }
  258. }
  259. break;
  260. case moduleCP['suplement']:
  261. break;
  262. default:
  263. break;
  264. }
  265. },
  266. setChoose(state,param){ //症状情况-已选症状
  267. state.symptom.choose = param.choose;
  268. },
  269. setImgFile(state,param){//区别模块
  270. const type = parseInt(param.type);
  271. switch(type){
  272. case moduleCP['symp']:
  273. break;
  274. case moduleCP['diagT']: //诊疗情况
  275. state.diagnose.imgFile.push(param);
  276. break;
  277. case moduleCP['other']:
  278. break;
  279. case moduleCP['suplement']:
  280. break;
  281. default:
  282. break;
  283. }
  284. },
  285. setImgSrc(state,param){
  286. const key = param.key;
  287. const src = param.src;
  288. const type = parseInt(param.type);
  289. switch(type){
  290. case moduleCP['symp']:
  291. break;
  292. case moduleCP['diagT']:
  293. state.diagnose.imgSrc = Object.assign({},state.diagnose.imgSrc,{[key]:src});
  294. break;
  295. case moduleCP['other']:
  296. break;
  297. case moduleCP['suplement']:
  298. break;
  299. default:
  300. break;
  301. }
  302. },
  303. deleImg(state,param){
  304. const key = param.key;
  305. const type = parseInt(param.type);
  306. switch(type){
  307. case moduleCP['symp']:
  308. break;
  309. case moduleCP['diagT']:
  310. let data = state.diagnose.imgFile;
  311. for(let i=0; i<data.length;i++){
  312. if(data[i].key==key){
  313. data.splice(i,1)
  314. }
  315. }
  316. break;
  317. case moduleCP['other']:
  318. break;
  319. case moduleCP['suplement']:
  320. break;
  321. default:
  322. break;
  323. }
  324. },
  325. deleSrc(state,param){
  326. const key = param.key;
  327. const type = parseInt(param.type);
  328. switch(type){
  329. case moduleCP['symp']:
  330. break;
  331. case moduleCP['diagT']:
  332. let data = state.diagnose.imgFile;
  333. let obj = state.diagnose.imgSrc;
  334. delete(obj[key]);
  335. state.diagnose.imgSrc = Object.assign({},obj);
  336. break;
  337. case moduleCP['other']:
  338. break;
  339. case moduleCP['suplement']:
  340. break;
  341. default:
  342. break;
  343. }
  344. },
  345. }
  346. })
  347. export default store;