import request from '@/utils/request';

// 计划分页
export async function getPage(data) {
  const res = await request.get('/eam/planmaintenance/page', { params: data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 更新或保存
export async function saveOrUpdate(data) {
  const res = await request.post('/eam/planmaintenance/saveOrUpdate', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 详情
export async function getById(id) {
  const res = await request.get(`/eam/planmaintenance/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 详情(维修)
export async function getRepairInfoById(params) {
  const res = await request.get(`/eam/planmaintenance/getRepairInfoById`, {
    params
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 撤回
export async function revocation(id) {
  const res = await request.get(`/eam/planmaintenance/revocation/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 撤回（量具送检）
export async function revocationDelivery(id) {
  const res = await request.get(`/eam/plan/revocation/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询未派单设备数据
export async function getNotSendOrderList(planId) {
  const res = await request.get(
    `/eam/planmaintenance/getNotSendOrderList/${planId}`
  );
  if (res.data.code == 0) {
    return res.data?.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 派单
export async function sendOrder(data) {
  const res = await request.get(`/eam/planmaintenance/sendOrder`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data?.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 工单分页
export async function getWorkOrderPage(data) {
  const res = await request.get('/eam/workordermaintenance/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 详情
export async function getWordOrderDetail(workOrderId) {
  const res = await request.get(
    `/eam/workordermaintenance/maintenanceDetail/${workOrderId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 工单转派
export async function workOrderRotate(data) {
  const res = await request.get('/eam/workordermaintenance/rotate', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 删除量具送检计划
export async function workOrderDelete(data) {
  const res = await request.delete('/eam/plan/delete', { data });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 负责人已收
export async function received(data) {
  const res = await request.post('/eam/planTool/received', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 通过工单查询备品备件
 */
export async function getSpareParts(params) {
  const res = await request.get(`/eam/workorder/getSpareParts`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
