import { queryOne, createMerchantProduct } from '../../services/mproduct'; import pathToRegexp from 'path-to-regexp'; import queryString from 'query-string'; import { Codes } from '../../utils/config'; export default { namespace: 'mproductDetail', state: { filters: {}, currentItem: {}, itemLoading: false, }, subscriptions: { setup({ dispatch, history }) { history.listen(({ pathname, state, search, ...rest }) => { const match = pathToRegexp('/goods/edit').exec(pathname); if (match) { const params = queryString.parse(search); dispatch({ type: 'queryOne', payload: { ...params } }); dispatch({ type: 'saveFilters', payload: state }); } if (pathname === '/goods/add') { dispatch({ type: 'saveFilters', payload: state }); } }); }, }, effects: { // 查询一条渠道方产品详情 /merchant/product/detail?pid=xxx&merchantId=xxx * queryOne({ payload }, { call, put }) { yield put({ type: 'changeLoading', payload: { itemLoading: true } }); const { data, success } = yield call(queryOne, payload); if (success) { yield put({ type: 'querySuccess', payload: { ...data } }); } yield put({ type: 'changeLoading', payload: { itemLoading: false } }); }, // 创建渠道方产品 {pid:'xxx', merchantId:'xxx', status:'NORMAL'} * createMerchantProduct({ payload, callback }, { call, put }) { const { data, success } = yield call(createMerchantProduct, payload); if (success) { yield put({ type: 'clearPage' }); if (callback) callback(); } }, }, reducers: { changeLoading(state, { payload }) { return { ...state, ...payload }; }, querySuccess(state, { payload }) { return { ...state, currentItem: payload }; }, saveFilters(state, { payload: filters }) { return { ...state, filters }; }, showSupportModal(state, { payload }) { return { ...state, ...payload, supportModalVisible: true }; }, hideSupportModal(state) { return { ...state, supportModalVisible: false }; }, showResourceModal(state, { payload }) { return { ...state, ...payload, resourceModalVisible: true }; }, hideResourceModal(state) { return { ...state, resourceModalVisible: false }; }, saveSupportList(state, { payload: { supportList } }) { const currentItem = { ...state.currentItem, supportList }; return { ...state, supportModalVisible: false, currentItem }; }, saveImgList(state, { payload: { imgList } }) { const currentItem = { ...state.currentItem, imgList }; return { ...state, resourceModalVisible: false, currentItem }; }, clearPage(state) { return { ...state, currentItem: {}, itemLoading: false }; }, }, };