/**
 * Created by zhouhuan on 2017/10/30.
 */
import { getData } from '../../utils/DataTemplate';

export default {
  namespace: 'obligeeInfo',
  state: {
    sourceData: [],
  },
  effects: {
    *getObligeeInfo({ payload }, { take, put, call, select }) {
      console.log('come on ~~');
      if (payload === 'clear') {
        yield put({ type: 'clearList', payload: {} });
      }
      const { sourceData } = yield select(state => state.obligeeInfo);
      console.log(sourceData);
      const size = sourceData.length;
      const coordinate = {
        containerType: 'module',
        containerName: 'query-DSRInfo',
        datasourceName: 'QueryDSRInfoTable',
      };
      const result = yield call(getData, coordinate, { pst: size, psz: 10 });
      console.log(result);
      for (const row of result) {
        yield put({ type: 'addDSR', payload: row });
        yield take('addDSR/@@end');
      }
    },
    *addDSR({ payload }, { put }) {
      yield put({ type: 'setDSRList', payload: { arrayData: [payload] } });
    },
  },
  reducers: {
    setDSRList(state, { payload: { arrayData } }) {
      return { ...state, sourceData: [...state.sourceData, ...arrayData] };
    },
  },
};

