import request from '@/utils/request'

// 查询区域-省市区县列表
export function listArea(query) {
  return request({
    url: '/system/area/list',
    method: 'get',
    params: query
  })
}

// 查询区域-省市区县详细
export function getArea(areaId) {
  return request({
    url: '/system/area/' + areaId,
    method: 'get'
  })
}

// 新增区域-省市区县
export function addArea(data) {
  return request({
    url: '/system/area',
    method: 'post',
    data: data
  })
}

// 修改区域-省市区县
export function updateArea(data) {
  return request({
    url: '/system/area',
    method: 'put',
    data: data
  })
}

// 删除区域-省市区县
export function delArea(areaId) {
  return request({
    url: '/system/area/' + areaId,
    method: 'delete'
  })
}

/***下拉选择 */
export async function cascaderAreaList(parentId) {
  let query = { columns: 'id,full_name,parent_id,has_children', parentId };
  let res = await request.get('/system/area/list/tree', { params: query });
  return (res.rows || []).map(item => ({ ...item, leaf: !item.hasChildren }));
}
