import { Toast } from 'antd-mobile'; import { getFciSectionByGroupId, getFciDogBySectionId } from '../services/index'; const COMMON_STATE = { index: null, item: {}, list: [], listI: null, }; export default { state: COMMON_STATE, reducers: { clearState(state, { payload }) { return { ...COMMON_STATE }; }, updateState(state, { payload }) { return { ...state, ...payload }; }, }, effects: { *getFciSectionByGroupId({ payload }, { call, put }) { const data = yield call(getFciSectionByGroupId, { ...payload }); if (data.rc === 0) { let list = []; data['0'].forEach((item, i) => { list.push({ ...item, children: [], }); }); yield put({ type: 'updateState', payload: { list, }, }); } else { Toast.fail(data.msg, 2); } }, *getFciDogBySectionId({ payload }, { call, put, select }) { const { list, listI } = yield select(state => { return state.fciSection; }); const data = yield call(getFciDogBySectionId, { ...payload }); if (data.rc === 0) { list[listI].children = data['0']; yield put({ type: 'updateState', payload: { list, }, }); } else { Toast.fail(data.msg, 2); } }, }, subscriptions: { // setupHistory({ dispatch, history }) { // history.listen(location => {}); // }, }, };