import Config from '../../../../utils/config';
import { certificateInfo, geneReport } from '../services/ckuService';
import { Toast } from 'antd-mobile';

export default {
  state: {
    dog1: {},
    dog2: {},
    dog3: {},
    dog4: {},
    dog5: {},
    dog6: {},
    dog7: {},
    dog8: {},
    dog9: {},
    dog10: {},
    dog11: {},
    dog12: {},
    dog13: {},
    dog14: {},
    id: ''
  },
  reducers: {
    updateState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clean(state, { payload }) {
      return {
        dog1: {},
        dog2: {},
        dog3: {},
        dog4: {},
        dog5: {},
        dog6: {},
        dog7: {},
        dog8: {},
        dog9: {},
        dog10: {},
        dog11: {},
        dog12: {},
        dog13: {},
        dog14: {},
      };
    },
  },
  effects: {
    *certificateInfo({ payload }, { call, put }) {
      Toast.loading('查询中', 0);
      const { rc, msg, data } = yield call(certificateInfo, { ...payload });
      Toast.hide();
      if (rc === Config.constant.codeSuccess) {
        yield put({
          type: 'updateState',
          payload: {
            ...data,
          },
        });
      } else {
        Toast.fail(msg);
      }
    },
    *geneReport({ payload }, { call, put }) {
      Toast.loading('查询中', 0);
      const { rc, msg, data } = yield call(geneReport, { ...payload });
      Toast.hide();
      if (rc === Config.constant.codeSuccess) {
        yield put({
          type: 'updateState',
          payload: {
            ...data,
          },
        });
      } else {
        Toast.fail(msg);
      }
    },
  },
  subscriptions: {
    // setupHistory({ dispatch, history }) {
    //   history.listen(location => {});
    // },
  },
};
