// 存放路径: src/services/home.ts

import { http } from "@/utils/http";

// 登陆
export const loginByAccount = (data: {
  userName: string;
  password: string;
}) => {
  return http({
    method: "POST",
    url: "/api/user/login",
    data,
  });
};
// 登陆
export const logOut = () => {
  return http({
    method: "POST",
    url: "/api/user/logOut",
  });
};

// 验证码登录
export const loginPhone = (data: { phone: string; code: string }) => {
  return http({
    method: "GET",
    url: "/api/user/loginPhone",
    data,
  });
};

// 发送验证码
export const sendMsg = (data: { phone: string }) => {
  return http({
    method: "GET",
    url: "/api/user/sendMsg",
    data,
  });
};


// 修改密码
export const updateUserPwd = (data: any) => {
  return http({
    method: "POST",
    url: "/api/user/updateUserPwd",
    data
  });
};

// 创建角色
export const addRole = (data: { roleCode: string; roleName: string }) => {
  return http({
    method: "POST",
    url: "/api/role/addRole",
    data,
  });
};
// 修改角色
export const updateRole = (data: {
  id: string;
  roleCode: string;
  roleName: string;
  isDeleted: string;
}) => {
  return http({
    method: "POST",
    url: "/api/role/updateRole",
    data,
  });
};

// 查询角色列表
export const getRoleList = (data: any) => {
  return http({
    method: "GET",
    url: "/api/role/getRoleList",
    data
  });
};

// 验证角色是否重复 1=code 2=名称 3=全部
export const verifyRole = (data: {
  roleCode: string;
  roleName: string;
  type: string;
}) => {
  return http({
    method: "GET",
    url: "/api/role/verifyRole",
    data,
  });
};
// 添加角色菜单权限
export const addMenusRole = (data: {
  id: number;
  list: {
    menusId: number;
    state: number; // 状态1=开启0=关闭
  }[];
}) => {
  return http({
    method: "POST",
    url: "/api/role/addMenusRole",
    data,
  });
};

// 查询角色菜单权限
export const getMenusRole = (data: any) => {
  return http<[]>({
    method: "GET",
    url: "/api/role/getMenusRole",
    data
  });
};

// 查询分页菜单
export const getMenuByPage = (data: any) => {
  return http({
    method: "GET",
    url: "/api/menus/getPage",
    data
  });
};

// 创建菜单
export const addMenus = (data: any) => {
  return http({
    method: "POST",
    url: "/api/menus/addMenus",
    data
  });
};

// 查询菜单List
export const getMenuList = (data: any) => {
  return http({
    method: "GET",
    url: "/api/menus/getList",
    data
  });
};

// 修改菜单
export const updateMenus = (data: any) => {
  return http({
    method: "POST",
    url: "/api/menus/updateMenus",
    data
  });
};

// 查询省市区
export const getProvinceList = (data: any) => {
  return http({
    method: "GET",
    url: "/api/user/getChinaList",
    data
  });
};

// 添加用户
export const addUser = (data: any) => {
  return http({
    method: "POST",
    url: "/api/user/addUser",
    data
  });
};

// 查询用户分页
export const getUserListByPage = (data: any) => {
  return http<User>({
    method: "GET",
    url: "/api/user/getUserPage",
    data
  });
};

// 获取用户信息
export const getUserInfo = (data: any) => {
  return http({
    method: "GET",
    url: "/api/user/getUserInfo",
    data
  });
};

// 添加用户角色关系
export const addUserRole = (data: any) => {
  return http({
    method: "POST",
    url: "/api/user/addUserRole",
    data
  });
};
// 查询用户列表
export const getUserList = (data: {
  name?: string;
  userType?: number; // 1= 工作人员 2=采购商
}) => {
  return http({
    method: "GET",
    url: "/api/user/getUserList",
    data,
  });
};
// 供应商 客户分页
export const getInventoryUserPage = (data: any) => {
  return http<User>({
    method: "GET",
    url: "/api/user/getInventoryUserPage",
    data
  });
};

// 用户下线
export const updateUserByIdOffline = (data: any) => {
  return http<User>({
    method: "POST",
    url: "/api/user/updateUserByIdOffline",
    data
  });
};
// 用户编辑
export const updateUserById = (data: any) => {
  return http<User>({
    method: "POST",
    url: "/api/user/updateUserById",
    data
  });
};


