import request from '@/utils/request';

// 列表
export async function getList(data) {
  const res = data.parentId
    ? await request.post(`/qms/line_point/page`)
    : await request.post('/qms/quality_work_order/page', data);
  console.log(res);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// 编辑
export async function update(data) {
  const res = await request.post(`/qms/quality_work_order/update`, 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/quality_work_order/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增合格证
export async function qualificationSave(data) {
  const res = await request.post(`/qms/qualityWorkOrderCertificate/save`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 删除
export async function removeItem(data) {
  const res = await request.delete('/qms/quality_work_order/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//列表
export async function parameterList(params) {
  const res = await request.get('/main/produceparam/page', {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
}

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

// 根据质检工单id获取清单列表
export async function queryQualityInventory(data) {
  const res = await request.post(
    '/qms/quality_work_order/query_quality_inventory',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
}

// 根据质检工单id获取质检样品列表
export async function queryQualitySamplContent(data) {
  const res = await request.post(
    '/qms/quality_work_order/query_quality_sampl_content',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
}
// 根据质检工单id获取方案内容
export async function queryQualityTempleContent(data) {
  const res = await request.post(
    '/qms/quality_work_order/query_quality_temple_content',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
}
// 仓库定义列表
export async function warehouseList(data) {
  const res = await request.post('/wms/warehouse/select/warehouseList', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
}

//更新合格证号
export async function updateCertificateNumber(data) {
  const res = await request.post(
    '/qms/quality_work_order/updateCertificateNumber',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
}

// 查询合格证
export async function qualityWorkOrderCertificate(params) {
  const res = await request.get('/qms/qualityWorkOrderCertificate/page', {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
}

// 判断是否是报工人
export async function verificationQualityInspector(id) {
  const res = await request.post(
    `/qms/quality_work_order/verificationQualityInspector/${id}`
  );

  return res.data.code;
}
