import * as actionTypes from '../actiontype/ScanBarCode';
let currentProductInfo = {};
function initSuccess(state,data) {
    currentProductInfo.inventoryLossId = data.inventorylossId;
    currentProductInfo.packingStatusImageIds = [];
    currentProductInfo.lossPostion = undefined;
    currentProductInfo.packingStatus = undefined;
    data.data_currentProblemObj = Object.assign({},currentProductInfo);
    let newInfo = Object.assign({},state,data);
    return newInfo;
}
function submitSuccess(state,data) {
    let newInfo = Object.assign({},state,data);
    return newInfo;

}
function clearSuccess(state,data) {
    let newInfo = Object.assign({},state);
    newInfo = data;
    return newInfo;
}
function saveInfoSuccess(state,data) {
    if(data.type == "productPosition"){
        currentProductInfo.lossPostion = data.data;
    }
    if(data.type == "productPakingStatus"){
        currentProductInfo.packingStatus = data.data;
    }
    if(data.type == "imgList"){
        currentProductInfo.packingStatusImageIds = data.data;
    }
    let data_currentProblemObj = Object.assign({},currentProductInfo);

    let newInfo = Object.assign({},state,{data_currentProblemObj:data_currentProblemObj});
    return newInfo;
}
export default function(state={}, action) {
    switch (action.type) {
        case actionTypes.INIT_SCANBARCODEGETPRODUCTINFO_SUCCESS:
            return initSuccess(state,action.data)
        case actionTypes.SUBMIT_PRODUCT_SUCCESS:
            return submitSuccess(state,action.data)
        case actionTypes.SAVE_PRODUCTEDITINFO_SUCCESS:
            return saveInfoSuccess(state,action.data)
        case actionTypes.ClEAR_PRODUCT_SUCCESS:
            return clearSuccess(state,action.data)
        default:
            return state;
    }
}