import * as appService from '../services/editPage'
import * as engineeringPlanEditService from "../services/EM/engineeringPlanEdit"

export default {

  namespace: 'editPage',

  state: {
    autoComData: { Data: [] }, // 自动完成组件的数据
  },

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

  effects: {
    *fetchAutoComData ({ payload, url }, { call, put }) { // 自动完成组件获取数据
      const ret = yield call(appService.fetchAutoComData, { url, payload })
      yield put({ type: 'save', payload: { autoComData: ret } })
    },
    *subAutoComData ({ payload, url, onComplete }, { call, put }) { // 从表自动完成组件获取数据
      const ret = yield call(appService.subAutoComData, { url, payload })
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *getEditPageConfigInfo ({ payload, onComplete }, { call, put }) {
      const ret = yield call(appService.getEditPageConfigInfo, payload)
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *getAutoCompleteData ({ payload, url, isIgnoreTenant = false, onComplete }, { call, put }) { // 从表自动完成组件获取数据
      const ret = yield call(appService.getAutoCompleteData, { url, payload, isIgnoreTenant })
      yield put({ type: 'save', payload: { autoComData: ret } })
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *getUserCustomConfigInfo ({ payload, onComplete }, { call, put }) {
      const ret = yield call(appService.getUserCustomConfigInfo, payload)
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *saveUserCustomConfig ({ payload, onComplete }, { call, put }) {
      const ret = yield call(appService.saveUserCustomConfig, payload)
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
  },

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

}
