import request from '@/utils/request';

// 保存or更新
export async function save(data) {
  let fn = data.id ? request.put : request.post;
  const res = await fn(`/ehs/invhazard/` + (data.id ? 'update' : 'save'), data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 整改
export async function rectify(data) {
  const res = await request.put(`/ehs/invhazard/rectify`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 验收
export async function accept(data) {
  const res = await request.put(`/ehs/invhazard/accept`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 列表
 */
export async function getList(params) {
  const res = await request.get('/ehs/invhazard/page', { params });
  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(`/ehs/invhazard/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//模板删除
export async function remove(data) {
  const res = await request.delete(`/ehs/invhazard/delete`, {
    data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// // 校验当前登录人是不是验收人
export async function checkAcceptor(id) {
  const res = await request.get(`/ehs/invhazard/checkAcceptor/${id}`);
  return res.data.data;
}
// // 校验当前登录人是不是整改人
export async function checkRectifier(id) {
  const res = await request.get(`/ehs/invhazard/checkRectifier/${id}`);
  return res.data.data;
}
