/*
 * @Author: your name
 * @Date: 2020-11-19 16:54:53
 * @LastEditTime: 2020-12-04 17:24:27
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tostumi\src\models\CommunityManagement\VisitorRecord.ts
 */
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';

export default {
  namespace: 'VisitorRecord',
  state: {
    Data: null,
    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);
      if (resp.code == 500 || resp.error_code != '0000') {
        message.error(`${resp.error_code}:${resp.error_msg}`);
      }
      if (resp.error_code != '0000') {
        printf(playload, resp);
        message.error(`${resp.error_code}:${resp.error_msg}`);
      } else {
        switch (playload.index) {
          case 26:
            {
              // 总数据
              let Data = resp.data.rows;
              let DataSave = resp.data.rows;
              yield put({ type: 'returnPage', Data });
              yield put({ type: 'returnDataSave', DataSave });
            }
            break;
        }
      }
    },

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

    *SA({ playload }, { call, put }) {
      var Data = playload;
      yield put({ type: 'returnPage', Data });
    },
  },
};
