import request_9518 from '@/utils/request_9518'
import request from '@/utils/request'


import { exportExcelNew, downloadFile,exportZipFile, exportExcelData } from '@/utils/filedown'
import { getCurrentDateTime } from '@/utils'

export function GetOrderPager(data) {
  return request_9518({
    url: '/Order/GetOrderPager',
    method: 'post',
    data,
    timeout: 30 * 1000
  })
}

export function GetCounts(data) {
  return request_9518({
    url: '/Order/GetOrderQty',
    method: 'post',
    data,
    timeout: 30 * 1000
  })
}
export function Get(Id) {
  return request_9518({
    url: '/Order/Get',
    method: 'get',
    params: { Id }
  })
}

export function GetCustomerDraftOrder(Id) {
  return request_9518({
    url: '/Order/GetCustomerDraftOrder',
    method: 'get',
    params: { Id }
  })
}
export function ConfirmCustomerOrderReceipt(data) {
  return request_9518({
    url: '/GetMoreThanOneTicketMps/ConfirmCustomerOrderReceipt',
    method: 'post',
    data,
    timeout: 30 * 1000
  })
}
export function getMps(orderId, draftOrderId) {
  return request_9518({
    url: '/GetMoreThanOneTicketMps/get',
    method: 'get',
    params: { orderId, draftOrderId }
  })
}
export function BoxStatusOp(boxId, boxStatus) {
  return request_9518({
    url: '/GetMoreThanOneTicketMps/BoxStatusOp',
    method: 'get',
    params: { boxId, boxStatus }
  })
}
export function OutData(data) {
  const url = process.env.VUE_APP_9518_API + '/Order/OutData'
  return exportExcelNew(url, data, 'post')
}
export function CreateChannelOrder(orderId, channelId) {
  return request_9518({
    url: '/MpsChanelOrder/Post',
    method: 'get',
    params: { orderId, channelId }
  })
}

export function CreateMegerOrder(orderIds, channelId) {
  return request_9518({
    url: '/MpsChanelOrder/MergePost',
    method: 'post',
    data: { orderIds, channelId }
  })
}

export function _downloadSendReceipt(data) {
  downloadFile('http://wms.xingyunyi.cn/order/DownSendReceipt', data)
}
export function UpdateMpsOrder(data) {
  return request_9518({
    url: '/GetMoreThanOneTicketMps/UpdateMpsOrder',
    method: 'post',
    data
  })
}
export function InsPage(data) {
  return request_9518({
    url: '/HSCode/InsPage',
    method: 'post',
    timeout: 10 * 1000,
    data
  })
}
export function EUHSCodeUpdateSave(data) {
  return request_9518({
    url: '/HSCode/SaveEUHSCodeUpdate',
    method: 'post',
    timeout: 10 * 1000,
    data
  })
}

export function outMpsOrdermethod(data) {
  return request_9518({
    url: '/GetMoreThanOneTicketMps/OutMpsOrderData',
    method: 'post',
    timeout: 10 * 1000,
    responseType: 'blob',
    headers:{ 'Content-Type': 'application/json; application/octet-stream'},
    data
  })
  .then((res)=>{
    exportZipFile(res)
  })
}
export function ModifyCreateOrderChannelSave(data){
  return request_9518({
    url: '/GetMoreThanOneTicketMps/ModifyCreateOrderChannelId',
    method: 'post',
    timeout: 30 * 1000,
    data
  })
}
export function outMpsOrderTemplate(data) {
  return request_9518({
    url: '/MpsChanelOrder/OutOrderTemplate',
    method: 'post',
    timeout: 10 * 1000,
    responseType: 'blob',
    headers:{ 'Content-Type': 'application/json; application/octet-stream'},
    data
  })
  .then((res)=>{
    exportZipFile(res)
  })
}

/**
 * 更新单号与面单
 * @param {*} data
 * @returns
 */
export function UpdateImageAndTrakcing(data){
  return request({
    url: '/Order/UpdateImageAndTrakcing',
    method: 'post',
    timeout: 30 * 1000,
    data
  })
}

export function outOrderAndGoods(data) {
  return request({
    url: '/order/OutOrderAndGoods',
    method: 'post',
    timeout: 60 * 1000,
    responseType: 'blob',
    headers:{ 'Content-Type': 'application/json; application/octet-stream'},
    data
  })
  .then((res)=>{
    const fileName = getCurrentDateTime()
    exportExcelData(res, fileName)
  })
}
