import { http } from "../utils/http";
import { loadEnv } from "@build/index";
const { VITE_PROXY_DOMAIN_REAL, VITE_PROXY_USER_REAL } = loadEnv();
const userAPi = VITE_PROXY_DOMAIN_REAL;
const yewuApi = VITE_PROXY_USER_REAL + "/admin/";

interface userType extends Promise<any> {
  svg?: string;
  code?: number;
  info?: object;
}

// 获取验证码
export const getVerify = (): userType => {
  return http.request("get", "/captcha");
};

// 登录
export const getLogin = (data: object) => {
  return http.request("post", `${yewuApi}/login`, { data });
};
// 钉钉获取用户信息
export function ddDetail(data) {
  return http.request("post", `${userAPi}/Api/dintalk`, { data });
}
// 获取当前账号菜单数据
export const getAsyncRoutes = async (data: object) => {
  const companyNo = window.sessionStorage.getItem("companyNo");
  const result = await http.request("post", `${yewuApi}menu`, {
    data: {...data, relaComNo: companyNo }
  });

  window.sessionStorage.removeItem("companyNo");
  return result;
};

// 刷新token
export const refreshToken = (data: object) => {
  return http.request("post", "/refreshToken", { data });
};

export const httpCompany = (data: object): any => {
  return http.request("post", `${yewuApi}comprehensiveList`, { data });
};

export const httpMyCompany = (data: object): any => {
  return http.request("post", `${yewuApi}myCompanyList`, { data });
};

export const httpUserInfo = (data: object): any => {
  return http.request("post", `${yewuApi}userinfo`, { data });
};

export const httpUserList = (data: object): any => {
  return http.request("post", `${yewuApi}userlist`, { data });
};

export const httpSupplierall = (data: object): any => {
  return http.request("post", `${yewuApi}supplierlist`, {
    data
  });
};

export const httpSupplierList = (data: object): any => {
  return http.request("post", `${yewuApi}comprehensiveList`, { data: {... data, type: '3' } });
};
export const httpBusinessList = (data: object): any => {
  return http.request("post", `${yewuApi}comprehensiveList`, { data: {... data, type: '1' } });
};

export const httpGetAllCompany = (data: object) => {
  return http.request("post", `${yewuApi}supplierall`, {
    data
  });
};

export const httpGetSupplier = (data: object) => {
  return http.request("post", `${yewuApi}supplier_by_super`, {
    data
  });
};

export const httpGetBusiness = (_data: object) => {
  return http.request("post", `${yewuApi}companylist`, { data: { ..._data, noRela: true } });
};

export const httpSystemList = (data: object): any => {
  return http.request("post", `${yewuApi}versionlist`, { data });
};


export const transformCompany = (data: object) => {
  return http.request('post', "http://user.api.caixiao365.com/hqInfo", { data })
}
