|
@@ -0,0 +1,119 @@
|
|
|
+import { queryOne, create, update } from '../../services/combo';
|
|
|
+import { message } from 'antd';
|
|
|
+import pathToRegexp from 'path-to-regexp';
|
|
|
+import { Codes } from '../../utils/config';
|
|
|
+
|
|
|
+export default {
|
|
|
+ namespace: 'comboDetail',
|
|
|
+
|
|
|
+ state: {
|
|
|
+ filters: {},
|
|
|
+ operType: 'create',
|
|
|
+ currentItem: {},
|
|
|
+ courseModalVisible: false,
|
|
|
+ supportModalVisible: false,
|
|
|
+ itemLoading: false,
|
|
|
+ },
|
|
|
+
|
|
|
+ subscriptions: {
|
|
|
+ setup({ dispatch, history }) {
|
|
|
+ history.listen(({ pathname, state, ...rest }) => {
|
|
|
+ const match = pathToRegexp('/product/package/edit/:id').exec(pathname);
|
|
|
+ if (match) {
|
|
|
+ dispatch({ type: 'query', payload: { id: match[1] } });
|
|
|
+ dispatch({ type: 'saveFilters', payload: state });
|
|
|
+ dispatch({ type: 'saveOperType', payload: { operType: 'update' } });
|
|
|
+ }
|
|
|
+ if (pathname === '/product/package/add') {
|
|
|
+ dispatch({ type: 'saveFilters', payload: state });
|
|
|
+ dispatch({ type: 'saveFilters', payload: state });
|
|
|
+ dispatch({ type: 'saveOperType', payload: { operType: 'create' } });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ effects: {
|
|
|
+ * query ({ payload }, { call, put }) {
|
|
|
+ yield put({ type: 'changeLoading', payload: { itemLoading: true } });
|
|
|
+ const { data, success } = yield call(queryOne, payload);
|
|
|
+ if (success) {
|
|
|
+ yield put({ type: 'querySuccess', payload: { ...data } });
|
|
|
+ }
|
|
|
+ yield put({ type: 'changeLoading', payload: { itemLoading: false } });
|
|
|
+ },
|
|
|
+ * create ({ payload, callback }, { call, put }) {
|
|
|
+ // 创建课程包,默认状态为NORMAL
|
|
|
+ const { data, success } = yield call(create, { ...payload, status: Codes.CODE_NORMAL });
|
|
|
+ if (success) {
|
|
|
+ message.success('创建成功!');
|
|
|
+ yield put({ type: 'clearPage' });
|
|
|
+ if (callback) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message.error('创建失败!');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ * update ({ payload, callback }, { call, put }) {
|
|
|
+ const { data, success } = yield call(update, payload);
|
|
|
+ if (success) {
|
|
|
+ message.success('更新成功!');
|
|
|
+ yield put({ type: 'clearPage' });
|
|
|
+ if (callback) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message.error('更新失败!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ reducers: {
|
|
|
+ changeLoading(state, { payload }) {
|
|
|
+ return { ...state, ...payload };
|
|
|
+ },
|
|
|
+
|
|
|
+ querySuccess(state, { payload }) {
|
|
|
+ return { ...state, currentItem: payload };
|
|
|
+ },
|
|
|
+
|
|
|
+ saveFilters(state, { payload: filters }) {
|
|
|
+ return { ...state, filters };
|
|
|
+ },
|
|
|
+
|
|
|
+ showCourseModal(state, { payload }) {
|
|
|
+ return { ...state, ...payload, courseModalVisible: true };
|
|
|
+ },
|
|
|
+
|
|
|
+ hideCourseModal(state) {
|
|
|
+ return { ...state, courseModalVisible: false };
|
|
|
+ },
|
|
|
+
|
|
|
+ showSupportModal(state, { payload }) {
|
|
|
+ return { ...state, ...payload, supportModalVisible: true };
|
|
|
+ },
|
|
|
+
|
|
|
+ hideSupportModal(state) {
|
|
|
+ return { ...state, supportModalVisible: false };
|
|
|
+ },
|
|
|
+
|
|
|
+ saveOperType(state, { payload }) {
|
|
|
+ return { ...state, ...payload };
|
|
|
+ },
|
|
|
+
|
|
|
+ saveCourseList(state, { payload: { courseList } }) {
|
|
|
+ const currentItem = { ...state.currentItem, courseList };
|
|
|
+ return { ...state, courseModalVisible: false, currentItem };
|
|
|
+ },
|
|
|
+
|
|
|
+ saveSupportList(state, { payload: { supportList } }) {
|
|
|
+ const currentItem = { ...state.currentItem, supportList };
|
|
|
+ return { ...state, supportModalVisible: false, currentItem };
|
|
|
+ },
|
|
|
+
|
|
|
+ clearPage(state) {
|
|
|
+ return { ...state, currentItem: {}, itemLoading: false };
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|