import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeptForm, DeptQuery, DeptVO } from './types';

// 查询部门列表
export const listDept = (types: number[], menuId: string | undefined) => {
  return request({
    url: '/sys/dept/listTree',
    method: 'post',
    data: { orgTypes: types, reviewTag: 1, scopeMenuId: menuId }
  });
};

// 查询部门列表（排除节点）
export const listDeptExcludeChild = (deptId: string | number): AxiosPromise<DeptVO[]> => {
  return request({
    url: '/system/dept/list/exclude/' + deptId,
    method: 'get'
  });
};

// 查询部门详细
export const getDept = (deptId: string | number): AxiosPromise<DeptVO> => {
  return request({
    url: '/system/dept/' + deptId,
    method: 'get'
  });
};

// 查询部门下拉树结构
export const treeselect = (): AxiosPromise<DeptVO[]> => {
  return request({
    url: '/system/dept/treeselect',
    method: 'get'
  });
};

// 新增部门
export const addDept = (data: DeptForm) => {
  return request({
    url: '/system/dept',
    method: 'post',
    data: data
  });
};

// 修改部门
export const updateDept = (data: DeptForm) => {
  return request({
    url: '/system/dept',
    method: 'put',
    data: data
  });
};

// 删除部门
export const delDept = (deptId: number | string) => {
  return request({
    url: '/system/dept/' + deptId,
    method: 'delete'
  });
};

// 设置部门负责人
export const setDepartManager = (deptId: number | string, managerId: number | string) => {
  return request({
    url: '/sys/dept/setDepartManager',
    method: 'post',
    data: { deptId, managerId }
  });
};

// 设置部门负责人
export const setLeaderId = (subCompanyId: number | string, leaderId: number | string) => {
  return request({
    url: '/sys/subcompany/setLeaderId',
    method: 'post',
    data: { subCompanyId, leaderId }
  });
};

// 启用/停用部门
export const enableDept = (id: number | string, enable: boolean, type: number | string) => {
  return request({
    url: '/sys/dept/enable',
    method: 'post',
    data: { id, enable, type }
  });
};
