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:{ searchShow:false, pathInfo:{}, //患者信息-后续提交要用 sysConfig:[], //系统配置项 allMoudles:[], //模板 scroll:{ x:0,y:0 }, symptom:{ //症状情况 choose:[], origin:{}, datas:{}, text:[], }, diagnose:{ //诊疗 origin:[], //模板数据 datas:[], text:[], imgFile:[],//上传图片信息file imgSrc:{},//上传的图片信息src }, others:{ //其他情况 origin:[], //模板数据 datas:[], text:[], imgFile:[], imgSrc:{}, }, addContent:{ origin:[], txt:'', txtDoc:'' }, activeModule:{},//有效显示的模块 loadingShow:false, detailInfo:{}, detailShow:false, finish:{ //标识已填 '1':true, '51':false, '3':false, '52':false }, currentTab:{ //标识当前tab页 '1':true, '51':false, '3':false, '52':false }, tabType: { "1": 1, "51": 0, "3": 0, "52": 0, }, }, mutations:{ setFinish(state,param){ let obj = state.finish let obj1 = state.currentTab for(let key in obj){ if(key == param){ obj[key] = true obj1[key] = true }else{ obj1[key] = false } } state.finish = obj }, setActiveModule(state,param){ state.activeModule = param }, 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:'', txtDoc:'' } }, setDetail(state,param){//明细 const detail = param.detail; if(JSON.stringify(detail)=='{}'){ state.detailShow = false; }else{ if(param.sign!=1){ state.detailInfo = Object.assign({},param); state.detailShow = true; }else{ if(param.idx == 0&&detail.idx == 1){ state.detailInfo = Object.assign({},param); state.detailShow = true; }else{ state.detailShow = false; } } } }, setSearchShow(state,flg){//搜索显示与否 state.searchShow = flg; }, setDataAll(state,param){ let res = state.allMoudles for(let i = 0;i 0 && param.filter(item => item.code == "symptoms_show")[0].value, "51": param.length > 0 && param.filter(item => item.code == "diagnosis_show")[0].value, "3": param.length > 0 && param.filter(item => item.code == "omhistory_show")[0].value, "52": param.length > 0 && param.filter(item => item.code == "replenish_show")[0].value, } state.tabType = tabType }, 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); break; case moduleCP['diagT']: //诊疗情况 let diaText = JSON.parse(JSON.stringify(state.diagnose.text)); // 先判断order,然后判断index let item = diaText[param.order]; if(item){ // 判断是对象还是数组--数组则区分index if(Array.isArray(item)){ if(param.flag){//详情完成-覆盖 item[param.index] = param; }else{ //直接点label--无则覆盖 if(!item[param.index]){ item[param.index] = param; } } }else{ if(param.flag){ diaText[param.order] = param; } } }else{ if(param.arrFlag){ let temp = []; temp[param.index] = param; diaText[param.order] = temp; }else{ diaText[param.order] = param; } } state.diagnose.text = diaText; break; case moduleCP['other']: //其他情况 let otherText = JSON.parse(JSON.stringify(state.others.text)); let oitem = otherText[param.order]; if(oitem){ // 判断是对象还是数组--数组则区分index if(Array.isArray(oitem)){ if(param.flag){//详情完成-覆盖 oitem[param.index] = param; }else{ //直接点label--无则覆盖 if(!oitem[param.index]){ oitem[param.index] = param; } } }else{ if(param.flag){ otherText[param.order] = param; } } }else{ if(param.arrFlag){ let temp = []; temp[param.index] = param; otherText[param.order] = temp; }else{ otherText[param.order] = param; } } state.others.text = otherText; break; case moduleCP['suplement']: let addText = state.addContent.txt state.addContent.origin = param.data state.addContent.txt = getAllStr(param).allStr state.addContent.txtDoc = getAllStr(param).allStrDoc 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 = JSON.parse(JSON.stringify(state.diagnose.text)); let temp = diaText[param.order]; temp[param.index] = null; state.diagnose.text = diaText; break; case moduleCP['other']: let otherText = JSON.parse(JSON.stringify(state.others.text)); let otemp = otherText[param.order]; otemp[param.index] = null; state.others.text = otherText; break; case moduleCP['suplement']: break; default: break; } }, setChoose(state,param){ //症状情况-已选症状 state.symptom.choose = param.choose; }, setScroll(state,data){ //症状情况-已选症状 state.scroll = data; }, delChoose(state,param){ //详情有必填项未填--移除症状 const id = param.id; let symp = state.symptom.choose; for(let i=0; i