import request from '@/utils/request';


/**
 * 不合格品台账列表
 */
export async function getList(data) {
  const res = await request.post('/mes/unqualified_products/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 不合格品台账列表详情
 */
export async function getDetail(data) {
  const res = await request.get('/mes/unqualified_products_detail/query/' + data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//不合格品新建/修改
export async function unqualifiedProductsAdd(data) {
  const res = await request.post('/mes/unqualified_products/' + (data.id ? 'update' : 'add'), data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//不合格品处置
export async function dispose(data) {
  const res = await request.post('mes/unqualified_products_detail/dispose', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 删除
export async function deleteUnacceptedProduct(data) {
  const res = await request.delete('/mes/unqualified_products/delete/' + data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
// 删除详情
export async function deleteUnacceptedProductDetail(data) {
  const res = await request.delete('/mes/unqualified_products_detail/delete', { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 返工返修台账
 */
export async function getReworkList(data) {
  const res = await request.post('/mes/return_repair_work/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 删除返工返修台账
export async function deleteReworkList(data) {
  const res = await request.delete('/mes/return_repair_work/delete' , {data});
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
// // 下达
// export async function releaseWorkOrder({ id, teamId }) {
//   const res = await request.get(
//     `/aps/workorder/releaseWorkOrder/${id}/${teamId}`
//   );
//   if (res.data.code == 0) {
//     return res.data.data;
//   }
//   return Promise.reject(new Error(res.data.message));
// }
/**
 * 返工返修转换
 */
 export async function transformation(data,type) {
  const res = await request.post('/mes/return_repair_work/transformation?type='+type, data);
    return res.data
  
}
/**
 * 试销品台账
 */
 export async function trialProducts(data) {
  const res = await request.post('/mes/trial_products/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 删除试销品台账
export async function deleteTrialProducts(data) {
  const res = await request.delete('/mes/trial_products/delete' , {data});
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 报废品台账
 */
 export async function scrapProducts(data) {
  const res = await request.post('/mes/scrap_products/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 删除报废品台账
export async function deleteScrapProducts(data) {
  const res = await request.delete('/mes/scrap_products/delete' , {data});
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}