import http from "@/utils/http";
import { AppDispatch } from "..";
/**
 * 获取 云学校 列表
 */
export const A7_APIgetList = (data: any, type: "口述史" | "刊物") => {
  return async (dispatch: AppDispatch) => {
    const flag = type === "口述史";
    const res = await http.post(
      `cms/${flag ? "person" : "periodical"}/pageList`,
      data
    );
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total,
      };

      dispatch({
        type: flag ? "A7/getList1" : "A7/getList2",
        payload: obj,
      });
    }
  };
};

/**
 * 获取采访主题列表
 */
export const A7_APIgetListByTheme = () => {
  return http.get("cms/person/getDict");
};

/**
 * 采访主题 - 删除
 */
export const A7_APIthemeDel = (id: number) => {
  return http.get(`cms/dict/remove/${id}`);
};

/**
 * 采访主题 - 排序
 */
export const A7_APIthemeSort = (id1: number, id2: number) => {
  return http.get(`cms/dict/sort/${id1}/${id2}`);
};

/**
 * 采访主题 - 新增、编辑
 */
export const A7_APIthemeSave = (data: any) => {
  return http.post("cms/dict/save", data);
};

/**
 * 口述史 - 详情
 */
export const A7_APIgetInfo = (id: number) => {
  return http.get(`cms/person/detail/${id}`);
};

/**
 * 口述史 - 新增、编辑
 */
export const A7_APIsave = (data: any) => {
  return http.post("cms/person/save", data);
};

/**
 * 口述史 刊物 - 删除
 */
export const A7_APIdel = (id: number, type: "口述史" | "刊物") => {
  return http.get(
    `cms/${type === "口述史" ? "person" : "periodical"}/removes/${id}`
  );
};

/**
 * 刊物 - 详情
 */
export const A7_APIgetInfoBook = (id: number) => {
  return http.get(`cms/periodical/detail/${id}`);
};

/**
 * 刊物 - 新增、编辑
 */
export const A7_APIsaveBook = (data: any) => {
  return http.post("cms/periodical/save", data);
};
