import { postJ, post, get } from "@/utils/request";
import Vue from "vue";

// 报工固定端口
function getUrl() {
  //  // #ifdef APP-PLUS
  //   return "http://192.168.3.190:9090" // Vue.prototype.apiUrl
  // // #endif
  // // #ifdef H5
  // return '/handleReport'
  // // #endif

  // APP“服务器设置”界面设定的：协议、主机地址、端口
  const apiInfo = uni.getStorageSync("apiInfo");

  // 生产报工对接601-mes后端：与必品云后端同主机，用9090端口。
  return apiInfo.protocal ? `${apiInfo.protocal}${apiInfo.hostname}:9090` : '/api'
  // const apiInfo = uni.getStorageSync("apiInfo");

  // Vue.prototype.apiWebUrl = `${apiInfo.protocal}${apiWWInfo.hostname}:${apiInfo.port}/api`;
}

// 获取工单基本信息
export async function getOrderInfo(orderCode) {
  const data = await get(
    getUrl() + `/order/getOrderInfo/${orderCode}`, null, true,
  );

  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 查询生产订单工艺路线信息 工序信息
export async function getProcessRoute(orderId) {
  const data = await get(
    getUrl() + `/orderVornr/getProcessRoute/${orderId}`, null, true,
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 查询生产订单报工明细
export async function getReportInfo(orderCode, loading = true) {
  const data = await get(
    getUrl() + `/feedRecord/getReportInfo/${orderCode}`, null, loading,
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 报工
export async function report(params) {
  const data = await postJ(
    getUrl() + `/feedRecord/report`, params, true,
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 不合格品类型字典
export async function getDict(type) {
  const data = await get(
    getUrl() + `/dict/getDict?type=${type}`
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}


// 根据工序id 查询 报工信息
export async function getReportByVornrId(vornrId, loading = true) {
  const data = await get(
    getUrl() + `/feedRecord/getReportByVornrId/${vornrId}`, null, true
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 查询生产订单101产品收货明细
export async function getProductReciverInfoOne(orderId) {
  const data = await get(
    getUrl() + `/oneReciver/getProductReciverInfo/${orderId}`, null, true
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}


// 查询生产订单531产品收货明细
export async function getProductReciverInfoFive(orderId) {
  const data = await get(
    getUrl() + `/fiveReciver/getProductReciverInfo/${orderId}`, null, true
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 查询生产订单投料明细
export async function getFeedInfo(orderId) {
  const data = await get(
    getUrl() + `/feedRecord/getFeedInfo/${orderId}`, null, true
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 查询生产订单bom组件数据
export async function getBomInfo(orderId) {
  const data = await get(
    getUrl() + `/bom/getBomInfo/${orderId}`, null, true
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 冲销
export async function chargeOff(params) {
  const data = await postJ(
    getUrl() + `/feedRecord/writeOff`, params, true
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 查询报工权限
export async function getPostingDate() {
  const data = await get(
    getUrl() + `/postingDate/getPostingDate`
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}





