import actionTypes from '../actiontype/common';


const saveCommonInfo = (state,data)=>{
    let keys = Object.keys(data);
    keys.forEach(k=>
    {
        if(state[k]){
            if(typeof data[k] === 'string'){
                state[k] = data[k]
            }else{
                state[k] = Object.assign({},state[k],data[k]);
            }

        }else{
            state[k] = data[k]
        }
    });
    return Object.assign({},state);
};

const emptyCommInfo = (state,data)=>{
    return Object.assign({},state,data)
}
const startalljob= (state,data)=>{
    return Object.assign({},state,data)
}
export default function(state={}, action) {
    switch (action.type) {
        case actionTypes.SAVECOMMONINFO:
            return saveCommonInfo(state,action.data);
        case actionTypes.EMPTYCOMMONINFO:
            return emptyCommInfo(state);
        case actionTypes.STARTALLJOB   :
            return startalljob(state);
        default:
            return state;
    }
}