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/";
const accountApi = VITE_PROXY_USER_REAL + "/account/";

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}user/login`, { data });
};
// 钉钉获取用户信息
export function ddDetail(data) {
  return http.request("post", `${userAPi}/Api/dintalk`, { data });
}
// 获取当前账号菜单数据
export const getAsyncRoutes = async (data: object) => {
  // /admin/action/query
  // await http.request("post", `${yewuApi}action/query`, { data:{} })
  const result = await http.request("post", `${yewuApi}role_action/menu`, {
    data
  });
  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}getcompany`, {
    data
  });
};

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

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

export const httpDepart = (data: object): any => {
  return http.request("post", `${accountApi}depart`, { data });
};

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

export const httpSupplierList = (data: object): any => {
  return http.request("post", `${accountApi}depart/supplier `, {
    data
  });
};

export const httpBusinessList = (data: object): any => {
  return http.request("post", `${accountApi}depart/business`, {
    data
  });
};

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 httpSystemLast = (data: object): any => {
  return http.request("post", `${yewuApi}systemlast`, { data });
};
