import request from '@/utils/request'

// 查询工艺路线列表
export function listRoute(query) {
  return request({
    url: '/system/route/list',
    method: 'get',
    params: query
  })
}

// 查询工艺路线详细
export function getRoute(id) {
  return request({
    url: '/system/route/' + id,
    method: 'get'
  })
}

// 新增工艺路线
export function addRoute(data) {
  return request({
    url: '/system/route',
    method: 'post',
    data: data
  })
}

// 修改工艺路线
export function updateRoute(data) {
  return request({
    url: '/system/route',
    method: 'put',
    data: data
  })
}

// 获取项目令号列表
export function getDistinctProjectCodes(query) {
  return request({
    url: '/system/route/getDistinctProjectCodes', // 后端接口 URL，确保正确
    method: 'get',
    params: { query } // 将查询关键字传递给后端
  })
    .then((response) => {
      return response; // 返回数据部分
    })
    .catch((error) => {
      console.error('Error fetching project codes:', error);
      throw error; // 抛出错误让前端可以捕获
    });
}

export function getProcessInfoList(query) {
  return request({
    url: '/system/route/getProcessInfoList', // 后端接口 URL，确保正确
    method: 'get',
    params: { query } // 将查询关键字传递给后端
  })
    .then((response) => {
      return response; // 返回数据部分
    })
    .catch((error) => {
      console.error('Error fetching project codes:', error);
      throw error; // 抛出错误让前端可以捕获
    });
}

export function onSave(list) {
  return request({
    url: '/system/route/addRoute',
    method: 'post',
    data: list,
  })
  .then((response) => {
    
    return response;
  })
  .catch((error) => {
    console.error('Error saving route:', error); 
    throw error; 
  });
}


// 删除工艺路线
export function delRoute(id) {
  return request({
    url: '/system/route/' + id,
    method: 'delete'
  })
}

export function pushRouteBom(rooteProdet) {
  return request({
    url: '/system/route/pushRouteBom',
    method: 'post',
    params: { rooteProdet },
  });
}
export function updateProcessPlan(rooteProdet) {
  return request({
    url: '/system/route/updateProcessPlan',
    method: 'post',
    params: { rooteProdet },
  });
}

export function generatePDFs(rooteProdet) {
  return request({
    url: '/system/route/generatePDFs',
    method: 'post',
    params: { rooteProdet },
  });
}

