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 }; }, }, };