import request from '@/utils/request'

export function listArea(query) {
  return request({ url: '/warehouse/area/list', method: 'get', params: query })
}

export function getArea(id) {
  return request({ url: '/warehouse/area/' + id, method: 'get' })
}

export function addArea(data) {
  return request({ url: '/warehouse/area', method: 'post', data })
}

export function updateArea(data) {
  return request({ url: '/warehouse/area', method: 'put', data })
}

export function delArea(id) {
  return request({ url: '/warehouse/area/' + id, method: 'delete' })
}

export function optionselectArea() {
  return request({ url: '/warehouse/area/optionselect', method: 'get' }).then(response => {
    response.data = (response.data || []).sort((a, b) => {
      const first = a.areaName || a.areaCode || ''
      const second = b.areaName || b.areaCode || ''
      return first.localeCompare(second, 'zh-Hans-CN', { numeric: true })
    })
    return response
  })
}
