import { createAction, NavigationActions } from '../../utils' import * as authService from '../../services/auth' export default { namespace: 'optional', state: { optDataByGoodId: [], optDataByIds: [], optionalReturn: [], goodsBoom: [], // isRefreshing: false, // totalPages: 2, // // 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中 // showFoot: 0 colorGroups: [], colorData: [], goodsPriceByColor: [], goodsOpt: [], }, reducers: { optionalByGoodIdReducer(state, { payload }) { return { ...state, ...payload } }, optionalByIdsReducer(state, { payload }) { return { ...state, ...payload } }, saveOptionalReducer(state, { payload }) { return { ...state, ...payload } }, getBoomReducer(state, { payload }) { return { ...state, ...payload } }, getColorGroupsReducer(state, {payload}) { return {...state, ...payload} }, getColorByGroupsReducer(state, {payload}) { return {...state, ...payload} }, getPriceByColorIdReducer(state, {payload}) { return {...state, ...payload} }, saveGoodsOptReducer(state, {payload}) { return {...state, ...payload} } }, effects: { // 获取选配信息 ByGoodId *optionalByGoodIdSaga(action, { call, put }) { let returnData = [] try { const hotdata = yield call(() => authService.getOptionalByGoodId(action.payload) ) if (hotdata && hotdata.data) { returnData = hotdata.data } yield put( createAction('optionalByGoodIdReducer')({ optDataByGoodId: returnData, }) ) } catch (error) { yield put( createAction('optionalByGoodIdReducer')({ optDataByGoodId: returnData, }) ) console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 获取选配信息 ByIds *optionalByIds(action, { call, put }) { try { const hotdata = yield call(() => authService.getOptionalByIds({ ids: action.payload }) ) if (hotdata && hotdata.data) { yield put( createAction('optionalByIdsReducer')({ optDataByIds: hotdata.data, }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 保存选配 *saveOptionalSaga(action, { call, put }) { try { const hotdata = yield call(() => authService.saveOptional(action.payload) ) if (hotdata && hotdata.data) { yield put( createAction('saveOptionalReducer')({ optionalReturn: hotdata.data, }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 获取Boom信息 *getBoomInfo(action, { call, put }) { try { const hotdata = yield call(() => authService.getBoomInfo({ parentGoodId: action.payload }) ) if (hotdata && hotdata.data) { yield put( createAction('getBoomReducer')({ goodsBoom: hotdata.data, }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, //获取颜色选配分组 *getColorGroups(action, { call, put}) { try { const hotdata = yield call(() => authService.getColorGroups({}) ) if(hotdata && hotdata.data) { yield put( createAction('getColorGroupsReducer')({ colorGroups : hotdata.data }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, //根据颜色分组查询颜色 *getColorByGroups(action, { call, put}) { try { const hotdata = yield call(() => authService.getColorByGroups(action.payload) ) console.log(hotdata); if(hotdata && hotdata.data) { yield put( createAction('getColorByGroupsReducer')({ colorData : hotdata.data }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, //根据色卡号查询商品调色价格 *getPriceByColorId(action, { call, put}) { try { const hotdata = yield call(() => authService.getPriceByColorId(action.payload) ) if(hotdata && hotdata.data) { yield put( createAction('getPriceByColorIdReducer')({ goodsPriceByColor : hotdata.data }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, //保存调色商品配置 *saveGoodsOpt(action, { call, put}) { try { const hotdata = yield call(() => authService.saveGoodsOpt(action.payload) ) if(hotdata && hotdata.data) { yield put( createAction('saveGoodsOptReducer')({ goodsOpt : hotdata.data }) ) } } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } } }, }