import request from '@/utils/request';

// 查询临时盘点数据列表
export async function getInventoryPlanList(params) {
  const res = await request.get('/wms/plan/page', { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增临时盘点计划
export async function saveInventoryPlan(params) {
  const res = await request.post('/wms/plan/save', params);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取临时盘点计划详情
export async function getInventoryPlanDetailById(id) {
  const res = await request.get('/wms/plan/getById/' + id);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 修改临时盘点计划
export async function updateInventoryPlan(params) {
  const res = await request.post('/wms/plan/update', params);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 临时盘点计划删除
export async function deleteInventoryPlan(data) {
  const res = await request.delete(`/wms/plan/delete`, { data });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 盘点计划派单
export async function sendOrders(params) {
  const res = await request.post('/wms/planOrder/sendOrders', params);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 盘点工单列表
export async function getPlanOrderList(params) {
  const res = await request.get('/wms/planOrder/page', { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 盘点工单详情
export async function getOrderInfoByPlanId(params) {
  const res = await request.get('/wms/plan/getOrderInfoByPlanId', {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 盘点计划撤回
export async function revocationInventoryPlan(params) {
  const res = await request.post('/wms/plan/revocation', params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 盘点工单物品详情
export async function getPlanDetailList(params) {
  const res = await request.get('/wms/plandetail/page', {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 盘点报工
export async function reportWork(data) {
  console.log(data);
  const res = await request.post('/wms/planOrder/reportWork', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 报损报溢列表
export async function getReportsList(params) {
  const res = await request.get('/wms/planProfitLoss/page', {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取临时盘点计划详情
export async function getReportPlanDetailById(id) {
  const res = await request.get('/wms/planProfitLoss/getById/' + id);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 报损报溢保存
export async function saveReportsList(data) {
  const res = await request.post('/wms/planProfitLoss/save', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 报损报溢修改
export async function updateReportsList(data) {
  const res = await request.post('/wms/planProfitLoss/update', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 报损报溢列表
export async function getReportList(params) {
  const res = await request.get('/wms/plandetail/list', {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
