/*
 * @Author: your name
 * @Date: 2020-11-19 16:54:53
 * @LastEditTime: 2020-11-26 16:33:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tostumi\src\models\CommunityManagement\CommunityAnnouncement.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: 'CommunityAnnouncement',
  state: {
    Data: null, //公告列表
    Result: null, //新增、编辑保存成功信息
    DataSave: null, // 列表内容
    DataSaveDetail: { pageNum: 1 }, // 页码
    ImgSrc: null,
  },

  reducers: {
    returnPage(state, { Data }) {
      return { ...state, Data };
    },
    returnResult(state, { Result }) {
      return { ...state, Result };
    },
    returnDataSave(state, { playload }) {
      console.log(playload);
      let DataSave = playload.DataSave;
      return { ...state, DataSave };
    },
    returnDataSaveDetail(state, { playload }) {
      // console.log(playload.DataSaveDetail)
      let DataSaveDetail = playload.DataSaveDetail;
      return { ...state, DataSaveDetail };
    },
    returnImg(state, { ImgSrc }) {
      return { ...state, ImgSrc };
    },
  },

  effects: {
    //标准请求
    *RA({ playload }, { call, put }) {
      const resp = yield call(service.RA, playload);
      console.log(resp);

      if (resp.error_code != '0000') {
        printf(playload, resp);
        message.error(`${resp.error_code}:${resp.error_msg}`);
      } else {
        switch (playload.index) {
          case 25:
            {
              let Data = resp.data;
              yield put({ type: 'returnPage', Data });
            }
            break;
          case 28:
            {
              let Result = resp;
              yield put({ type: 'returnResult', Result });
            }
            break;
          case 47:
            {
              let ImgSrc = resp.data;
              yield put({ type: 'returnImg', ImgSrc });
            }
            break;
        }
      }
    },

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

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

    *SA({ playload }, { put }) {
      console.log(playload);
      // 这里传递两个值来。 一个是修改同步的方法   一个是修改值的名称   一个是修改 的数据
      yield put({
        type: playload.Method,
        playload: {
          [playload.DefaultName]: playload.Data,
        },
      });
    },
  },
};
