store.js 9.8 KB

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