import request from "@/utils/request";

// 创建出货
export function createbox(data) {
  return request({
    url: "/shipment/box/create",
    method: "post",
    data: data,
  });
}

// 更新出货
export function updatebox(data) {
  return request({
    url: "/shipment/box/update",
    method: "put",
    data: data,
  });
}

// 删除出货
export function deletebox(id) {
  return request({
    url: "/shipment/box/delete?id=" + id,
    method: "delete",
  });
}

// 获得出货
export function getbox(id) {
  return request({
    url: "/shipment/box/get?id=" + id,
    method: "get",
  });
}

// 获得出货分页
export function getboxPage(query) {
  return request({
    url: "/shipment/box/page",
    method: "get",
    params: query,
  });
}

// 导出出货 Excel
export function exportboxExcel(query) {
  return request({
    url: "/shipment/box/export-excel",
    method: "get",
    params: query,
    timeout: 20 * 60000,
    responseType: "blob",
  });
}

// 导出预装单-异步
export function exportPreloadGoodsList(query) {
    return request({
        url: "/ecw/box-preload-goods/downloadPreloadGoodsList",
        method: "get",
        params: query
    });
}

// 创建费用登记
export function createCost(data) {
  if (data.id) {
    return request({
      url: "/ecw/box-cost/update",
      method: "put",
      data,
    });
  }

  return request({
    url: "/ecw/box-cost/create",
    method: "post",
    data,
  });
}

// 删除费用登记
export function deleteCost(id) {
  return request({
    url: `/ecw/box-cost/delete?id=${id}`,
    method: "delete",
  });
}

// 审核详情
export function approvalDetail(data) {
  return request({
    url: "/ecw/box-approval/approvalDetail",
    method: "post",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    data: jsonToFormData(data),
  });
}

// 出货操作日志列表
export function getLogList(params) {
  return request({
    url: "/ecw/box-op-log/list",
    method: "get",
    params,
  });
}

// 获得费用登记列表
export function getCostList(params) {
  return request({
    url: "/ecw/box-cost/list",
    method: "get",
    params,
  });
}

// 获得出货异常记录列表
export function getAbnormalList(params) {
  return request({
    url: "/ecw/box-abnormal/list",
    method: "get",
    params,
  });
}

// 获得制作提货单列表
export function getMakeBillList(params) {
  return request({
    url: "/shipment/make-bill-of-lading/getMakeLadingBillList",
    method: "get",
    params,
  });
}

// 制作提货单
export function makeBillService(params) {
  return request({
    url: "/shipment/make-bill-of-lading/make",
    method: "get",
    params,
  });
}

// 创建制作提货单
export function createBillService(data) {
  return request({
    url: "/shipment/make-bill-of-lading/create",
    method: "post",
    data,
  });
}

// 取消制作提货单审核
export function cancelBillService(id) {
  return request({
    url: `/shipment/make-bill-of-lading/cancel?id=${id}`,
    method: "delete",
  });
}

// 下载提货单
export function downloadBillService(params) {
  return request({
    url: "/shipment/make-bill-of-lading/download",
    method: "get",
    params,
  });
}

// 更新制作提货单
export function updateBillService(data) {
  return request({
    url: "/shipment/make-bill-of-lading/update",
    method: "put",
    data,
  });
}

// 删除制作提货单
export function deleteBillService(id) {
  return request({
    url: `/shipment/make-bill-of-lading/delete?id=${id}`,
    method: "delete",
  });
}

// 获得制作提货单
export function getBillService(params) {
  return request({
    url: "/shipment/make-bill-of-lading/get",
    method: "get",
    params,
  });
}

// 打包下载提货单
export function zipDownload(params) {
  return request({
    url: "/shipment/make-bill-of-lading/zipDownload",
    method: "get",
    timeout: 120000,
    params,
  });
}

/**
 * formData数据
 *
 * @param {*} params
 * @return {*}
 */
function jsonToFormData(params) {
  const formData = new FormData();
  for (const [key, value] of Object.entries(params)) {
    formData.append(key, value);
  }
  return formData;
}

// 创建制作提货单
export function getNoticeList(data) {
  return request({
    url: "/shipment/box/noticeList",
    method: "post",
    data,
  });
}

// 空运出货提示
export function getAirNoticeList(data) {
  return request({
    url: "/shipment/box/airNoticeList",
    method: "post",
    data,
  });
}

/**
 * 根据订单ID下载提货单
 *
 * @export
 * @param {*} orderId
 * @return {*}
 */
export function downloadByOrderId(orderId) {
  return request({
    url: "/shipment/make-bill-of-lading/downloadByOrderId",
    method: "get",
    params: { orderId },
    /* responseType: "arraybuffer", */
  });
}

// 获得出货审核
export function getBoxApproval(params) {
  return request({
    url: "/ecw/box-approval/get",
    method: "get",
    params,
  });
}

// 获得制作提货单（审核中调用）
export function getBillOfLandingInProcessing(params) {
  return request({
    url: "/shipment/make-bill-of-lading/getInProcessing",
    method: "get",
    params,
  });
}
// 下载agent list文件
export function downloadAgentListFiles(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadAgentListFiles",
    method: "get",
    timeout: 3*60*1000,
    params,
  });
}

// 下载son cap文件
export function downloadSoncapFiles(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadSoncapFiles",
    method: "get",
    timeout: 3*60*1000,
    params,
  });
}

// 下载报关单
export function downloadCustomFiles(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadCustomFiles",
    method: "get",
    timeout: 3*60*1000,
    params,
  });
}

// 下载已装单
export function downloadLoadGoodsList(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadLoadGoodsList",
    timeout: 3*60*1000,
    method: "get",
    params,
  });
}

// 下载预装单
export function downloadPreloadGoodsList(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadPreloadGoodsList",
    responseType: "blob",
    timeout: 3*60*1000,
    method: "get",
    params,
  });
}

// 下载应收汇总
export function downloadReceivableList(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadReceivableList",
    timeout: 3*60*1000,
    method: "get",
    params,
  });
}

// 空运的应收汇总下载
export function downloadAirReceivableList(params) {
  return request({
    url: "/ecw/box-preload-goods/downloadAirBillReceivable",
    method: "get",
    params,
  });
}

// 下载提单copy
export function downloadLadingCopy(params) {
  return request({
    url: "/ecw/box-lading-copy/downloadLadingCopy",
    method: "get",
    timeout: 3*60*1000,
    params,
  });
}

// 更新异常订单状态
export function updateAbnormalOrder(data) {
  return request({
    url: "/shipment/box/updateAbnormalOrder",
    method: "post",
    data,
  });
}

// 更新提单URL
export function updateUrl(data) {
  return request({
    url: "/shipment/make-bill-of-lading/updateUrl",
    method: "put",
    data,
  });
}

export function dealCustomsSplitNotify(notifyId){
  return request({
    url: `/shipment/box/dealCustomsSplitNotify?notifyId=${notifyId}`,
    method: "get",
  })
}

// 自编号报表分页
export function boxSettlementPage(params) {
  return request({
    url: "/shipment/box/pageSettlement",
    method: "get",
    params,
  });
}

// 导出自编号汇总excel
export function exportSettlementExcel(params) {
  return request({
    url: "/shipment/box/export-shipment-summary",
    method: "get",
    params,
  });
}
