store.js 9.7 KB

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