import request from '@/utils/request';

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

//保存
export async function saveData(data) {
  const res = await request.post(`/qms/sample/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 列表
export async function getSampleQWorkOrderIdPage(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(`/qms/sample/getSampleQWorkOrderId?` + par, {});
  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(`/qms/sample/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function disposeSubmit(data) {
  const res = await request.post(`/qms/sample/dispose`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 列表
export async function getSampleSmallWhole(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(
    `/qms/qualitysample/getSampleSmallWhole?` + par,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getQualitySampleList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(`/qms/qualitysample/page?` + par, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//删除
export async function removeItem(data) {
  const res = await request.delete('/qms/sample/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

// 样品删除
export async function removeSample(data) {
  const res = await request.delete('/qms/qualityinventory/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getWarehouseList(data) {
  const res = await request.post(`/wms/warehouse/select/warehouseList`, {
    params: { status: 1 }
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
