
/**
 * Created by zhouhuan on 2017/11/13.
 */
import { getData, getMeta } from '../../utils/DataTemplate';

export default {
  namespace: 'QSInfoDetail',
  state: {
    singularData: {},
    metas: [],
    enableEdit: false,
    QSID: '',
  },
  reducers: {
    setList(state, { payload }) {
      return { ...state, singularData: payload.singularData };
    },
    setSingularData(state, { payload }) {
      return { ...state, singularData: payload };
    },
    setEnable(state, { payload: enableEdit }) {
      return { ...state, enableEdit };
    },
    setMetas(state, { payload }) {
      return { ...state, metas: payload };
    },
    setQSID(state, { payload }) {
      return {
        ...state,
        QSID: payload,
      };
    },
  },
  effects: {
    *getDSRInfoDetail({ payload }, { call, put }) {
      const coordinate = {
        containerType: 'module',
        containerName: 'query-DSRFWQuanShu',
        datasourceName: 'QueryfwqsDetails',
      };
      const result = yield call(getData, coordinate, { pst: 0, psz: 10, params: { pID: payload } });
      const singularData = result[0];
      yield put({ type: 'setQSID', payload });
      yield put({ type: 'setList', payload: { singularData: { ...singularData } } });
      const metas = yield call(getMeta, coordinate);
      yield put({ type: 'setMetas', payload: metas });
    },
  },
};

