import { http } from "@/utils/http";
import { ElMessage } from "element-plus";
// 用户设置
type addDept = {
  code: number;
  msg: string;
  data: boolean;
};
type userList = {
  code: number;
  msg: string;
  data: recordsList;
};
type userPageList = {
  code: number;
  msg: string;
  data: Array<any>;
};

type recordsList = {
  records: Array<any>;
  totalPage: number;
  totalRow: number;
};
// 查询用户列表
export const postUserList = data => {
  return http.request<userPageList>("post", "/user/userList", { data });
};
// 查看不同组织架构下用户
export const postOrganizationUserPage = data => {
  return http.request<userList>("post", "/user/organizationUserPage", { data });
};
// 组织架构关联动作
export const postAssignmentUser = data => {
  return http.request<addDept>("post", "/user/assignmentUser", { data });
};
export const postAssignmentUserApi = async (data, pageList) => {
  const { code, msg } = await postAssignmentUser(data);
  if (code === 200) {
    ElMessage.success("移除成功");
    pageList();
  } else {
    console.log(msg);
    // ElMessage.error(msg);
  }
};
// 删除用户
export const getDeleteUser = params => {
  return http.request<addDept>("get", "/user/deleteUser", { params });
};
export const getDeleteUserApi = async (userCode, pageList) => {
  const { msg, code } = await getDeleteUser({ userCode });
  if (code === 200) {
    ElMessage.success("删除成功");
    pageList();
  } else {
    ElMessage.error(msg);
  }
};
// 更新当前用户信息
export const postUpdateUserInfo = data => {
  return http.request<addDept>("post", "/user/updateUserInfo", { data });
};
// 查看用户数据包含用户部门，用户组
export const userPageWhitOrganization = data => {
  return http.request<addDept>("post", "/user/userPageWhitOrganization", {
    data
  });
};
// 获取所有负责人数据（deptCode不转返回所有）
export const getLeaderList = (params?: string) => {
  return http.request<userPageList>("get", "/user/getLeaderList", {
    params
  });
};
