/**
 * 设备管理接口
 */
import request from '@/utils/request'
import qs from 'qs'

// 设备查询
export function getDeviceList(params) {
  return request({
    url: 'device/list',
    method: 'get',
    params
  })
}
// 设备查询
export function getDeviceListAll(params) {
  return request({
    url: 'device/listAll',
    method: 'get',
    params
  })
}
// 业务类型
export function getBusinessType(params) {
  return request({
    url: '/dict/code/businessType',
    method: 'get',
    params
  })
}

// 设备类别
export function getDeviceType(params) {
  return request({
    url: 'device/type',
    method: 'get',
    params
  })
}

// 设备型号
export function getDeviceModel(deviceType) {
  return request({
    url: 'device/model',
    method: 'get',
    params: {
      deviceType: deviceType
    }
  })
}

// 添加设备
export function addDevice(params) {
  return request({
    url: 'device/add',
    method: 'post',
    params
  })
}
// 修改设备
export function updateDevice(params) {
  return request({
    url: 'device/update',
    method: 'post',
    params
  })
}
// 删除设备
export function delDevice(ids) {
  return request({
    url: 'device/delete',
    method: 'post',
    params: {
      ids: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
// 批量下发更新数据库指令
export function updateDB(ids) {
  return request({
    url: 'device/updateDB',
    method: 'post',
    params: {
      ids: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
// 批量导入
export function batchImportDevice(fileobj) {
  const param = new FormData()
  param.append('file', fileobj)
  return request({
    url: 'device/batchImport',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}
// 批量导出
export function batchExportDevice(params) {
  return request({
    url: 'device/batchExport',
    method: 'get',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}
