{"size": 2906, "ext": "js", "max_stars_repo_path": "src/routes/trade/bi_type_manage/investors_role_change/models/ApplyForChangeModel.js", "max_stars_repo_name": "tailer-zhang/react-dva", "max_stars_repo_stars_event_min_datetime": "2021-09-18T09:25:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-18T09:25:58.000Z", "max_issues_repo_path": "src/routes/trade/bi_type_manage/investors_role_change/models/ApplyForChangeModel.js", "max_issues_repo_name": "tailer-zhang/react-dva", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/routes/trade/bi_type_manage/investors_role_change/models/ApplyForChangeModel.js", "max_forks_repo_name": "tailer-zhang/react-dva", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.7168141593, "max_line_length": 94, "alphanum_fraction": 0.5151410874}
import { fetchapplyforChangeList, applyForchangeUpload } from '../../../../../services/trade';
import { fetchCustomerList } from '../../../../../services/relativeChanged';
import { parse } from 'qs';

export default {
  namespace: 'ApplyForChangeModel',
  state: {
    status: false,
    applyforChangeList: [],
    pageNumber: 1,
    loadingMore: false,
    reach_bottom: false,
    filterArgs: {},
    keyWord: '',
    custName: '',
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === '/applyforChangeCnt' && location.action === 'PUSH') {
          dispatch({
            type: 'fetchList',
            payload: {
              status: false,
              applyforChangeList: [],
              pageNumber: 1,
              loadingMore: false,
              reach_bottom: false,
              filterArgs: {},
              keyWord: '',
              custName: '',
            },
          })
        }
      });
    },
  },

  effects: {
    *fetchList({ payload }, { call, put, select }) {
      yield put({
        type: 'fetch',
        payload: { ...payload },
      });
      const ApplyForChangeModel = yield select(state => state.ApplyForChangeModel);
      let pageNumber = ApplyForChangeModel.pageNumber;
      if (ApplyForChangeModel.loadingMore === false) {
        pageNumber = 1;
      }
      const custName = ApplyForChangeModel.custName;
      const param = {
        pageNumber,
        pageSize: 10,
        type: '2',
        custName,
      };
      const list = ApplyForChangeModel.applyforChangeList;
      const { data } = yield call(fetchCustomerList, parse(param));
      const result = data

      if (result && result.data !== undefined && result.data.length > 0) {
        yield put({
          type: 'fetch',
          payload: {
            applyforChangeList: list.concat(result.data),
            pageNumber: pageNumber + 1,
            loadingMore: false,
            reach_bottom: result.data.length < 5,
          },
        })
      } else {
        yield put({
          type: 'fetch',
          payload: {
            pageNumber: 1,
            loadingMore: false,
            reach_bottom: true,
          },
        })
      }
    },

    *applyForchangeUpload({ payload }, { call, put, select }) {
      const params = payload.params
      const backMethod = payload.backMethod;
      const { data } = yield call(applyForchangeUpload, parse(params))
      backMethod(data)
    },

    *clear({ payload }, { call, put, select }) {
      yield put({
        type: 'fetch',
        payload,
      });
    },

    * fetchDetail({ payload }, { call, put, select }) {
      yield put({ type: 'showLoading' });
      yield put({
        type: 'fetch',
        payload,
      });
    },

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