goods.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { create, update, remove, bundleTags } from '../services/goods';
  2. import { message } from 'antd';
  3. import { Codes } from '../utils/config';
  4. export default {
  5. namespace: 'goodsModel',
  6. state: {
  7. goodsItem: {},
  8. modalShow: false,
  9. tagModalShow: false,
  10. operation: 'create',
  11. },
  12. effects: {
  13. * createItem({ payload, callback }, { call, put }) {
  14. const { data, success } = yield call(create, { ...payload, status: Codes.CODE_NORMAL });
  15. if (success) {
  16. message.success('创建成功!');
  17. yield put({ type: 'hideModal' });
  18. if (callback) callback();
  19. }
  20. },
  21. * updateItem({ payload, callback }, { call, put }) {
  22. const { data, success } = yield call(update, { ...payload });
  23. if (success) {
  24. message.success('修改成功!');
  25. yield put({ type: 'hideModal' });
  26. if (callback) callback();
  27. }
  28. },
  29. * removeItem({ payload, callback }, { call, put }) {
  30. const { data, success } = yield call(remove, { ...payload });
  31. if (success) {
  32. message.success('删除成功!');
  33. if (callback) callback();
  34. }
  35. },
  36. * bundleTags({ payload, callback }, { call, put }) {
  37. const { data, success } = yield call(bundleTags, { ...payload });
  38. if (success) {
  39. message.success('操作成功!');
  40. yield put({ type: 'hideTagModal' });
  41. if (callback) callback();
  42. }
  43. },
  44. },
  45. reducers: {
  46. showModal(state, action) {
  47. return { ...state, ...action.payload, modalShow: true };
  48. },
  49. showTagModal(state, action) {
  50. return { ...state, ...action.payload, tagModalShow: true };
  51. },
  52. hideModal(state, action) {
  53. return { ...state, ...action.payload, modalShow: false };
  54. },
  55. hideTagModal(state, action) {
  56. return { ...state, ...action.payload, tagModalShow: false };
  57. },
  58. },
  59. };