import {
  getCarouselImgUrlAPI,
  getNoticeDataAPI,
  getTodoDadaAPI,
  getAutoPlaySpeedAPI
} from "../services/api";
import { getCustomer } from "@/utils/request";

export default {
  namespace: "home",

  state: {
    imgSrcData: null
  },

  effects: {
    // 请求轮播图片
    *getCarouselImgUrl({ payload }, { call, put }) {
      const response = yield call(getCarouselImgUrlAPI, payload);
      yield put({
        type: "imgSrcData",
        imgSrcData: response ? response.content : []
      });
    },
    // 请求轮播时间间隔
    *getAutoPlaySpeed({ payload }, { call, put }) {
      const response = yield call(getAutoPlaySpeedAPI, payload);
      yield put({
        type: "autoPlaySpeed",
        autoPlaySpeed: response ? response.content : []
      });
    },
    // 请求公告
    // *getNoticeData({ payload }, { call, put }) {
    //   const response = yield call(getNoticeDataAPI, payload);
    //   yield put({
    //     type: "noticeData",
    //     noticeData: response.content
    //   });
    // },
    *getNoticeData({ payload }, { call, put }) {
      const response = yield call(getNoticeDataAPI, payload);
      // const response = [
      //   {
      //     noticeType: "a7e07637-cdcc-4471-9682-c5149f5da97d",
      //     noticeTypeName: "促销",
      //     noticeInfoMap: [
      //       {
      //         noticeId: "1f906d12-f0ce-4499-849a-ede25c435b75",
      //         title: "新品促销政策通知",
      //         pubdate: 1524240000000
      //       },
      //       {
      //         noticeId: "d4bafbf1-b772-4cf0-9b9b-fb332009611d",
      //         title: "班车发车时间变更",
      //         pubdate: 1524240000000
      //       },
      //       {
      //         noticeId: "b77f31c2-8b19-49a6-945a-6254f3c63f95",
      //         title: "413758",
      //         pubdate: 1525449600000
      //       },
      //       {
      //         noticeId: "b77f31c2-8b19-49a6-945a-6254f3c63f95",
      //         title: "413758",
      //         pubdate: 1525449600000
      //       },
      //       {
      //         noticeId: "b77f31c2-8b19-49a6-945a-6254f3c63f95",
      //         title: "413758",
      //         pubdate: 1525449600000
      //       }
      //     ]
      //   },
      //   {
      //     noticeType: "db2b657c-deb5-4c2d-b8c7-8e91db9837c1",
      //     noticeTypeName: "新品",
      //     noticeInfoMap: [
      //       {
      //         noticeId: "6ba36e2d-dc10-4eec-bf72-375bb887891a",
      //         title: "gg",
      //         pubdate: 1525881600000
      //       }
      //     ]
      //   },
      //   {
      //     noticeType: "db2b657c-deb5-4c2d-b8c7-8e91db9837c1",
      //     noticeTypeName: "物流",
      //     noticeInfoMap: [
      //       {
      //         noticeId: "6ba36e2d-dc10-4eec-bf72-375bb887891a",
      //         title: "gg",
      //         pubdate: 1525881600000
      //       }
      //     ]
      //   }
      // ];
      yield put({
        type: "noticeData",
        noticeData: response
      });
    },
    // 请求待办事项
    // *getTodoDada({ payload }, { call, put }) {
    //   if (!payload) payload = {};
    //   payload.customerId = getCustomer().id;
    //   const response = yield call(getTodoDadaAPI, payload);
    //   yield put({
    //     type: "todoDada",
    //     todoDada: response
    //   });
    // }
  },

  reducers: {
    imgSrcData(state, payload) {
      return {
        ...state,
        imgSrcData: payload.imgSrcData
      };
    },
    autoPlaySpeed(state, payload) {
      return {
        ...state,
        autoPlaySpeed: payload.autoPlaySpeed
      };
    },
    noticeData(state, payload) {
      return {
        ...state,
        noticeData: payload.noticeData
      };
    },
    todoDada(state, payload) {
      return {
        ...state,
        todoDada: payload.todoDada
      };
    }
  }
};
