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


//获取组织架构

export function getTreelist(queryParams:any) {
  return request({
    url: '/system/organization/getOrgTree',
    method: 'POST',
    params: queryParams
  });
}
//新增企业或部门

export function addTreelist(queryParams:any) {
  return request({
    url: '/system/organization/addOrg',
    method: 'POST',
    data: queryParams
  });
}
// 修改企业部门

export function updataTreelist(queryParams:any) {
  return request({
    url: '/system/organization/updateById',
    method: 'POST',
    data: queryParams
  });
}
//删除企业 
export function delTreelist(queryParams:any) {
  return request({
    url: '/system/organization/deleteById',
    method: 'POST',
    params: queryParams
  });
}
//获取部门信息
export function gettableData(queryParams:any) {
  return request({
    url: '/system/organization/getOrganizationById',
    method: 'POST',
    params: queryParams
  });
}
//部门是否有效
export function deptIsVaild(queryParams:any) {
  return request({
    url: '/system/organization/setIsValid',
    method: 'POST',
    params: queryParams
  });
}

//修改部门信息
export function reviseDepartment(queryParams:any) {
  return request({
    url: '/system/organization/updateById',
    method: 'POST',
    data: queryParams
  });
}

/**
 * 部门树形表格
 *
 * @param queryParams
 */
export function listDepartments(queryParams?: DeptQuery): AxiosPromise<Dept[]> {
  return request({
    url: '/api/v1/dept',
    method: 'get',
    params: queryParams
  });
}

/**
 * 部门下拉列表
 */
export function listDeptOptions(): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/v1/dept/options',
    method: 'get'
  });
}

/**
 * 获取部门详情
 *
 * @param id
 */
export function getDeptForm(id: string): AxiosPromise<DeptForm> {
  return request({
    url: '/api/v1/dept/' + id + '/form',
    method: 'get'
  });
}

/**
 * 新增部门
 *
 * @param data
 */
export function addDept(data: DeptForm) {
  return request({
    url: '/api/v1/dept',
    method: 'post',
    data: data
  });
}

/**
 *  修改部门
 *
 * @param id
 * @param data
 */
export function updateDept(id: string, data: DeptForm) {
  return request({
    url: '/api/v1/dept/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 删除部门
 *
 * @param ids
 */
export function deleteDept(ids: string) {
  return request({
    url: '/api/v1/dept/' + ids,
    method: 'delete'
  });
}
