import request from '@/utils/request';

// 获取未合并挂网数据列表
export const getScheduleWorkOrderByPage = (data) => {
  return request({
    url: '/aps/productionplan/ListHangNetwork',
    method: 'post',
    params: {
      pageNum: data.pageNum,
      size: data.size
    },
    data
  });
};

//添加挂网并模
export const updateMergeV2 = (data) => {
  return request({
    url: '/aps/productionplan/HangNet',
    method: 'post',
    data
  });
};

// 获取任务下发数据列表
export const getPutMeshWorkOrderByPage = async (data) => {
  const res = await request({
    url: '/aps/team_networking_task/ListPage',
    method: 'post',
    params: {
      pageNum: data.pageNum,
      size: data.pageSize
    },
    data: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
};

// 任务下发按钮操作
export const issuedPutMeshWorkOrder = (params) => {
  return request.post('/aps/team_networking_task/updateStatus', params);
};

// 批量删除挂网工单信息(取消、删除、撤回)
export const deletePutMeshWorkOrder = (params, type) => {
  console.log(params);
  let url =
    type == 0
      ? '/aps/team_networking_task/cancel'
      : '/aps/team_networking_task/delete';
  if (type == 1) {
    return request.post(url, params.id);
  } else {
    return request.post(url, params);
  }
};

// // 未合并挂网列表删除
// export const deleteScheduleWorkOrder = (params) => {
//   return request({
//     url: '/aps/productionplan/delete/' + id,
//     method: 'post',
//     params
//   });
// };
// 删除
export async function deleteScheduleWorkOrder(id) {
  const res = await request.delete('/aps/productionplan/deleteByBy/' + id);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
