import { request } from '@/utils/request.js';

export const login = (data) =>
  request({
    url: '/api/admin/common/login',
    method: 'post',
    data,
    loading: true,
    noAuth: true,
  });
export const getOrgStructList = () =>
  request({
    url: '/api/admin/org/list',
  });
export const addOrgNode = (data) =>
  request({
    url: '/api/admin/org/save',
    data,
    loading: true,
  });
export const toggleOrgNodeStatus = (data) =>
  request({
    url: '/api/admin/org/enable',
    data,
    loading: true,
  });
export const getUserList = (data) =>
  request({
    url: '/api/admin/user/list',
    params: data,
  });
export const getUserListDjr = (data) =>
  request({
    url: '/api/admin/device/in/out/registrant_list',
    params: data,
  });
export const getRoleList = (data) =>
  request({
    url: '/api/admin/role/list',
    params: data,
  });
export const getAllRoleList = (data) =>
  request({
    url: '/api/admin/common/get_role_list',
    params: data,
  });
export const addUser = (data) =>
  request({
    url: '/api/admin/user/save',
    data,
    loading: true,
  });
export const toggleUserStatus = (data) =>
  request({
    url: '/api/admin/user/enable',
    data,
    loading: true,
  });
export const getAllMenuResource = () =>
  request({
    url: '/api/admin/sys/privilege/list',
  });

export const addRole = (data) =>
  request({
    url: '/api/admin/role/save',
    data,
    loading: true,
  });
export const deleteRole = (data) =>
  request({
    url: '/api/admin/role/delete',
    params: data,
    loading: true,
  });
export const getRoleDetail = (data) =>
  request({
    url: '/api/admin/role/privilege/list',
    params: data,
  });
export const logout = (data) =>
  request({
    url: '/api/admin/common/logout',
    data,
    loading: true,
  });
export const updateMyPassword = (data) =>
  request({
    url: '/api/admin/common/update_password',
    data,
    loading: true,
  });
export const updateUserPassword = (data) =>
  request({
    url: '/api/admin/user/update_password',
    data,
    loading: true,
  });
export const initUserPassword = (data) =>
  request({
    url: '/api/admin/user/init_password',
    data,
    loading: true,
  });
export const getVerifyCode = (data) =>
  request({
    url: '/api/admin/common/get_verify_code',
    data,
    noAuth: true,
  });
export const forgetPassword = (data) =>
  request({
    url: '/api/admin/common/forget_password',
    data,
    loading: true,
    noAuth: true,
  });
export const getMenus = () =>
  request({
    url: '/api/admin/common/get_menu', //真实接口url
    method: 'post',
    loading: true,
  });

export const editUser = (data) =>
  request({
    url: '/api/edit',
    method: 'post',
    data,
  });

export const getRoleUserList = (roleType) =>
  request({
    url: '/api/admin/common/get_user_list_by_role_type',
    params: { roleTypeEnum: roleType },
  });
export const getAllUserList = (roleType) =>
  request({
    url: '/api/admin/common/get_user_list',
  });
export const fileUploadApi = (data) =>
  request({
    url: '/api/admin/common/file/upload',
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
      'md5': data.get('md5'),
    },
  });

export const getAttachmentFile = (taskId, type) =>
  request({
    url: '/api/admin/common/file/download',
    params: { taskId, type },
  });
export const getAttachmentList = (ids) =>
  request({
    url: '/api/admin/common/file/preview',
    data: ids,
  });
export const getAttachmentListByKey = (key) =>
  request({
    url: '/api/admin/common/file/preview/app',
    params: { key },
  });
//根据用户id查询可绑定的供应商列表options
export const getSupplierByUser = (params) =>
  request({
    url: '/api/sys/supplier/list/by/user_role',
    params,
  });
//用户绑定过的供应商
export const getUserBindSupplier = (params) =>
  request({
    url: '/api/admin/user/query/supplier',
    params,
  });
//用户绑定供应商
export const userBindSupplier = (params) =>
  request({
    url: '/api/admin/user/band/supplier',
    params,
  });
