import request from '@/utils/request';

// 一键报工，新增或修改填写表单类型的执行记录，并修改状态为已执行
export async function saveOrUpdateAndSubmit(body) {
  const res = await request.post(
    '/mes/producetaskrulerecord/saveOrUpdateAndSubmit',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 缓存，新增或修改填写表单类型的执行记录
export async function saveOrUpdate(body) {
  const res = await request.post(
    '/mes/producetaskrulerecord/saveOrUpdate',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 一键报工，新增或修改填写表单类型的执行记录，并修改状态为已执行
export async function logicDelete(id) {
  const res = await request.delete(
    '/mes/producetaskrulerecord/logicDeleteById/' + id
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getById(id) {
  const res = await request.get('/mes/producetaskrulerecord/getById/' + id);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /mes/producetaskrulerecordpickdetail/queryListByWorkOrderId post
export async function queryListByWorkOrderId(body) {
  const res = await request.post(
    '/mes/producetaskrulerecordpickdetail/queryListByWorkOrderId',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /main/categoryparam/getMaterialQuotaInfo/{bomCategoryId}/{produceTaskId}
export async function getMaterialQuotaInfo(bomCategoryId, produceTaskId) {
  const res = await request.get(
    `/main/categoryparam/getMaterialQuotaInfo/${bomCategoryId}/${produceTaskId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /main/category/getCategoryAndLevelByCategoryId/{categoryId}
export async function getCategoryAndLevelByCategoryId(categoryId) {
  const res = await request.get(
    `/main/category/getCategoryAndLevelByCategoryId/${categoryId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// POST /main/producerouting/taskinstance/getAllList
export async function getAllRoutingTaskList(params) {
  const res = await request.get(
    '/main/producerouting/taskinstance/getAllList',
    { params }
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//  /mes/producetaskrulerecordpickdetail/getPickAndFeed 参数：workOrderId produceTaskId或produceTaskInstanceId
export async function getPickAndFeed(body) {
  const res = await request.post(
    '/mes/producetaskrulerecordpickdetail/getPickAndFeed',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /mes/producetaskrulerecord/reSubmit 重新一键报工
export async function resetSubmit(body) {
  const res = await request.post('/mes/producetaskrulerecord/reSubmit', body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /mes/workorder/inStoreageRecord
export async function inStoreageRecord(body) {
  const res = await request.post('/mes/workorder/inStoreageRecord', body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /mes/workorder/listProduceTaskAndFormNum
export async function listProduceTaskAndFormNum(body) {
  const res = await request.post(
    '/mes/workorder/listProduceTaskAndFormNum',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
