import http from "@/utils/http";
import { AppDispatch } from "..";

/**
 * 获取列表
 */
export const A2_APIgetList = (data: any, flag?: boolean) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("cms/exhibition/pageList", data);
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total,
      };
      if (flag) dispatch({ type: "A2/inGetList", payload: res.data.records });
      else dispatch({ type: "A2/getList", payload: obj });
    }
  };
};

/**
 * 获取列表-A1下拉
 */
export const A2_APIgetListSelect = (data: any) => {
  return http.post("cms/exhibition/pageList", data);
};

/**
 * 通过id获取详情
 */
export const A2_APIgetInfoById = (id: number) => {
  return http.get(`cms/exhibition/detail/${id}`);
};

/**
 * 新增、修改
 */
export const A2_APIeditItem = (data: any) => {
  return http.post("cms/exhibition/save", data);
};

/**
 * 删除
 */
export const A2_APIdelItem = (id: number) => {
  return http.get(`cms/exhibition/remove/${id}`);
};

/**
 * 置顶
 */
export const A2_APIupdateIndex = (id: number, parentId: number) => {
  return http.get(`cms/exhibition/updateIndex/${id}/${parentId}`);
};
