import { defineStore } from "pinia";
import { request } from "../api";

export const useInfoStore = defineStore({
  id: "info",
  state: () => {
    return {
      exhibition: [],
      activity: [],
      news: [],
      notices: [],
      pagination: {
        pageNum: 1,
        pageSize: 20,
        searchKey: "",
        type: "",
        total: 0,
      },
    };
  },
  getters: {},
  actions: {
    async getExhibition(page) {
      this.pagination.type = "exhibition";
      this.pagination.pageNum = page || 1;
      const { data, status } = await request.post("/show/news/pageList", {
        ...this.pagination,
      });
      if (data.code === 0) {
        this.exhibition = data.data;
      }
    },
    async getActivity() {
      this.pagination.type = "activity";
      const { data, status } = await request.post("/show/news/pageList", {
        ...this.pagination,
      });
      if (data.code === 0) {
        this.activity = data.data;
      }
    },
    async getNews(page) {
      this.pagination.type = "news";
      this.pagination.pageNum = page || 1;
      const { data, status } = await request.post("/show/news/pageList", {
        ...this.pagination,
      });
      if (data.code === 0) {
        this.news = data.data;
      }
    },
    async getNotices() {
      this.pagination.type = "notice";
      this.pagination.pageNum = 1;
      const { data, status } = await request.post("/show/news/pageList", {
        ...this.pagination,
      });
      if (data.code === 0) {
        this.notices = data.data;
      }
    },
  },
});
