actions.js 1013 Bytes
Newer Older
xuzhenghua committed
1 2 3
import {api, getParam, http} from "@/utils";

export const RECEIVE_COURSES_DETAIL = 'RECEIVE_COURSES_DETAIL'
4 5
export const ADD_COURSES_TO_CART = 'ADD_COURSES_TO_CART';

xuzhenghua committed
6 7 8 9 10
export const receiveCourseDetail = payload => ({
    type: RECEIVE_COURSES_DETAIL,
    payload
})

11 12 13 14 15 16
// 加入购物车
export const addCourseToCart = payload => ({
    type: ADD_COURSES_TO_CART,
    payload
})

xuzhenghua committed
17 18 19 20 21
export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
    dispatch(getCourses({
        courseInfo: getState().detailInfo
    }))
}
22 23
export const getCourses = (id, cb) => dispatch => {
    const courseId = id? id : getParam('id');
FE committed
24 25
    const url = getParam('dist_code')? `${API.home}/m/course/detail/${courseId}/${getParam('dist_code')}` : `${API.home}/m/course/detail/${courseId}`;
    return http.get(url).then((res) => {
xuzhenghua committed
26 27 28
        if (res.data.code === 200) {
            dispatch(receiveCourseDetail({
                ...res.data.data
29 30
            }));
            typeof cb === 'function' && cb();
xuzhenghua committed
31 32 33
        }
    })
}