import request from '@/utils/request'

// 获得地区树
export async function getAreaTree() {
  const res = await request.get('/eam/area/tree')
  if (res.data.code == 0) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.message))
}

// 获得子级地区
export async function getChildrenArea(id) {
  const res = await request.get('/system/area/get-children?id=' + id)
  if (res.data.code == 0) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.message))
}

// 根据ID列表获取地区
export async function getAreaListByIds(ids) {
  const res = await request.get('/system/area/get-by-ids?ids=' + ids)
  if (res.data.code == 0) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.message))
}

// 根据IP获取地区信息
export async function getAreaByIp(ip) {
  const res = await request.get('/eam/area/get-by-ip?ip=' + ip)
  if (res.data.code != '-1') {
    return res.data
  }
  return Promise.reject(new Error(res.data.message))
}
