import { createAction, NavigationActions } from '../../utils' import * as authService from '../../services/auth' export default { namespace: 'attention', state: { attentData: [], isRefreshing: false, }, reducers: { attentionListReducer(state, { payload }) { return { ...state, ...payload } }, updateReducer(state, { payload }) { return { ...state, ...payload } }, // shopIdsReducer(state, { payload }) { // return { ...state, ...payload }; // } }, effects: { // 查看关注列表 *getAttentionList(action, { call, put }) { try { let attentData = [] yield put( createAction('attentionListReducer')({ isRefreshing: true, }) ) const attention = yield call(() => authService.checkAttention({ customer: CUSTOMERINFO.id }) ) if (attention && attention.data) { attention.data.map(item => { if (item.storelist) { attentData = attentData.concat(item.storelist) } }) yield put( createAction('attentionListReducer')({ attentData: attentData }) ) } } catch (error) { yield put( createAction('attentionListReducer')({ isRefreshing: false, }) ) console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 添加关注 *addAttention(action, { call, put }) { try { const attentionAdd = yield call(() => authService.addAttention(action.payload) ) yield put(createAction('getAttentionList')()) } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 删除关注商品行 *delAttention(action, { call, put }) { try { const delAttent = yield call(() => authService.delAttention({ customer: CUSTOMERINFO.id, id: action.payload, }) ) yield put(createAction('getAttentionList')()) } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 删除关注商品行 *delAttentionByGoodsId(action, { call, put }) { try { const delAttent = yield call(() => authService.delAttentionByGood({ customer: CUSTOMERINFO.id, goodsId: action.payload.goodsId, saleOrg: action.payload.saleOrg, }) ) yield put(createAction('getAttentionList')()) } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, // 删除关注商品行 *updateAttention(action, { call, put }) { try { yield put( createAction('updateReducer')({ attentData: action.payload.attentData, }) ) } catch (error) { console.log( error, '-----error的完整信息' + '\n' + error.response.data.message, '-----相关错误信息' ) } }, }, }