/*
 * @Author: your name
 * @Date: 2022-01-13 09:15:59
 * @LastEditTime: 2023-09-14 14:00:11
 * @LastEditors: code4eat awesomedema@gmail.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/src/service/hospList.ts
 */

import { Key } from 'react';
import { request } from 'umi';

//获取当前登陆院区以及互通的院区列表
export const getShareHospList = async () => {
  return request<
    {
      id: number;
      name: string;
    }[]
  >('/centerSys/hospital/currentAndShareHosp', {
    method: 'GET',
  });
};


//获取所有院区
export const getHospList = async () => {
  return request<
    {
      id: number;
      name: string;
    }[]
  >('/centerSys/hospital/getAllMainList', {
    method: 'GET',
  });
};

//获取主院
export const getMainHosp = async () => {
  return request<{
    id: number;
    name: string;
  }[]>('/centerSys/hospital/getMainList', {
    method: 'GET',
  });
};

export type HospTableItem = {
  id: number;
  hospName: string;
  hospSign: string;
  hospAbbreviation: string;
  mainHospId: number;
  mainHospName: string;
  updateTime: string;
  systemName: string;
  dataShare: string;
};

//获取医院列表
export const getAllHosp = async (params?: {
  current: number;
  pageSize: number;
  hospitalName?: string;
}) => {
  return request<{
    current: number;
    pageSize: number;
    totalCount: number;
    totalPage: number;
    list?: HospTableItem[];
  }>('/centerSys/hospital/list', {
    method: 'GET',
    params: params,
  });
};

export type AddHospDataType = {
  hospAbbreviation: string; //医院简称
  hospName: string;
  hospSign: string;
  isDataShare: number; //是否数据共享，0.默认，不共享，1.共享数据
  mainHospId: number;
  mainHospName: string;
  systemName: string;
};
//添加院区
export const addHosp = async (data: AddHospDataType) => {
  return request('/centerSys/hospital/addHospital', {
    method: 'POST',
    data: data,
  });
};

//院区管理删除院区

export const delHosp = async (data: number[]) => {
  return request('/centerSys/hospital/deleteHosp', {
    method: 'POST',
    data: data,
  });
};

//院区管理编辑院区
export type EditHospType = {
  id: number;
  hospAbbreviation: string;
  hospName: string;
  hospSign: string;
  isDataShare: string;
  systemName: string;
};
export const editHosp = async (data: EditHospType) => {
  return request('/centerSys/hospital/editHosp', {
    method: 'POST',
    data: data,
  });
};

//院区绑定菜单

export const hospBindMenu = async (data: { hospId: number; menuIds: string[] }) => {
  return request('/centerSys/hospital/addHospMenu', {
    method: 'POST',
    data: data,
  });
};

export type YoushuAccountsType = {
  id: number;
  userName: string;
  account: string;
  password: string;
  isDefault: number; //是否默认0，非默认，1.默认
};

export type GetHospYoushuAccountsType = {
  reportUrl: string;
  reportId: string;
  youshuUsers: YoushuAccountsType[];
};

export const getHospYoushuAccounts = async (data: { hospId: number }) => {
  return request<GetHospYoushuAccountsType>('/centerSys/hospital/getHospReport', {
    method: 'GET',
    params: data,
  });
};

export type YoushuUserSaveDTOs = {
  userName: string;
  account: string;
  password: string;
};

export type HospBindYoushuAccountReqBodyType = {
  hospId: number;
  reportId: number;
  reportUrl: string;
  userId: number;
  youshuUserSaveDTOs: YoushuUserSaveDTOs[];
};

export const hospBindYoushuAccount = async (data: HospBindYoushuAccountReqBodyType) => {
  return request('/centerSys/hospital/saveHospReport', {
    method: 'POST',
    data: data,
  });
};

//院区初始化
export const hospInit = async (hospId:Key) => {
  return request('/centerSys/role/init', {
    method: 'POST',
    params:{hospId},
  });
};


//获取院区对应的菜单列表

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

}

//保存院区菜单绑定的api权限
export const saveHospMenuApiPerm = async (data:any) => {
  return request('/centerSys/hospital/addBatchFunction', {
    method: 'POST',
    data
  });
};



//初始化只读
export const setReadOnly = async (hospId:string) => {
  return request(`/centerSys/role/initReadOnly?hospId=${hospId}`, {
    method: 'POST'
  });
};

//院区菜单全部按钮
export const setIfCheckAll= async (params:{systemId:string,hospId:string,type:string}) => {
  return request(`/centerSys/hospital/setAll`, {
    method: 'POST',
    params
  });
};



//获取当前院的系统列表
export const getHospOwnSys = async (hospId:string) => {
  return request(`/centerSys/hospital/getSystemList?hospId=${hospId}`, {
    method: 'GET'
  });
};

//获取当前院区所有科室
export const getCurrentHospAllDepartments = async () => {
  return request(`/centerSys/sysdepartment/getHospDepartment`, {
    method: 'GET'
  });
};

//获取当前院区所有人员信息
export const getCurrentHospAllEmps = async () => {
  return request(`/centerSys/user/getUserByHospId`, {
    method: 'GET'
  });
};
