import * as service from '../../services/tos';
import { message } from 'antd';
import { Link, useIntl, connect, Dispatch, history } from 'umi';

import { routerRedux } from 'dva/router'

import { printf } from '@/utils/log';
import { getObjectInfo } from '@/utils/method';

export default {
  namespace: 'CellList',
  state: {
    Data: null,
    curString:{},
    Result: null,
    DataSave: null,
    DataSaveDetail:null,
  },

  reducers: {
    returnPage(state, { Data}) {
      return { ...state, Data };
    },
    returnResult(state, { Result}) {
      return { ...state, Result};
    },
    returnDataSave(state, { DataSave }) {
      return {...state,DataSave}
    },
    returnDataSaveDetail(state, { DataSaveDetail }) {
      return {...state,DataSaveDetail}
    },
  },

  effects: {
    
    //标准请求
    *RA({ playload }, { call, put }) {
      
      const resp = yield call(service.RA, playload);
      console.log(resp)
      // if (resp.code == 500||resp.error_code!="0000") {     
      // }
      if (resp.code == 500 && resp.error_code != "0000") {
        getObjectInfo(playload.body)
        printf(playload, resp)
        message.error(`${resp.code}:${resp.msg}`)
      } else { 
        switch (playload.index) {
          case 24: {            
            let Data = resp.data;          
            yield put({ type: 'returnPage', Data });            
            } break;
          case 29: {
            let Result = resp;          
            yield put({ type: 'returnResult', Result }); 
            message.success(`新增成功！`)
          } break;
        }
        history.push('/CommunityManagement/CellList');
      }
      
      
    },

    *ResultClear({ }, { put }) {
      var tmp=null
      yield put({type: 'returnResult', tmp} )
    },

    *SA({ playload }, { call, put }) {
      var DataSave = playload
      yield put({type: 'returnDataSave', DataSave} )
    },

  },

};
