/*
 * @Author: your name
 * @Date: 2022-01-18 14:56:29
 * @LastEditTime: 2024-12-27 14:43:38
 * @LastEditors: code4eat awesomedema@gmail.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/src/service/role.ts
 */

import { TableRequestParamsType, TableResponseDataType } from '@/typings';
import { request } from 'umi';

//获取所有角色

export type RoleItemType = {
  allUsers: any;
  roleId: number;
  roleName: string;
  hospName: string;
  modifyTime: string;
  remark: string;
  hospId: number;
  dataPermissionCode?:string;
  dataPermissionName?:string;
  roleTags?:any[]
};

type GetAllRolesType = { list: RoleItemType[] } & TableResponseDataType;
export const getAllRoles = async (params: { roleName?: string } & TableRequestParamsType) => {
  return request<GetAllRolesType>('/centerSys/role/list', {
    method: 'GET',
    params: { ...params },
  });
};

//新增角色
export const addRoles = async (data: { roleName: string; remark?: string; hospId: number }) => {
  return request('/centerSys/role/addRole', {
    method: 'POST',
    data: { ...data },
  });
};

//删除角色
export const delRoles = async (data: number[]) => {
  return request('/centerSys/role/deleteRole', {
    method: 'POST',
    data: data,
  });
};

//编辑角色
export const editRoles = async (data: {
  remark: string;
  roleId: number;
  roleName: string;
  youshuUserId: number;
}) => {
  return request('/centerSys/role/editRole', {
    method: 'POST',
    data: data,
  });
};

//根据角色获取一绑定的菜单
export const getRoleHasBindMenus = async (params: {
  hospId: number;
  roleId: number;
  name?: string;
}) => {
  return request<{
    menuVOs: any[];
    menuIds: number[];
  }>('/centerSys/role/roleMenuList', {
    method: 'GET',
    params: params,
  });
};

//角色绑定菜单
export const roleBindMenus = async (data: {
  hospId: number;
  roleId: number;
  menuIds: number[];
}) => {
  return request('/centerSys/role/editRoleMenu', {
    method: 'POST',
    data,
  });
};

//根据角色获取已绑定的人员
export const getRoleHasBindUsers = async (params: {
  hospId: number;
  roleId: number;
  name?: string;
}) => {
  return request<{
    users: any[];
    userIds: number[];
  }>('/centerSys/role/roleUserList', {
    method: 'GET',
    params: params,
  });
};

//角色绑定人员
export const roleBindUsers = async (data: {
  hospId: number;
  roleId: number;
  userIds: number[];
}) => {
  return request('/centerSys/role/editUserRole', {
    method: 'POST',
    data,
  });
};



//角色绑定api权限菜单列表

export const getRolePermRelaMenu = async (params: {
  hospId: number;
  roleId: string;
  systemId:string,
  name?:string;
}) => {
  return request('/centerSys/role/getMenuList', {
    method: 'GET',
    params,
  });
};


//保存角色与菜单api权限关系
export const saveRoleRelaApiPerm = async (data:any) => {
  return request('/centerSys/navigation/addBatchRoleFunction', {
    method: 'POST',
    data,
  });
};


//初始化角色
export const initRoleFunc = async (params:{hospId:number;roleId:number}) => {
  return request('/centerSys/role/initRole', {
    method: 'POST',
    params,
  });
};

//初始化角色只读
export const initRoleReadOnlyFunc = async (params:{hospId:number;roleId:number}) => {
  return request('/centerSys/role/initRoleReadOnly', {
    method: 'POST',
    params,
  });
};





