import { createAction, NavigationActions } from '../../utils' import * as authService from '../../services/auth' export default { namespace: 'detail', state: { detailDatas: [], detailPicts: [], detailSpec: {}, questSuccess: false, }, reducers: { pictureReducer(state, { payload }) { return { ...state, ...payload } }, specReducer(state, { payload }) { return { ...state, ...payload } }, }, effects: { // 进入详情 *gotoDetail(action, { call, put }) { try { const hotdata = yield call(() => authService.getPicture({ id: action.payload.item.id }) ) const hotdetaildata = yield call(() => authService.getDetailAuth({ id: action.payload.item.id, customer: CUSTOMERINFO.id, supplier: action.payload.item.saleOrgId, }) ) if (hotdata && hotdata.data) { let pictures = [] hotdata.data.map(items => pictures.push(items.fileUrl)) yield put( createAction('pictureReducer')({ detailPicts: pictures, detailDatas: hotdetaildata.data, }) ) yield put( NavigationActions.navigate({ routeName: 'CommodityTab', params: action.payload.userFor, }) ) } } catch (error) { console.log( error, '-----获取商品列表及图片并进入详情的完整信息' + '\n' + '相关错误信息---->:' + error.response.data.message ) } }, //获取商品详情 *getDetail(action, { call, put }) { try { let pictures = [], questSuccess = false const hotdata = yield call(() => authService.getDetailAuth(action.payload.inFo) ) if (action.payload.useFor == 'specification') { const pictureData = yield call(() => authService.getPicture({ id: action.payload.inFo.id }) ) pictureData.data.map(item => pictures.push(item.fileUrl)) } if (hotdata && hotdata.data && Object.keys(hotdata.data).length > 0) { if (action.payload.useFor == 'specification') { questSuccess = true yield put( createAction('pictureReducer')({ detailDatas: hotdata.data, detailPicts: pictures, questSuccess: questSuccess, }) ) } else { yield put( createAction('pictureReducer')({ detailDatas: hotdata.data, }) ) } if (action.payload.useFor == 'specification') { action.payload.refresh._refreshdata( hotdata.data.salePrice || hotdata.data.basePrice, pictures[0] ) } } } catch (error) { console.log( error, '-----获取商品详情的完整信息' + '\n' + '相关错误信息---->:' + error.response.data.message ) } }, //商品规格 *getSpec(action, { call, put }) { try { const hotdata = yield call(() => authService.getSpecification(action.payload) ) if (hotdata && Object.keys(hotdata).length > 0) { yield put( createAction('specReducer')({ detailSpec: hotdata.data, }) ) } } catch (error) { yield put( createAction('specReducer')({ detailSpec: {}, }) ) console.log( error, '-----商品规格的完整信息' + '\n' + '相关错误信息---->:' + error.response.data.message ) } }, }, }