import request from '@/utils/request';

// 更新或保存
export async function saveOrUpdate (data) {
  const res = await request.post('/main/ruleinfo/saveOrEdit', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生成编码
export async function getCode (code) {
  const res = await request.get(`/main/codemanage/getCode/` + code, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取规则列表页
export async function getList (data) {
	let par = new URLSearchParams(data);
  const res = await request.get(`/main/ruleinfo/page?` + par, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取规则详情
export async function getDetail (id) {
  const res = await request.get(`/main/ruleinfo/getById/` + id, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 删除事项
 */
export async function removeRule(data) {
  const res = await request.delete('/main/ruleinfo/delete', { data } );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


// 获取仓库列表 
export async function getWarehouseList (params) {
  const res = await request.get('/wms/warehouse/page',  params );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

