123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { message } from 'antd';
- import { queryMerchantRecommend, updateMerchantRecommend } from '../services/merchant';
- import { getLocalUser } from '../utils/helper';
- export default {
- namespace: 'recommend',
- state: {
- item: [],
- loading: false,
- modalShow: false,
- },
- subscriptions: {
- setup({ dispatch, history }) {
- history.listen(({ pathname, state }) => {
- if (pathname === '/frontend') {
- const { merchantId } = getLocalUser();
- dispatch({
- type: 'queryMerchantRecommend',
- payload: { id: merchantId },
- });
- }
- });
- },
- },
- effects: {
- * queryMerchantRecommend({ payload }, { call, put }) {
- yield put({ type: 'changeLoading', payload: { loading: true } });
- const { data, success } = yield call(queryMerchantRecommend, payload);
- if (success) {
- yield put({ type: 'querySuccess', payload: data });
- }
- yield put({ type: 'changeLoading', payload: { loading: false } });
- },
- * updateMerchantRecommend({ payload, callback }, { call, put }) {
- const { data, success } = yield call(updateMerchantRecommend, payload);
- if (success) {
- message.success('修改成功!');
- if (callback) callback();
- }
- },
- },
- reducers: {
- changeLoading(state, action) {
- return { ...state, ...action.payload };
- },
- querySuccess(state, action) {
- return { ...state, item: action.payload };
- },
- showModal(state, action) {
- return { ...state, ...action.payload, modalShow: true };
- },
- hideModal(state, action) {
- return { ...state, ...action.payload, modalShow: false };
- },
- saveSortResult(state, action) {
- return { ...state, item: [...action.payload], modalShow: false };
- },
- },
- };
|