import { SEARCH_LIST, SET_LABEL, FILL_ACTIVE, GET_EXCEL, CHECK_VALUE_IS_CHANGE, CLEAR_LABEL, RESET_LABEL, CLEAR_ALL_LABEL, DEL_PART_ITEM, DEL_EXCEL_LIST, ADD_LABEL, SET_CONTEXT, SET_TIP, SEARCH_TYPE, DEL_ONE_PIC, CHECK_ON_OFF, REINSPECTDATA, } from '../types/inspect'; import store from '@store'; import { getStringPlus, getPushLists, getPushList,getCurrentDate} from '@utils/tools.js'; const initSearchList = { list: [], //搜索的结果 labelList: [], //选中的结果,也是需要保存的数据 labelListActive: [], //缓存值 fillActive: {}, //选中的标签的填写单 getExcelData: {}, //导入的数据 inspectStrPlus:'', getExcelDataList: [], //导入的数据 pushItem:[], //推送的数据 pushItems:[], //右侧模板预览的数据 inspectVal:'', context:{}, shType:2, labelListBig:[],//大项 labelListSmall:[],//小项 totalOrder:[],//开单项 } export default (state = initSearchList, action) => { if (action.type == CHECK_ON_OFF) { const newState = Object.assign({}, state); let tempArr = newState.labelListBig; let tempArrs = newState.labelListSmall; let tmpLis = action.item,tempBigOrder=[],tempSmallOrder=[],tempTotalOrder=[]; if(tmpLis&&tmpLis.flg == 1){ for(let i = 0;i < tempArr.length;i++){ if(tempArr[i].time == tmpLis.time){ let flg = tempArr[i].check; tempArr[i].check = !flg } } newState.labelListBig = [...tempArr] }else{ for(let i = 0;i < tempArrs.length;i++){ if(tempArrs[i].time == tmpLis.time){ let flg = tempArrs[i].check; tempArrs[i].check = !flg } } newState.labelListSmall = [...tempArrs] } tempBigOrder = tempArr.filter((item)=>item.check) tempSmallOrder = tempArrs.filter((item)=>item.check) tempTotalOrder=tempBigOrder.concat(tempSmallOrder) newState.totalOrder=[...tempTotalOrder] return newState; } if (action.type == DEL_ONE_PIC) { const newState = Object.assign({}, state); let tempArr = newState.labelListBig; let tempArrs = newState.labelListSmall; let tmpLis = action.item,tempBigOrder=[],tempSmallOrder=[],tempTotalOrder=[]; if(tmpLis&&tmpLis.flg == 1){//大项 tempArr = tempArr.filter((item)=>item.time != tmpLis.time) newState.labelListBig = [...tempArr] }else{//小项 tempArrs = tempArrs.filter((item)=> item.time != tmpLis.time ) newState.labelListSmall = [...tempArrs] } tempBigOrder = tempArr.filter((item)=>item.check) tempSmallOrder = tempArrs.filter((item)=>item.check) tempTotalOrder=tempBigOrder.concat(tempSmallOrder) newState.totalOrder=[...tempTotalOrder] return newState; } if (action.type == SET_TIP) { const newState = Object.assign({}, state); let tempArr = newState.labelListBig; let tempArrs = newState.labelListSmall; let tmpLis = action.item tempArrs = tempArrs.filter((item)=>{ if(item.time == tmpLis.time){ if(isNumber(action.value-0)){ item.value = action.value }else{ item.otherValue = action.value } } return item }) newState.labelListSmall = [...tempArrs] return newState; } if (action.type == SEARCH_TYPE) { const newState = Object.assign({}, state); newState.shType = action.value return newState; } if (action.type == RESET_LABEL) { //选中的结果重组 const newState = Object.assign({}, state); const tempArr = newState.labelListBig; const tempArrs = newState.labelListSmall; let tmpLis = action.list tmpLis['dateValue'] = getCurrentDate(1) tmpLis['time'] = getCurrentDate(1) if(tmpLis.flg == 1){//大项 tempArr.push(tmpLis) newState.labelListBig = [...tempArr] }else{//小项 tempArrs.push(tmpLis) newState.labelListSmall = [...tempArrs] } return newState; } if (action.type == SEARCH_LIST) { const newState = Object.assign({}, state); newState.list = action.list newState.inspectVal = action.val return newState; } if (action.type == SET_LABEL) { //选中的结果 const newState = Object.assign({}, state); let tempArr = []; if(action.sign == 'common'){ let tmpInspectList = store.getState().homePage.inspectList tempArr = tmpInspectList; }else{ tempArr = newState.list } const tempArrs = newState.labelList; for (let i = 0; i < tempArr.length; i++) { if (i == action.idx) { tempArrs.push(tempArr[i]) newState.labelList = [...tempArrs] } } let tmpArr = newState.getExcelDataList; let tmpArr2 = newState.labelList; newState.pushItems = getPushLists(tmpArr,tmpArr2); newState.inspectStrPlus = getStringPlus(newState.pushItems) return newState; } if (action.type == ADD_LABEL) { //右侧推送的检验检查项,点击开单放到左侧检验检查的位置上 const newState = Object.assign({}, state); const tempArr = newState.labelList; for(let i = 0;i 0){ action.data.lisExcelRes.map((item)=>{ item.lisExcelItem.map((part)=>{ if(part.type == 1){ if(part.max != '' && (part.value-0) > (part.max-0) ) { let rate = (part.value/part.max).toFixed(2); let tmpStr = part.mealName+','+part.itemName+','+part.value+' '+part.unit+'升高'+rate+';' tmpString += tmpStr; }else if(part.min != '' && (part.value-0) < (part.min-0) ){ let rate = (part.value/part.min).toFixed(2); let tmpStr = part.mealName+','+part.itemName+','+part.value+' '+part.unit+'降低'+rate+';' tmpString += tmpStr; }else{ let tmpStr = part.mealName+','+part.itemName+','+part.value+' '+part.unit+'异常;' tmpString += tmpStr; } }else{ let tmpStr = part.mealName+','+part.itemName+','+part.value+' '+part.unit+'正常;' tmpString += tmpStr; } }) }) newState.pushItem = getPushList(tmpArr,tmpArr2); newState.pushItems = getPushLists(tmpArr,tmpArr2); newState.inspectStrPlus = getStringPlus(newState.pushItems) }else{ newState.inspectStrPlus = ''; newState.pushItem = [] } } function getString(lists) { let tmpString = ''; lists.map((item)=>{ if(item.show == true){ item.details.map((part)=>{ if(part.value){ if(typeof(part.value) == "number"){ if(part.maxValue != '' && (part.value-0) > (part.maxValue-0) ) { let rate = (part.value/part.maxValue).toFixed(2); let tmpStr = item.name+','+part.name+','+part.value+' '+part.labelSuffix+'升高'+rate+';' tmpString += tmpStr; }else if(part.minValue != '' && (part.value-0) < (part.minValue-0) ){ let rate = (part.value/part.minValue).toFixed(2); let tmpStr = item.name+','+part.name+','+part.value+' '+part.labelSuffix+'降低'+rate+';' tmpString += tmpStr; }else{ let tmpStr = item.name+','+part.name+','+part.value+' '+part.labelSuffix+';' tmpString += tmpStr; } }else{ tmpString += item.name+','+part.name+','+part.value+' '+part.labelSuffix+';' } } }) } }) return tmpString; } function isNumber(obj) { return typeof obj === 'number' && !isNaN(obj) }