import request from '@/utils/request';

/**
 * 不合格品台账列表
 */
export async function getList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(`/qms/unqualifiedproducts/page?` + par, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 不合格品台账列表详情
 */
export async function getDetail(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(
    `/qms/unqualifiedproductsdetail/page?` + par,
    {}
  );
  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(`/qms/unqualifiedproducts/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//修改
export async function updateData(data) {
  const res = await request.put('/qms/unqualifiedproducts/update', data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//不合格品处置
export async function dispose(data) {
  const res = await request.post('/qms/unqualifiedproducts/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('/qms/unqualifiedproducts/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('/qms/unqualifiedproductsdetail/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 返工返修台账
 */
export async function getReworkList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmsreturnrepairwork/page?' + par);
  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('/qms/qmsreturnrepairwork/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) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmstrialproducts/page?' + par);
  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('/qms/qmstrialproducts/delete', { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 报废品台账
 */
export async function scrapProducts(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmsscrapproducts/page?' + par);
  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('/qms/qmsscrapproducts/delete', { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 详情页面

export async function getById(id) {
  const res = await request.get(`/qms/unqualifiedproducts/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 不良品处置
export async function disposeApi(data) {
  const res = await request.post('/qms/unqualifiedproducts/dispose', data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/* 消耗品台账
 */
export async function getConsumeproductsList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmsconsumeproducts/page?' + par);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/* 退货品台账
 */
export async function getReturngoodsList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmsreturngoods/page?' + par);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/* 让步接收
 */
export async function getConcessionacceptanceList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmsconcessionacceptance/page?' + par);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/* 降级使用
 */
export async function getDowngradeuseList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/qmsdowngradeuse/page?' + par);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/* 留样
 */
export async function getKeepsampleList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get('/qms/keepsample/page?' + par);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取回流工序
export async function refluxTask(data) {
  const res = await request.post('/mes/workorder/refluxTask', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
