import request, { axios } from "@/utils/request";
// import request from "@/utils/request";
import qs from "qs";
import { baseUrl } from "../../../config/baseUrl";
import {
  upcloud_base_wh_inbound,
  upcloud_base_common,
  upcloud_base_wh,
  upcloud_base_strategy,
  upcloud_base_chain,
  SERVICE_DATA_API_BASE,
} from "@/config/serviceSettings";

export const api = {
  addItem: upcloud_base_wh_inbound + "/rcvHeaders/v1.0/addWithRelated",
  queryContainerList: upcloud_base_wh_inbound + "/common/getContainerPage",
  getRecommendArea: upcloud_base_wh_inbound + "/rcvLines/v1.0/recommendArea",
  getItem: upcloud_base_wh_inbound + "/baseCargoOwnerMst/v1.0/pageCargoOwnerScopeList",
  findWithRelatedTemp: upcloud_base_wh_inbound + "/rcvHeaders/v1.0/findWithRelatedTempById",
  addWithRelatedTemp: upcloud_base_wh_inbound + "/rcvHeaders/v1.0/addWithRelatedTemp",
  getRcvItemLotNum: upcloud_base_wh_inbound + "/rcvHeaders/v1.0/getRcvItemLotNum",
};

export function addItem(parameter) {
  return request({
    method: "post",
    url: api.addItem,
    data: parameter,
  });
}

export let arrivalModeList = [];
getArrivalModeList();
export function getArrivalModeList(parameter) {
  return request({
    method: "post",
    url: upcloud_base_common + "/dict/listbytype?dicttypeCodes=po_billh_arrivalmode",
  }).then((res) => {
    arrivalModeList = res.data || [];
    return res;
  });
}

export function getRecommendArea(parameter) {
  return request({
    method: "post",
    url: api.getRecommendArea,
    data: parameter,
  });
}

export function getItem(parameter) {
  return request({
    method: "post",
    url: api.getItem,
    data: parameter,
  });
}

// 180Day
export function getExpiredDaysAlertNoIntercept(id) {
  return request({
    method: "get",
    url: upcloud_base_strategy + "/registry/by-code?regCode=expiredDaysAlertNoIntercept&warehouseId=" + id,
  });
}

// 90Day
export function getExpiredDaysAlertAndIntercept(id) {
  return request({
    method: "get",
    url: upcloud_base_strategy + "/registry/by-code?regCode=expiredDaysAlertAndIntercept&warehouseId=" + id,
  });
}

// 暂存
export function addWithRelatedTemp(parameter) {
  return request({
    method: "post",
    url: api.addWithRelatedTemp,
    data: parameter,
  });
}
//提取暂存订单
export function findWithRelatedTemp(parameter) {
  return request({
    method: "get",
    url: api.findWithRelatedTemp,
    // contentType: "x-www-form-urlencoded",
    params: parameter,
  });
}

// 历史批号
export function getRcvItemLotNum(parameter) {
  return request({
    method: "post",
    url: api.getRcvItemLotNum,
    data: parameter,
  });
}

// 查询堆垛
export function getStockCount(parameter) {
  return request({
    method: "post",
    url: SERVICE_DATA_API_BASE + "/search",
    data: {
      num: "212",
      params: parameter,
    },
  });
}

// 验证货主 供应商资质效期
export function postVaildate(parameter) {
  return request({
    method: "post",
    url: upcloud_base_chain + "/common/v1.0/license/vaildate",
    data: parameter,
  });
}
// 字典
export function getDicts(parameter) {
  return request({
    method: "post",
    url: upcloud_base_common + "/dict/listbytype",
    params: parameter,
    replaceFields: {
      value: "dictCode",
      label: "dictName",
    },
  });
}

// 容器占用
export function getContainers(parameter) {
  return request({
    method: "post",
    url: upcloud_base_wh + "/container/getPageList",
    data: parameter,
  });
}

// 清理过期订单
export function postAsnClear(parameter) {
  return request({
    method: "post",
    url: baseUrl + "/asn/v1.0/clear",
    data: parameter,
  });
}

// 获取库别-字典
export const getAreaCategoryCodeOptions = () => {
  return axios.post(upcloud_base_common + "/dict/listbytype?dicttypeCodes=wms_storeroom");
};
// 获取库别-策略
export const getAreaCategoryCode = (params) => {
  return axios.get(upcloud_base_strategy + "/strategy/v1/execute", { params });
};
// 获取入库结论-策略
export const getStockStatusOptions = (params) => {
  return axios.get(upcloud_base_strategy + "/strategy/v1/execute", { params });
};

// /dict/listbytype?dicttypeCodes=IS_AGV

export const IS_AGV = () => {
  return axios.post(upcloud_base_common + "/dict/listbytype?dicttypeCodes=IS_AGV");
};

// remoteUrl: { url: upcloud_base_strategy + "/strategy/v1/execute", method: "get" },

export function strategyExecute(data) {
  return request({
    method: "get",
    url: upcloud_base_strategy + "/strategy/v1/execute",
    params: data,
  });
}
