import http from "@/utils/http";
import { AppDispatch } from "..";
/**
 * 获取 进度统计 表格列表（存到仓库）-按机房
 */
export const B1_APIgetlist = (data: any) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("cms/schedule/pageList", data);
    if (res.code === 0) {
      const obj = {
        list: res.data.records.map((v: any, index: number) => ({
          ...v,
          idKey: v.id + "" + index,
        })),
        total: res.data.total,
      };
      dispatch({ type: "B1/getList", payload: obj });
    }
  };
};

/**
 * 获取 机房管理 表格列表（导出表格）-按机房
 */
export const B1_APIgetlistAll = (data: any) => {
  return http.post("cms/schedule/pageList", data);
};

/**
 * 获取 进度统计 表格列表（存到仓库）-按区域
 */
export const B1_APIgetlistArea = (data: any) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("cms/schedule/report/region", data);
    if (res.code === 0) {
      const arr: any = res.data;

      const arr2: any = [];

      arr.forEach((v: any, i: number) => {
        const cityTxt = `${v.province}${v.city ? "/" + v.city : ""}${
          v.region ? "/" + v.region : ""
        }`;
        arr2.push({
          ...v,
          cityAll: cityTxt,
          id: cityTxt ? cityTxt : i,
        });
      });

      const obj = {
        list: arr2,
        total: res.data.length,
      };
      dispatch({ type: "B1/getListArea", payload: obj });
    }
  };
};

/**
 * 获取 区域 里面的 按日期查看 列表
 */
export const B1_APIgetTimeList = (data: any) => {
  return http.post("cms/schedule/report/trend", data);
};
