import request from '@/utils/request';
//查询列表
export async function getList(data) {
  const res = await request.get('/eom/goods/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//添加
export async function saveGoods(data) {
  const res = await request.post('/eom/goods/save', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//删除
export async function del(data) {
  const res = await request.delete('/eom/goods/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//查询历史列表
export async function getHistoryList(data) {
  const res = await request.get(`/eom/goods/getHistoryList/${data}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


// 上下架
export async function offOnSheft(data) {
 
  const res = await request.put(`/eom/goods/priceOffOnSheft/${data.shelf_type}/`,data.goods_id);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//详情
export async function getGoodsById(data) {
  const res = await request.get(`/eom/goods/getGoodsById/${data}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//修改商品
export async function updateGoods(data) {
  const res = await request.put('/eom/goods/updateGoods', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}


//商品价格详情
export async function getGoodsPriceById(data) {
  const res = await request.get(`/eom/goods/getGoodsPriceById/${data}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//修改商品价格
export async function updateGoodsPrice(data) {
  const res = await request.put('/eom/goods/updateGoodsPrice', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}