// import { formUtils } from '@utils';
// import { routerRedux } from 'dva/router';

export default {
  namespace: 'dev_components',

  state: {
    modalVisible: false,
    modalLoading: false,
    formData: {
      itemClass: [],
      itemClassC: ['1', '102', '10202'], zljy: ['01', '02'],
    },
    formData2: {
      itemClass: {
        id: null,
        text: null,
        name: null,
      }, itemClassC: {
        id: 111,
        value: '100081',
        name: '深圳市贯垄农产品有限公司',
      }, itemClassCC: {
        id: 111,
        value: '100081',
        name: '深圳市贯垄农产品有限公司',
      },
      item: {
        id: null,
        value: null,
        name: null,
      },
      ou: {
        id: null,
        value: null,
        name: null,
      },
    },
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === '/cooperate/order/pyo') {
          // dispatch({ type: 'clean' });
          // dispatch({ type: 'query' });
        }
      });
    },
  },

  effects: {
    * query({ payload }, { call, select, put }) {

    },

    * querySingle({ payload }, { call, put }) {

    },

    * getSingle({ payload }, { put }) {

    },
  },

  reducers: {
    updateForm(state, { payload }) {
      const { key, value } = payload;
      const formData = state.formData;
      const newFormData = Object.assign({}, formData);
      newFormData[key] = value;
      return {
        ...state,
        formData: newFormData,
      };
    },

    updateForm2(state, { payload }) {
      const { key, value } = payload;
      const formData2 = state.formData2;
      const newFormData = Object.assign({}, formData2);
      newFormData[key] = value;
      return {
        ...state,
        formData2: newFormData,
      };
    },

    updateState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },

  },

};
