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

/**
 * 获取藏品登记列表信息
 */
export const getObject6List = (data: any) => {
  return async (dispatch: AppDispatch) => {
    // 获取列表数据
    const res: any = await http.post("cms/cancel/pageList", data);
    const list = res.data.records;
    list.forEach((v: any) => {
      v.statusTxt = statusObj[v.status];
    });
    const obj = {
      list,
      total: res.data.total,
    };
    dispatch({ type: "object6/getList", payload: obj });
  };
};

/**
 * 获取藏品登记列表顶部数字信息
 */
export const getObject6ListNum = () => {
  return async (dispatch: AppDispatch) => {
    // 获取统计数据
    const res: any = await http.get("cms/cancel/countByStatus");

    const data = [
      { id: null, name: "全部", num: res.data.all ? res.data.all : 0 },
      // { id: 0, name: "待办理", num: res.data[0] ? res.data[0] : 0 },
      { id: 1, name: "待审核", num: res.data[1] ? res.data[1] : 0 },
      { id: 2, name: "审核不通过", num: res.data[2] ? res.data[2] : 0 },
      { id: 3, name: "已完成", num: res.data[3] ? res.data[3] : 0 },
    ];
    dispatch({ type: "object6/getListNum", payload: data });
  };
};

/**
 * 删除外层表格数据
 */
export const object6DelAPI = (id: number) => {
  return http.get(`cms/cancel/remove/${id}`);
};

/**
 * 通过id获取信息
 */
export const object6infoOutAPI = (id: number) => {
  return http.get(`cms/cancel/detail/${id}`);
};

/**
 * 进新增页面发送请求
 */
export const object6AddAPI = (data?: any) => {
  return http.post("cms/cancel/save", { ...data });
};

/**
 * 点击新增或者编辑里面的添加按钮的所有藏品列表
 */
export const getGoodsListAllAPI = (val: any) => {
  return async (dispatch: AppDispatch) => {
    // 获取统计数据
    const res: any = await http.get(`cms/cancel/goods/list?searchKey=${val}`);
    dispatch({ type: "object6/setGoodsListAll", payload: res.data });
  };
};

/**
 * 审核入库信息
 */
export const auditObject6API = (data: any) => {
  return http.post("cms/cancel/audit", data);
};

