import {
  getAnnouncementDataAPI,
  getAnnouncementClassifyDataAPI
} from "../services/api";
import { getCustomer } from "@/utils/request.js";
export default {
  namespace: "announcement",

  state: {},

  effects: {
    *getAnnouncementData({ payload }, { call, put }) {
      payload[`customerId`] = getCustomer().id;
      const response = yield call(getAnnouncementDataAPI, payload);
      yield put({
        type: "announcementData",
        announcementData: response
      });
    },
    *getAnnouncementClassifyData({ payload }, { call, put }) {
      payload = payload || {};
      payload[`search_EQ_isEnable`] = 1;
      payload[`search_EQ_dr`] = 0;
      const response = yield call(getAnnouncementClassifyDataAPI, payload);
      yield put({
        type: "announcementClassifyData",
        announcementClassifyData: response.content
      });
    },
    *getAnnouncementTimeData({ payload }, { call, put }) {
      // const response = yield call(API, payload);
      const response = [
        {
          code: "1",
          name: "近一周"
        },
        {
          code: "2",
          name: "近一月"
        },
        {
          code: "3",
          name: "近一年"
        }
      ];
      yield put({
        type: "announcementTimeData",
        announcementTimeData: response
      });
    }
  },
  reducers: {
    announcementData(state, payload) {
      return {
        ...state,
        announcementData: payload.announcementData
      };
    },
    announcementClassifyData(state, payload) {
      return {
        ...state,
        announcementClassifyData: payload.announcementClassifyData
      };
    },
    announcementTimeData(state, payload) {
      return {
        ...state,
        announcementTimeData: payload.announcementTimeData
      };
    }
  }
};
