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

//获取当前登录信息
export async function getLoginUser() {
  const data = await get(Vue.prototype.apiUrl + `/system/account/getLoginUser`);
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 获取基本信息
export async function getInfoById(id) {
  const data = await get(
    Vue.prototype.apiUrl + `/mes/workreport/getById/${id}`
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 获取仓库字典
export async function getByCode(code) {
  const res = await get(
    Vue.prototype.apiUrl + `/system/dict/getByCode/${code}`
  );
  if (res.code == 0) {
    return res.data;
  }
  return Promise.reject(res.data.message);
}

// 领料保存
export async function batchSave(data) {
  const res = await postJ(
    Vue.prototype.apiUrl + `/mes/pickorder/batchSave`,
    data,
    true
  );
  if (res.code == 0) {
    return res.data;
  }
  return Promise.reject(res.data.message);
}

// 获取工单信息
export async function getOrderById(id) {
  const data = await get(Vue.prototype.apiUrl + `/mes/workorder/getById/${id}`);
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 获取工单数量
export async function getCount(params) {
  const data = await getJ(
    Vue.prototype.apiUrl + `/mes/workreport/count`,
    params
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 获取工序列表
export async function getTaskListById(id) {
  const data = await get(
    Vue.prototype.apiUrl + `/main/produceversion/getTaskListById/${id}`
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}
//获取设备
export async function getDeviceByTaskId(id) {
  const data = await get(
    Vue.prototype.apiUrl + `/main/producetask/getDeviceByTaskId/${id}/4`
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

//根据生产版本ID查询bom子项列表
export async function bomSubListByVersionId(params) {
  const data = await get(
    Vue.prototype.apiUrl +
      `/main/produceversion/resource/bomSubListByVersionId/${params.versionId}/${params.taskId}`
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}

// 获取批次号
export async function getBatchNumber(params) {
  const data = await getJ(
    Vue.prototype.apiUrl + `/sap/sync/realTimeStorage`,
    params
  );
  if (data.code == 0) {
    return data.data;
  }
  return Promise.reject(data.message);
}
