repayDetailReducer.js 1.37 KB
'use strict';

import InitialState from './repayDetailInitialState';
import Immutable, {Map} from 'immutable';

const {
    SET_REPAY_ORDER_NO,
    SET_TIP_MESSAGE,
    SET_ERROR,
    
    QUERY_REPAY_RECORD_LIST_REQUEST,
    QUERY_REPAY_RECORD_LIST_FAILURE,
    QUERY_REPAY_RECORD_LIST_SUCCESS,
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function appReducer(state = initialState, action) {
    if (!(state instanceof InitialState)) return initialState.merge(state);

    switch (action.type) {
        case SET_REPAY_ORDER_NO:
            return state.set('repayOrderNo', action.payload);
        case SET_TIP_MESSAGE:
            return state.set('tipMessage', action.payload);
        case QUERY_REPAY_RECORD_LIST_REQUEST:
            return state.set('isFetching', true);
        case QUERY_REPAY_RECORD_LIST_SUCCESS:
            return state.set('repayList', Immutable.fromJS(action.payload.detailInfoList))
            .set('currentPage', action.payload.currentPage)
            .set('pageTotal', action.payload.pageTotal)
            .set('isFetching', false);
        case QUERY_REPAY_RECORD_LIST_FAILURE:
            return state.set('isFetching', false)
            .set('tipMessage', error.message||'暂未获取到数据');
        case SET_ERROR:
            return state.set('error', action.payload);
    }

    return state;
}