import request from '@/utils/request';

/**
 * 分页查询用户
 * @param params 查询条件
 */
export async function pageList (params) {
  let par = new URLSearchParams(params);
  const res = await request.get(
    `/main/produceversion/page?` + par,
    params
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取生产版本详情
export async function versionDetail(id) {
  const res = await request.get(`/main/produceversion/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


// 生产版本新增、编辑
export async function versionSave(data) {
  const res = await request.post('/main/produceversion/save', data);
  if (res.data.code == 0) {
    return res.data.message;
  }
}



// 根据工艺路线编码获取工序
export async function getProcessByRoute(data) {
  const res = await request.post('/main/producerouting/taskinstance/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


// 查询物料关联BOM子项列表
export async function getBomSubList(data) {
  const res = await request.get('/main/produceversion/resource/bomSubList', { params: data});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 保存bom子项列表 
export async function saveBomList(data) {
  const res = await request.post('/main/produceversion/resource/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生产版本同步
export async function syncVersion(data) {
  const res = await request.get('/sap/sync/syncVersion');
  if (res.data.code == 0) {
    return res.data.code;
  }
  return Promise.reject(new Error(res.data.message));
}

