import Vue from 'vue'; import Vuex from 'vuex'; import {deepClone,getAllStr,moduleCP} from '@utils/tools.js' Vue.use(Vuex); const store = new Vuex.Store({ state:{ pathInfo:{}, //患者信息-后续提交要用 sysConfig:[], //系统配置项 allMoudles:[], //模板 symptom:{ //症状情况 choose:[], origin:{}, datas:{}, text:[], }, diagnose:{ //诊疗 origin:[], //模板数据 datas:[], text:[], imgFile:[],//上传图片信息file imgSrc:{},//上传的图片信息src }, others:{ //其他情况 origin:[], //模板数据 datas:[], text:[], imgFile:[], imgSrc:{}, }, addContent:{ origin:[], txt:'', } }, mutations:{ initAllData(state){ state.symptom={ //症状情况 choose:[], origin:{}, datas:{}, text:[], } state.diagnose={ //诊疗 origin:[], //模板数据 datas:[], text:[], imgFile:[], imgSrc:{}, } state.others={ //其他情况 origin:[], //模板数据 datas:[], text:[], imgFile:[], imgSrc:{}, } state.addContent={ origin:[], txt:'', } }, setDataAll(state,data){ let res = state.allMoudles res[1].moduleDetailDTOList[0].questionMapping[1].questionMapping = data state.allMoudles = res }, savePathInfo(state,param){ state.pathInfo = param; }, saveSysConfig(state,param){ state.sysConfig = param; }, saveAll(state,param){ state.allMoudles = param; for(let k in param){ if(param[k].type == moduleCP['diagT']){ state.diagnose.origin = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList)) state.diagnose.datas = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList)) }else if(param[k].type == moduleCP['other']){ state.others.origin = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList)) state.others.datas = JSON.parse(JSON.stringify(param[k].moduleDetailDTOList)) } } }, setOrigin(state,param){//取消选中时用 const type = parseInt(param.type); const data = param.data; switch(type){ case moduleCP['symp']: //症状情况 state.symptom.origin = Object.assign({},state.symptom.origin,{[data.id]:data}); break; case moduleCP['diagT']: //诊疗情况 let diagData = state.diagnose.origin; for(let i in diagData){ if(diagData[i].id == param.pId){ let questionMapping = diagData[i].questionMapping; for(let k in questionMapping){ if(questionMapping[k].id == data.id){ questionMapping.splice(k,1,data); } } } } break; case moduleCP['other']: let otherData = state.others.origin; for(let i in otherData){ if(otherData[i].id == param.pId){ let questionMapping = otherData[i].questionMapping; for(let k in questionMapping){ if(questionMapping[k].id == data.id){ questionMapping.splice(k,1,data); } } } } break; case moduleCP['suplement']: break; default: break; } }, setDatas(state,param){ // ppId--每一道题的id;pId--每个选项的id const type = parseInt(param.type); const data = param.data; const ppId = param.ppId; switch(type){ case moduleCP['symp']: state.symptom.datas = Object.assign({},state.symptom.datas,{[param.pId]:data}); break; case moduleCP['diagT']: //诊疗情况 let diagData = state.diagnose.datas; for(let i in diagData){ if(diagData[i].id == ppId){ let questionMapping = diagData[i].questionMapping; for(let k in questionMapping){ if(questionMapping[k].id == data.id){ // questionMapping[k].questionMapping = data.questionMapping; questionMapping.splice(k,1,data); } } } } break; case moduleCP['other']: let otherData = state.others.datas; for(let i in otherData){ if(otherData[i].id == ppId){ let questionMapping = otherData[i].questionMapping; for(let k in questionMapping){ if(questionMapping[k].id == data.id){ questionMapping[k].questionMapping = data.questionMapping; } } } } break; case moduleCP['suplement']: break; default: break; } }, setText(state,param){ const type = parseInt(param.type); switch(type){ case moduleCP['symp']: // 对象易更新但顺序无法控制 // state.symptom.text = Object.assign({},state.symptom.text,{[param.pId]:param.text}); let text = state.symptom.text; if(text.length > 0){ for(let i in text){ // 点完成时才覆盖,单纯点开再关闭不覆盖flag if(text[i].pId==param.pId){ if(param.flag){ text.splice(i,1,param); } return } } text.push(param); }else{ text.push(param); } break; case moduleCP['diagT']: //诊疗情况 let diaText = state.diagnose.text; if(diaText.length > 0){ for(let i in diaText){ if(diaText[i].pId==param.pId){ if(param.flag){ diaText.splice(i,1,param); } return } } diaText.push(param); }else{ diaText.push(param); } break; case moduleCP['other']: //其他情况 let otherText = state.others.text; if(otherText.length > 0){ for(let i in otherText){ if(otherText[i].pId==param.pId){ if(param.flag){ otherText.splice(i,1,param); } return } } otherText.push(param); }else{ otherText.push(param); } break; case moduleCP['suplement']: let addText = state.addContent.txt state.addContent.origin = param.data state.addContent.txt = getAllStr(param) break; default: break; } }, delText(state,param){ const type = parseInt(param.type); switch(type){ case moduleCP['symp']: let text = state.symptom.text; for(let i in text){ if(text[i].pId==param.pId){ text.splice(i,1) } } break; case moduleCP['diagT']: //诊疗情况 let diaText = state.diagnose.text; for(let i in diaText){ if(diaText[i].pId==param.pId){ diaText.splice(i,1) } } break; case moduleCP['other']: let otherText = state.others.text; for(let i in otherText){ if(otherText[i].pId==param.pId){ otherText.splice(i,1) } } break; case moduleCP['suplement']: break; default: break; } }, setChoose(state,param){ //症状情况-已选症状 state.symptom.choose = param.choose; }, setImgFile(state,param){//区别模块 const type = parseInt(param.type); switch(type){ case moduleCP['symp']: break; case moduleCP['diagT']: //诊疗情况 state.diagnose.imgFile.push(param); break; case moduleCP['other']: break; case moduleCP['suplement']: break; default: break; } }, setImgSrc(state,param){ const key = param.key; const src = param.src; const type = parseInt(param.type); switch(type){ case moduleCP['symp']: break; case moduleCP['diagT']: state.diagnose.imgSrc = Object.assign({},state.diagnose.imgSrc,{[key]:src}); break; case moduleCP['other']: break; case moduleCP['suplement']: break; default: break; } }, deleImg(state,param){ const key = param.key; const type = parseInt(param.type); switch(type){ case moduleCP['symp']: break; case moduleCP['diagT']: let data = state.diagnose.imgFile; for(let i=0; i