import axios from '@/libs/api.request'

export const getPage = (parmas) => {
  return axios.request({
    url: 'api/v1/rbac/organization/page',
    params: parmas,
    method: 'get',
  })
}

export const editOrg = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/organization',
        method: 'PATCH',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const removeOrg = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/organization/delete/' + id,
        method: 'POST',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const addOrg = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/organization',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const getChilds = (pid) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/organization/childs/' + pid,
        method: 'GET',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const getOrgData = () => {
  return axios.request({
    url: 'cas/api/v1/get_org_data',
    method: 'get',
  })
}

export const getTreeSelectData = () => {
  return axios.request({
    url: 'api/v1/get_tree_select_data',
    method: 'get',
  })
}
