recommend.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { message } from 'antd';
  2. import { queryMerchantRecommend, updateMerchantRecommend } from '../services/merchant';
  3. import { getLocalUser } from '../utils/helper';
  4. export default {
  5. namespace: 'recommend',
  6. state: {
  7. item: [],
  8. loading: false,
  9. modalShow: false,
  10. },
  11. subscriptions: {
  12. setup({ dispatch, history }) {
  13. history.listen(({ pathname, state }) => {
  14. if (pathname === '/frontend') {
  15. const { merchantId } = getLocalUser();
  16. dispatch({
  17. type: 'queryMerchantRecommend',
  18. payload: { id: merchantId },
  19. });
  20. }
  21. });
  22. },
  23. },
  24. effects: {
  25. * queryMerchantRecommend({ payload }, { call, put }) {
  26. yield put({ type: 'changeLoading', payload: { loading: true } });
  27. const { data, success } = yield call(queryMerchantRecommend, payload);
  28. if (success) {
  29. yield put({ type: 'querySuccess', payload: data });
  30. }
  31. yield put({ type: 'changeLoading', payload: { loading: false } });
  32. },
  33. * updateMerchantRecommend({ payload, callback }, { call, put }) {
  34. const { data, success } = yield call(updateMerchantRecommend, payload);
  35. if (success) {
  36. message.success('修改成功!');
  37. if (callback) callback();
  38. }
  39. },
  40. },
  41. reducers: {
  42. changeLoading(state, action) {
  43. return { ...state, ...action.payload };
  44. },
  45. querySuccess(state, action) {
  46. return { ...state, item: action.payload };
  47. },
  48. showModal(state, action) {
  49. return { ...state, ...action.payload, modalShow: true };
  50. },
  51. hideModal(state, action) {
  52. return { ...state, ...action.payload, modalShow: false };
  53. },
  54. saveSortResult(state, action) {
  55. return { ...state, item: [...action.payload], modalShow: false };
  56. },
  57. },
  58. };