import request from '@/utils/request'
import { upcloud_base_wh_inbound, upcloud_base_wh } from '@/config/serviceSettings'
const baseUrl = '/api/upcloud-base-wh-dev-mysql-eistest'
// export function getContainerLocationByContainerNoAndPalletNo(params) {
//   return request({
//     // url: 'mapi/eis/containerMonitoring',
//     url: baseUrl + '/master/containerLocation/get-containerLocation-containerNoAndPalletNo',
//     method: 'get',
//     params: params
//     // params: params
//   })
// }

export function downloadALL(data, callBack, param) {
  let params = param
  let xhr = new XMLHttpRequest()
  // console.log(xhr)
  const ids = data.ids
  const token = sessionStorage.getItem('token')

  xhr.open(
    'get',
    upcloud_base_wh_inbound +
      '/supervisionCodeXml/exportXmlAll?supervisionType=' +
      data.supervisionType +
      '&warehouseId=' +
      data.warehouseId +
      '&cargoOwnerId=' +
      data.cargoOwnerId +
      '&access_token+' +
      token +
      '&status=' +
      data.status,
    true
  )
  xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8')
  xhr.setRequestHeader('Authorization', 'Bearer ' + token)
  // xhr.send("a=3&b=4");

  xhr.responseType = 'blob'
  xhr.onload = function(e) {
    if (this.status == 200) {
      if (navigator.msSaveBlob) {
        return navigator.msSaveBlob(this.response, params.originalName ? params.originalName : '错误提示文档.xlsx')
      }
      let blob = this.response
      console.log(blob)
      let a = document.createElement('a')
      let url = window.URL.createObjectURL(blob)
      a.href = url
      //获取后端文件名称
      let fileName = decodeURI(xhr.getResponseHeader('content-disposition'))
      console.log(fileName)
      if (fileName == '数据为空.zip') {
        callBack(false,fileName)
      } else {
        //截取=字符串后面的内容
        let str = fileName.substring(21, fileName.length)
        // let utfStr = decodeURI(escape(str))     //是ISO_8859_1格式->改成utf-8
        a.download = fileName
        a.click()
        window.URL.revokeObjectURL(url)
        downloadALL(data, callBack, param)
      }
    }
  }
  //参数是json格式
  xhr.send(JSON.stringify(params))
}
// 创建监管码待导出任务：
// /supervisionCode/createSupervisionTask
export function createSupervisionTask(params) {
  return request({
    // url: 'mapi/eis/containerMonitoring',
    url: upcloud_base_wh_inbound + '/supervisionCode/createSupervisionTask',
    method: 'get',
    //   data: params
    params: params
  })
}
export function add(params) {
  return request({
    // url: 'mapi/eis/containerMonitoring',
    url: baseUrl + '/eisWhArea/save-storeArea',
    method: 'post',
    data: params
    // params: params
  })
}

// stationupdate
export function update(params) {
  return request({
    // url: 'mapi/eis/containerMonitoring',
    url: baseUrl + '/eisWhArea/update-storeArea',
    method: 'post',
    data: params
    // params: params
  })
}

//   /eisStationService/station/delete

export function deletes(params) {
  return request({
    // url: 'mapi/eis/containerMonitoring',
    url: baseUrl + '/eisWhArea/del-storeArea',
    method: 'get',
    //   data: params,
    params: params
  })
}
