import { create, update, remove, bundleTags } from '../services/goods'; import { message } from 'antd'; import { Codes } from '../utils/config'; export default { namespace: 'goodsModel', state: { goodsItem: {}, modalShow: false, tagModalShow: false, operation: 'create', }, effects: { * createItem({ payload, callback }, { call, put }) { const { data, success } = yield call(create, { ...payload, status: Codes.CODE_NORMAL }); if (success) { message.success('创建成功!'); yield put({ type: 'hideModal' }); if (callback) callback(); } }, * updateItem({ payload, callback }, { call, put }) { const { data, success } = yield call(update, { ...payload }); if (success) { message.success('修改成功!'); yield put({ type: 'hideModal' }); if (callback) callback(); } }, * removeItem({ payload, callback }, { call, put }) { const { data, success } = yield call(remove, { ...payload }); if (success) { message.success('删除成功!'); if (callback) callback(); } }, * bundleTags({ payload, callback }, { call, put }) { const { data, success } = yield call(bundleTags, { ...payload }); if (success) { message.success('操作成功!'); yield put({ type: 'hideTagModal' }); if (callback) callback(); } }, }, reducers: { showModal(state, action) { return { ...state, ...action.payload, modalShow: true }; }, showTagModal(state, action) { return { ...state, ...action.payload, tagModalShow: true }; }, hideModal(state, action) { return { ...state, ...action.payload, modalShow: false }; }, hideTagModal(state, action) { return { ...state, ...action.payload, tagModalShow: false }; }, }, };