import request from '@/utils/request';

// 分页
export async function getPage(data) {
  const res = await request.get('/eam/repairrequest/page', { params: data });
  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('/eam/repairrequest/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.put('/eam/repairrequest/update', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 详情
export async function getRepairById(id) {
  const res = await request.get(`/eam/repairrequest/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 详情(新)
export async function getRepairInfoById(id) {
  const res = await request.get(`/eam/repairrequest/getInfoById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 撤销
export async function removeRequest(id) {
  const res = await request.get(`/eam/repairrequest/delete/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 委外
export async function addOutsource(data) {
  const res = await request.post('/eam/outsourceworkorder/addOrEdit', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 委外工单列表
export async function outsourceList(data) {
  const res = await request.post('/eam/outsourceworkorder/getList', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取委外工单详情
export async function getOutsourceInfo(id) {
  const res = await request.get(`/eam/outsourceworkorder/info/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 委外工单驳回或验收
export async function checkOrBack(data) {
  const res = await request.post('/eam/outsourceworkorder/checkOrBack', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 维修计划新增
export async function savePlanRepair(data) {
  const res = await request.post('/eam/plan/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取维修计划列表数据
export async function getPlanList(data) {
  const res = await request.get('/eam/plan/page', { params: data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 维修计划撤销
export async function removePlan(data) {
  const res = await request.delete(`/eam/plan/delete`, { data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
