/*
 * @Author: your name
 * @Date: 2022-01-10 10:27:15
 * @LastEditTime: 2023-09-07 17:38:41
 * @LastEditors: code4eat awesomedema@gmail.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/src/service/hospInfo.ts
 */

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

//获取平台菜单
export const getPlatformMenu = async (systemId?:Key) => {
  return request('/centerSys/user/getMenuNav', {
    method: 'GET',
    params: { systemId },
  });
};

//菜单管理界面菜单列表
export interface MenuItemDataType {
  menuId: string;
  icon?: any;
  name: string;
  orderNum?: number; //排序数字
  parentId: string; //父级id，没有传0
  path: string;
  perms?: string;
  softUrl?: string;
  type: number;
  url?: string;
  key?:string;
  contentType:string;
  systemId?:string;
  isHomepage:number;
  description:string;
  modifyTime: string;
  isSetupMenu?:number;
  children: MenuItemDataType[];
}

export interface getAllMenusDataType extends TableResponseDataType {
  list: MenuItemDataType[];
}

interface getAllMenusDataParamsType {
  name?: string;
}

export const getAllMenus = async () => {
  return request<getAllMenusDataType>('/centerSys/menu/list', {
    method: 'GET',
  });
};

//获取院区所拥有的菜单
export const getHospAllMenus = async (hospId:string|number) => {
  return request<{selectedMenuIds:string[];allMenuVO:getAllMenusDataType[]}>('/centerSys/hospital/getHospCheckedMenu', {
    method: 'GET',
    params:{hospId}
  });
};

//菜单管理-新增菜单

export type AddMenuDataType = {
  icon?: any;
  name: string;
  orderNum?: number; //排序数字
  parentId: number; //父级id，没有传0
  path: string;
  perms?: string;
  softUrl?: string;
  type: number;
  contentType:string;
  url?: string;
};

export const addMenu = async (data: AddMenuDataType) => {
  return request('/centerSys/menu/addMenu', {
    method: 'POST',
    data: data,
  });
};

//菜单管理- 编辑菜单

export type EditMenuDataType = {
  id?: string;
  icon?: any;
  name: string;
  orderNum?: number; //排序数字
  parentId: number; //父级id，没有传0
  path: string;
  perms?: string;
  softUrl?: string;
  type: number;
  contentType:string;
  url?: string;
};

export const editMenu = async (data: EditMenuDataType) => {
  return request('/centerSys/menu/editMenu', {
    method: 'POST',
    data: data,
  });
};

//菜单管理-删除菜单
export const delMenu = async (data: number[]) => {
  return request('/centerSys/menu/removeMenu', {
    method: 'POST',
    data: data,
  });
};

//获取指定院区菜单
export const getSpacifyHospMenu = async (data: { hospId: number }) => {
  return request<{
    selectedMenuIds: string[];
    allMenuVO: any[];
  }>('/centerSys/hospital/getHospMenu', {
    method: 'GET',
    params: data,
  });
};


//获取用户在平台中所拥有的导航菜单

export type UserPlatformNav = {
  menuId:string|number;
  name:string;
  type:number;
  path:string;
  systemId:string;
  contentType:number;
  child:UserPlatformNav[];
}

export const getUserPlatformNav =async () => {
  return request<UserPlatformNav[]>('/centerSys/user/getUserMenu', {
    method: 'GET',
  });
}


//添加快速入口

export type AddFastEntryDataType = {
  menuId:string|number;
  systemId:string|number;
  name:string;
  path:string;
}

export const addFastEntry = async (data:AddFastEntryDataType[]) => {
     
  return request('/centerSys/index/addFastEntrance', {
    method: 'POST',
    data: data,
  });   

}



//菜单设为首页
export const menuSetToHomePage = async (data:{menuId:string;menuName:string;}) => {
  return request('/centerSys/menu/setHomePage', {
    method: 'POST',
    params: data,
  });   
}

//菜单目录列表
export const getMenuDirectory = async () => {
  return request<{list:MenuItemDataType[]}>('/centerSys/menu/catalogList', {
    method: 'GET',
  });   

}

//复制/移动菜单

export const transformMenu = async (type:'MOVE'|'COPY',menuId:Key,catalogId:Key) => {
  if(type == 'COPY'){
    return request('/centerSys/menu/copyMenu', {
      method: 'POST',
      params:{menuId,catalogId},
    });   
  }
  if(type == 'MOVE'){
    return request('/centerSys/menu/moveMenu', {
      method: 'POST',
      params:{menuId,catalogId},
    });   
  }

}

//通过ID获取指定菜单的详情

export const getSpecifyMenuDetail = async (menuId:Key) => {
  return request<MenuItemDataType>('/centerSys/menu/getMenuDetail', {
    method: 'GET',
    params:{menuId}
  });   

}





