import http from "@/utils/http";
import { AppDispatch } from "..";
/**
 * 获取列表
 */
export const A1_APIgetList = (data: any) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("cms/project/pageList", data);
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total,
      };
      dispatch({ type: "A1/getList", payload: obj });
    }
  };
};

/**
 * 新增、编辑 项目
 */
export const A1_APIaddProject = (data: any) => {
  return http.post("cms/project/save", data);
};

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

/**
 * 通过id删除项目
 */
export const A1_APIdelProject = (id: number) => {
  return http.get(`cms/project/remove/${id}`);
};

/**
 * 通过id获取下载列表
 */
export const A1_APIgetDownList = (id: number) => {
  return http.get(`cms/inside/download/echoList/${id}`);
};

/**
 * 下载列表点击确定（外层）
 */
export const A1_APIdownBtnOk = (data: any) => {
  return http.post("cms/inside/download/attrIds", data);
};

// --------------------------  项目文件  --------------------------
/**
 * 项目文件---------获取 左侧一级 写死目录
 */
export const A1_APIOgetHardCoded = () => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get("cms/item/getHardCoded");
    if (res.code === 0) {
      dispatch({ type: "A1/outLeftArr", payload: res.data });
    }
  };
};

/**
 * 项目文件---------新增、修改
 */
export const A1_APIOadd = (data: any) => {
  return http.post("cms/item/save", data);
};

/**
 * 项目文件---------获取列表
 */
export const A1_APIOgetList = (data: any) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("cms/item/pageList", data);
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total,
      };
      dispatch({ type: "A1/outTableArr", payload: obj });
    }
  };
};

/**
 * 项目文件---------批量下载
 */
export const A1_APIOdownload = (ids: string | number) => {
  return http.get(`cms/item/download/${ids}`);
};

/**
 * 项目文件---------删除文件
 */
export const A1_APIOdel = (id: number) => {
  return http.get(`cms/item/remove/${id}`);
};

/**
 * 项目文件---------批量上传点击确定
 */
export const A1_APIOupFileIds = (ids: string) => {
  return http.post(`cms/item/update/display?fileId=${ids}`);
};

/**
 * 项目文件---------获取列表 ---- 文件移动的展示
 */
export const A1_APIOgetListMove = (projectId: number, parentId: number) => {
  return http.post("cms/item/pageList", {
    pageNum: 0,
    pageSize: 99999,
    projectId,
    parentId,
  });
};

/**
 * 项目文件---------移动文件
 */
export const A1_APIOmove = (id: number, parentId: number) => {
  return http.get(`cms/item/move/${id}/${parentId}`);
};

/**
 * 项目介绍的删除
 */
export const A1_APIremoveSure = (fileIds: string[]) => {
  return http.post("cms/dict/delFile", { fileIds });
};

/**
 * 项目文件---------上传文件成功 还没有点确定 的时候的 真删除
 */

export const A1_APIremoveOut = (ids: string) => {
  return http.post(`cms/item/delTemp?ids=${ids}`);
};


/**
 * 内控文件---------上传文件成功 还没有点确定 的时候的 真删除
 */
export const A1_APIremoveInn = (ids: string) => {
  return http.post(`cms/inside/delTemp?ids=${ids}`);
};

// --------------------------  项目成员  --------------------------
/**
 * 项目成员---------获取列表
 */
export const A1_APIUgeiList = (projectId: number, val: string) => {
  return http.get(`cms/member/getList/${projectId}?searchKey=${val}`);
};

/**
 * 项目成员---------新增/编辑
 */
export const A1_APIUsave = (data: any) => {
  return http.post("cms/member/save", data);
};

/**
 * 项目成员---------删除
 */
export const A1_APIUdel = (id: number) => {
  return http.get(`cms/member/remove/${id}`);
};

// --------------------------  内控文件  --------------------------

/**
 * 内控文件---------获取内控文件属性的已过滤的列表
 */
export const A1_APIIgetIresList = () => {
  return http.get("cms/inside/getFileAttributeList");
};

/**
 * 内控文件---------获取列表
 */
export const A1_APIIgetList = (data: any) => {
  return http.post("cms/inside/getList", data);
};
/**
 * 内控文件---------删除列表(调用成功之后到回收站)
 */
export const A1_APIIdel = (data: any) => {
  return http.post(`cms/inside/remove`, data);
};

/**
 * 内控文件---------获取登记缺失文件列表
 */
export const A1_APIIgetLack = (projectId: number) => {
  return http.get(`cms/inside/getRegister/${projectId}`);
};

/**
 * 内控文件---------登记缺失文件
 */
export const A1_APIIsaveLack = (
  projectId: number,
  data: { attributeId: number; description: string }[]
) => {
  return http.post(`cms/inside/lack/save/${projectId}`, data);
};

/**
 * 内控文件---------审批
 */
export const A1_APIIaudit = (data: any) => {
  return http.post("cms/inside/audit", data);
};

/**
 * 内控文件---------上传点击确定
 */
export const A1_APIIupBtnOk = (projectId: number, data: any) => {
  return http.post(`cms/inside/update/${projectId}`, data);
};

/**
 * 内控文件---------批量下载
 */
export const A1_APIIdowns = (ids: string) => {
  return http.get(`cms/inside/download/${ids}`);
};
