import request from '@/utils/request';
// 查询实例详情
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 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 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 getAssetList(data) {
  let par = new URLSearchParams(data);
  const res = await request.get(`/main/asset/page?` + par, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取工厂下的所有车间
export async function listWorkshopByParentId(params) {
  const res = await request.get(
    `/main/factoryarea/listWorkshopByParentId/${params}`,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询工厂列表-分页
export async function getFactoryarea(params) {
  const res = await request.get(`/main/factoryarea/page`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询工厂列表-分页
export async function factoryworkstation(params) {
  const res = await request.get(`/main/factoryworkstation/page`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 保存or更新
export async function saveOrEdit(data) {
  const res = await request.post(`/main/asset/saveOrEdit`, data);
  if (res.data.code == 0) {
    return res.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));
// }

//根据产品ID获取bom列表、工艺路线列表【产品管理】
export async function getBomRoutingList(categoryId) {
  const res = await request.get(`/main/category/getSourceList/${categoryId}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询产品已关联物料信息
export async function getRelatesInformationList(data) {
  const res = await request.post(
    `/main/category/getRelatesInformationList`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getRealData(id) {
  const res = await request.get(`/main/asset/getRealData/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询设备工单信息
export async function deviceWorkList(data) {
  const res = await request.get(`/eam/plan/deviceWorkList`, {
    params: data
  });
  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 listByProductionLineId(params) {
  const res = await request.get(
    `/main/factoryworkstation/listByProductionLineId/` + params,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function listFactoryLine(params) {
  const res = await request.post(`/main/factoryarea/listFactoryLine`, params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取工序下所有的设备信息
export async function getTaskDeviceList(taskId) {
  const res = await request.get(
    `/main/factoryworkstation/listBySourceTaskId/${taskId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
