import { GET_ASSIST_SEARCH_LIST, GET_ASSIST_LABEL, DEL_ASSIST_LABEL, CHANGE_ASSIST_VAL, CHANGE_DATE, CLEAR_ASSIST_DATA, ADD_ASSIST_LABEL, SEARCH_HOSPITAL_PAC, SEARCH_HOSPITAL_PAC_SON, SET_ALLCHECKS, SELECT_ONE_CHECKS, SHOW_IN_ICSSS } from '../types/assistCheck'; import store from '@store'; const initSearchList = { list: [], //点击的结果 assistLabel: [], //搜索的结果 dataString: '', //结果拼接 assistVal: '', hospitalPac: [], //医院检索到的 hospitalPacObj: {}, //组对应的明细(单选多选全选) selectGroupList: [], //选的组的明细可能有多个组 allCheck: false, //全选反选 checkedList: [], //选中的小项 checkedListImport: [], //辅检导入 allCheckLis:[],//所有导入数据 msgObj:{ name:'', patientNum:'' } } import { getCurrentDate} from '@utils/tools'; export default (state = initSearchList, action) => { if (action.type == SHOW_IN_ICSSS) { const newState = Object.assign({}, state); let tmpGroup = JSON.parse(JSON.stringify(newState.selectGroupList)) let tmpListImport = JSON.parse(JSON.stringify(newState.checkedListImport)) let tempArrs = JSON.parse(JSON.stringify(newState.assistLabel)),importLis=[]; for (let i = 0; i < tmpGroup.length; i++) { for (let k = 0; k < tmpGroup[i].pacsResultDTO.length; k++) { let tmpObj = {} tmpObj.time = tmpGroup[i].Rtime tmpObj.disabled = true tmpObj.name = tmpGroup[i].pacsResultDTO[k].checkItem tmpObj.value = tmpGroup[i].pacsResultDTO[k].imagingResults tmpObj.imagingDiagnose = tmpGroup[i].pacsResultDTO[k].imagingDiagnose importLis.push(tmpObj) tempArrs.push(tmpObj) } } tmpListImport.push(importLis) newState.checkedListImport = [...tmpListImport] newState.allCheckLis = [...tempArrs] newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) newState.hospitalPac = [] //医院检索到的 newState.hospitalPacObj = {} //组对应的明细(单选多选全选) newState.selectGroupList = [] //选的组的明细可能有多个组 newState.allCheck = false //全选反选 newState.checkedList = [] //选中的小项 newState.msgObj={name:'',patientNum:''} return newState; } if (action.type == SELECT_ONE_CHECKS) { const newState = Object.assign({}, state); let listWrap = JSON.parse(JSON.stringify(newState.hospitalPacObj)) let tmpGroup = JSON.parse(JSON.stringify(newState.selectGroupList)) let tmpLen = listWrap.pacsResultDTO.length; let tmpCheckedLis = JSON.parse(JSON.stringify(newState.checkedList)) let numS = 0; if (tmpCheckedLis.indexOf(action.name) == -1) { //添加选中 let tempArr = newState.checkedList; tempArr.push(action.name); newState.checkedList = [...tempArr] for (let m = 0; m < tmpGroup.length; m++) { if (tmpGroup[m].checkItem == action.checkItem) { //右侧有选中相同组的明细 tmpGroup[m].pacsResultDTO.push(action.item) } else { ++numS } } if (numS == tmpGroup.length) { //直接添加到右侧 listWrap.pacsResultDTO = [] listWrap.pacsResultDTO.push(action.item) tmpGroup.push(listWrap) } newState.selectGroupList = [...tmpGroup] //右侧已选中的项目 if (tempArr.length == tmpLen) { newState.allCheck = true; } else { newState.allCheck = false; } } else { //去除选中 let tempArr = newState.checkedList; tempArr.splice(tempArr.findIndex(item => item === action.name), 1) newState.checkedList = [...tempArr] for (let i = 0; i < tmpGroup.length; i++) { if (tmpGroup[i].checkItem == action.checkItem) { //右侧肯定有相同组的 let tmpArr = [] for (let k = 0; k < tmpGroup[i].pacsResultDTO.length; k++) { if (action.name != tmpGroup[i].pacsResultDTO[k].checkItem) { tmpArr.push(tmpGroup[i].pacsResultDTO[k]) } } if(tmpArr.length == 0){ tmpGroup.splice(i,1) }else{ tmpGroup[i].pacsResultDTO = [...tmpArr] } } } newState.selectGroupList = tmpGroup //右侧已选中的项目 if (tempArr.length == listWrap.pacsResultDTO.length) { newState.allCheck = true; } else { newState.allCheck = false; } } return newState; } if (action.type == SET_ALLCHECKS) { const newState = Object.assign({}, state); let flg = newState.allCheck let listWrap = newState.hospitalPacObj let tmpGroup = newState.selectGroupList let tmpCheckedLis = [] newState.allCheck = !flg if (!flg) { //全选 let numFst = 0 for (let i = 0; i < tmpGroup.length; i++) { if (listWrap.checkItem == tmpGroup[i].checkItem) { ++numFst tmpGroup[i].pacsResultDTO = listWrap.pacsResultDTO } } for (let m = 0; m < listWrap.pacsResultDTO.length; m++) { tmpCheckedLis.push(listWrap.pacsResultDTO[m].checkItem) } if (numFst == 0) { tmpGroup.push(listWrap) } newState.checkedList = [...tmpCheckedLis] newState.selectGroupList = [...tmpGroup] } else { //反选 for (let j = 0; j < tmpGroup.length; j++) { if (listWrap.checkItem == tmpGroup[j].checkItem) { tmpGroup.splice(j, 1) } } newState.checkedList = [] newState.selectGroupList = [...tmpGroup] } return newState; } if (action.type == SEARCH_HOSPITAL_PAC_SON) { const newState = Object.assign({}, state); let tmpArr = action.list let tmpSelect = newState.selectGroupList let tmpSelectSon = [] for (let i = 0; i < tmpSelect.length; i++) { if (tmpSelect[i].checkItem == action.name) { for (let k = 0; k < tmpSelect[i].pacsResultDTO.length; k++) { tmpSelectSon.push(tmpSelect[i].pacsResultDTO[k].checkItem) } } } newState.checkedList = [...tmpSelectSon] if (tmpSelectSon.length == tmpArr.pacsResultDTO.length) { newState.allCheck = true; } else { newState.allCheck = false; } newState.hospitalPacObj = tmpArr return newState; } if (action.type == SEARCH_HOSPITAL_PAC) { const newState = Object.assign({}, state); newState.hospitalPac = action.list newState.msgObj = action.msg newState.allCheck = false newState.hospitalPacObj = {} return newState; } if (action.type == ADD_ASSIST_LABEL) { const newState = Object.assign({}, state); let tempArr = newState.assistLabel; for (let i = 0; i < action.lis.length; i++) { tempArr.push(action.lis[i]); } for (let i = 0; i < tempArr.length; i++) { if (i == action.idx) { tempArr[i].time = action.date newState.assistLabel = [...tempArr] } } newState.assistLabel = [...tempArr] newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) return newState; } if (action.type == GET_ASSIST_SEARCH_LIST) { //右侧推送添加到左侧 const newState = Object.assign({}, state); newState.list = action.list newState.assistVal = action.val newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) return newState; } if (action.type == GET_ASSIST_LABEL) { //默认 const newState = Object.assign({}, state); const tempArrs = newState.assistLabel; let tempArr = []; let tmpCommonLis = store.getState().homePage.assistList; if (action.sign == 'common') { let tmpAssistList = JSON.parse(JSON.stringify(tmpCommonLis)) tempArr = tmpAssistList; } else { tempArr = newState.list } for (let i = 0; i < tempArr.length; i++) { if (tempArr[i].conceptId == action.id && i == action.idx) { tempArr[i].time = getCurrentDate(1); tempArrs.push(tempArr[i]); newState.assistLabel = [...tempArrs]; } } newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) return newState; } if (action.type == DEL_ASSIST_LABEL) { //删除 const newState = Object.assign({}, state); let tempArr = newState.assistLabel,tempArrs = []; let tmpImportLis = newState.checkedListImport; if(action.flg == 0){//删除辅检导入 tmpImportLis.splice(action.idx,1) }else{ for (let k = 0; k < tempArr.length; k++) { if (k != action.idx) { tempArrs.push(tempArr[k]) } } newState.assistLabel = [...tempArrs] } newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) return newState; } if (action.type == CHANGE_ASSIST_VAL) { //改变输入值 const newState = Object.assign({}, state); const tempArr = newState.assistLabel; for (let i = 0; i < tempArr.length; i++) { if (i == action.idx) { tempArr[i].value = action.val newState.assistLabel = [...tempArr] } } newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) return newState; } if (action.type == CHANGE_DATE) { //新增 const newState = Object.assign({}, state); const tempArr = newState.assistLabel; for (let i = 0; i < tempArr.length; i++) { if (i == action.idx) { tempArr[i].time = action.date newState.assistLabel = [...tempArr] } } newState.dataString = getAllString(newState.checkedListImport,newState.assistLabel) return newState; } if (action.type == CLEAR_ASSIST_DATA) { const newState = Object.assign({}, state); newState.assistLabel = [...action.data]; newState.dataString = action.saveText; newState.checkedListImport = action.checkedListImport; return newState; } return state; } function getAllString(checkedListImport,assistLabel){ let tmpImportLis = [],tmpString=''; for(let i = 0;i < checkedListImport.length;i++){ for(let j = 0;j < checkedListImport[i].length;j++){ tmpImportLis.push(checkedListImport[i][j]) } } let tempArr = tmpImportLis.concat(assistLabel) for (let i = 0; i < tempArr.length; i++) { let tmpVal = tempArr[i].value ? tempArr[i].value.trim() : tempArr[i].value; tmpString += (tempArr[i].name + (tmpVal ? (':' + tmpVal) + ', ' : ': ') + (tempArr[i].time ? '报告日期:' + tempArr[i].time : '') + ';') } return tmpString; }