import { routerRedux } from 'dva/router';
import * as processService from '../../services/FM/process';

export default {

  namespace: 'FMProcess',
  state: {
  },

  subscriptions: {
    setup({ dispatch, history }) {  // eslint-disable-line

    },
  },

  effects: {
    *getMaxNum({ payload, onComplete }, { call, put }) {
      const ret = yield call(processService.getProcessDetailList, payload);
      if (typeof onComplete === 'function') {
        let num = 0;
        if (ret && ret.length) {
          ret.forEach((n, i) => {
            if (num == 0) {
              num = n.NUM;
            }
          });
        }
        onComplete(num + 1)
      }
    },
    *getProcessDetailList({ payload, onComplete }, { call, put }) {
      const ret = yield call(processService.getProcessDetailList, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *getBaseConfig({ payload, onComplete }, { call, put }) {
      const ret = yield call(processService.getBaseConfig, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *getFullGet({ payload, onComplete }, { call, put }) {
      const ret = yield call(processService.getFullGet, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
  },

  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
  },

};
