import request from "@/utils/request";

// booking
export function booking(data) {
  return request({
    url: "/ecw/box-book-sea/create",
    method: "post",
    data,
  });
}

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

/*****************************  预装 **********************************/

/**
 * 获得已预装部分列表
 *
 * @export
 * @param {*} params
 * @return {*}
 */
export function secGoodsList(params) {
  return request({
    url: "/ecw/box-preload-goods/secGoodsList",
    method: "get",
    params,
  });
}

/**
 * 获得订单预装分页
 *
 * @export
 * @param {*} params
 * @return {*}
 */
export function preloadPage(params) {
  return request({
    url: "/ecw/order/preloadPage",
    method: "get",
    params,
  });
}

/**
 * 创建预装部分
 *
 * @export
 * @param {*} params
 * @return {*}
 */
export function createSection(data) {
  return request({
    url: "/ecw/box-preload-section/create",
    method: "post",
    data,
  });
}

/**
 * 删除预装部分
 *
 * @export
 * @param {*} params
 * @return {*}
 */
export function deleteSection(id) {
  return request({
    url: "/ecw/box-preload-goods/deleteSection?id=" + id,
    method: "delete",
  });
}

/**
 * 删除预装货物
 *
 * @export
 * @param {*} params
 * @return {*}
 */
export function deleteGoods(id) {
  return request({
    url: "/ecw/box-preload-goods/delete?ids=" + id.join(","),
    method: "delete",
  });
}

/**
 * 预装
 *
 * @export
 * @param {*} params
 * @return {*}
 */
export function createGoods(data) {
  return request({
    url: "/ecw/box-preload-goods/create",
    method: "post",
    data,
  });
}

/**
 * 服务提示消息回调
 *
 * @export
 * @param {*} result
 * @param {*} _vue
 * @return {*}
 */
export function serviceMsg(result, _vue) {
  return new Promise((resolve, reject) => {
    const { code, msg } = result;
    if (code === 0) {
      _vue.$message.success("提交成功");
      resolve();
    } else {
      _vue.$message.error(msg);
      reject();
    }
  });
}
