/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2022-12-21 11:13:51
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-11-10 10:26:29
 * @FilePath: /BudgetManaSystem/src/pages/budgetMana/monthlyInfoCheck/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { request } from 'umi';

//获取树结构数据

export type getTreeDataRespType = {
  code: number;
  name: string;
  children: getTreeDataRespType[];
};

export const getTreeData = (name?: string) => {
  return request<getTreeDataRespType[]>('/centerSys/navigation/getSystemList', {
    method: 'GET',
    params: { name },
  });
};

//获取菜单内容类型列表

export const getMenuContentType = (systemId: string) => {
  return request('/centerSys/sysdictdata/getDictDataList?current=1&pageSize=1000&dictType=MENU_CONTENT_TYPE', {
    method: 'GET',
    params: { systemId },
  });
};

//获取表格数据

export type SystemRelaMenuDataType = {
  menuId: string;
  parentId: string;
  name: string;
  path: string;
  url: string;
  softUrl: string;
  perms: string;
  type: number;
  icon: string;
  orderNum: number;
  reportId: string;
  contentType: number;
  isHomepage: number;
  children: SystemRelaMenuDataType[];
};

export const getTableDataRequest = (params: { systemId: string; name?: string }) => {
  return request<SystemRelaMenuDataType[]>('/centerSys/navigation/getMenuList', {
    method: 'GET',
    params: { ...params },
  });
};

//新增菜单

export type AddMenuDataType = {
  parentId: number;
  name: string;
  path: string;
  url: string;
  softUrl: string;
  perms: string;
  type: string;
  icon: string;
  orderNum: number;
  reportId: string;
  contentType: string;
  isHomepage: number;
  systemId: number;
};

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

//编辑菜单

export type EditMenuDataType = {
  parentId: number;
  name: string;
  path: string;
  url: string;
  softUrl: string;
  perms: string;
  type: string;
  icon: string;
  orderNum: number;
  reportId: string;
  contentType: string;
  isHomepage: number;
  systemId: number;
  menuId: number;
};

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

//删除菜单
export const delData = (menuId: number) => {
  return request('/centerSys/navigation/deleteMenu', {
    method: 'POST',
    params: { menuId },
  });
};

//获取功能字典

export type MenuRelaActDicItemType = {
  code: string;
  value: string;
  name: string;
};

export const getMenuRelaActDic = () => {
  return request<MenuRelaActDicItemType[]>('/centerSys/navigation/getFunctionDict', {
    method: 'GET',
  });
};

//保存功能字典

export const updateFuncDic = (data: { menuId: number; function: { code: string; name: string }[] }) => {
  return request('/centerSys/navigation/addFunction', {
    method: 'POST',
    data,
  });
};
