notification.js 1.7 KB
import * as types from '../constants/ActionTypes';
import {getNotificationList,finish_Notification,getUnreadMessage,readAllMessages} from '../../utils/notificationUtil';
import { message } from 'antd';
import moment from 'moment';
import {SubmissionError,change} from 'redux-form';


//获取提醒列表
export function   loadNotificationList(offset,limit){
    return dispatch => {
        return getNotificationList(offset,limit).then(data => {
            const {items,total_count} = data
            dispatch({
                type        : types.GET_NOTIFICATION_LIST,
                notificationList: items,
                notificationListCount:total_count
            });
        }).catch(err => {throw err});
    }
}


//点击读取提醒
export function   finishNotification(id,page=1){
    return dispatch => {
        return finish_Notification(id).then(data => {
          let offset = (page-1)*30;
          dispatch(loadNotificationList(offset,30));
          dispatch(loadUnreadMessage());
        }).catch(err => {throw err});
    }
}

//获取首页五条未读消息列表
export function loadUnreadMessage(offset,limit){
    return dispatch => {
        return getUnreadMessage(offset,limit).then(data => {
            const {items,total_count} = data
            dispatch({
                type        : types.GET_UNREAD_LIST,
                unreadList: items,
                unreadListCount:total_count
            });
        }).catch(err => {throw err});
    }
}


export function finishAllMessages(values){
    return dispatch => {
        return readAllMessages(values).then(data => {
          dispatch(loadUnreadMessage());
        }).catch(err => {throw err});
    }
}