import request from '@/utils/request'

// 获取充电机ID
export function getChargeCode() {
  return request({
    url: '/device/getChargeCode',
    method: 'get'
  })
}
// 充电记录列表
export function chargeList(data) {
  return request({
    url: '/charge/list',
    method: 'post',
    data
  })
}
// 充电记录导出
export function chargeExport(data) {
  return request({
    url: '/charge/export',
    method: 'post',
    data
  })
}
// 换电记录列表
export function swapList(data) {
  return request({
    url: '/swapRecord/list',
    method: 'post',
    data
  })
}
// 换电记录详情
export function swapRecordDetail(data) {
  return request({
    url: '/swapRecord/getInfo',
    method: 'post',
    data
  })
}
// 换电记录导出
export function swapExport(data) {
  return request({
    url: '/swapRecord/export',
    method: 'post',
    data
  })
}
// 告警记录列表
export function alarmList(data) {
  return request({
    url: '/alarm/list',
    method: 'post',
    data
  })
}
// 当前告警列表
export function getrealList(data) {
  return request({
    url: '/alarm/realList',
    method: 'post',
    data
  })
}
//消防调仓
export function FireChangestorage(data) {
  return request({
    url: '/device/fireProtection',
    method: 'post',
    data
  })
}
// 告警记录导出
export function alarmExport(data) {
  return request({
    url: '/alarm/export',
    method: 'post',
    data
  })
}
// 处理告警
export function alarmDispose(data) {
  return request({
    url: '/alarm/dispose',
    method: 'post',
    data
  })
}
//导出结果
export function RecordFile(Fileurl,fileName){
  return request({
    url: Fileurl,
    method: 'get',
    responseType: 'blob',
  }).then(data=>{
    console.log("RecordFile then", data)
    if (!data) return alert('文件下载失败');
    // let fileName = '统计表计';
    if (typeof window.navigator.msSaveBlob !== 'undefined') {
        // window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx');
        window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName);
    } else {
        let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }));
        let link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', fileName);
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); //下载完成移除元素
        window.URL.revokeObjectURL(url); //释放掉blob对象
    }
  })
}
// 费率
export function getratelist(data) {
  return request({
    url: '/rate/list',
    method: 'post',
    data
  })
}
// 费率删除
export function getdeletecode(id) {
  return request({
    url: `/rate/delete?id=${id}`,
    method: 'get',
  })
}