import request from '@/utils/request';

// 工单分页
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 getRule(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(`/main/ruleinfo/page?` + par, {});
  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 report(data) {
  const res = await request.post('/eam/workordermaintenance/report', 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));
}

/**
 * 查询人员列表
 * @param params 查询条件
 */
export async function getUserPage(params) {
  let par = new URLSearchParams(params);
  const res = await request.get(`/main/user/getUserPage?` + par, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 维修工单列表
export async function getWorkOrderList(data) {
  const res = await request.get('/eam/workorder/getWorkOrderList', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.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 getWorkOrderDetail(code) {
  const res = await request.get('/eam/workorder/getWorkOrderDetail/' + code);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询实例详情
export async function getAssetInfo(id) {
  const res = await request.get(`main/asset/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 报工
export async function acceptance(data) {
  const res = await request.post('/eam/workorder/acceptance', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
