import axios from 'axios';

// 生产环境默认同源，开发可由 .env 覆盖
const baseURL = process.env.VUE_APP_API_BASE_URL || (typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.hostname}:12315` : '');

export const http = axios.create({ baseURL, timeout: 15000 });

// 创建专门用于堆垛机数据的axios实例
const stackerHttp = axios.create({
  baseURL: 'http://172.18.222.253:9980',
  timeout: 15000
});

export async function queryTasksByPage(params) {
  const { data } = await http.post('/wms/taskQuery/queryTasksByPage', params);
  return data?.data;
}

export async function queryPickTasksByPage(params) {
  const { data } = await http.post('/wms/taskQuery/queryPickTasksByPage', params);
  return data?.data;
}

export async function queryPickPlansByPage(params) {
  const { data } = await http.post('/wms/pickPlan/queryPickPlansByPage', params);
  return data?.data;
}

export async function getGoodsInfoByGoodsId(goodsId) {
  const { data } = await http.get('/wms/goods/getGoodsInfoByGoodsId', { params: { goodsId } });
  return data?.data;
}

export async function queryOutsByPage(params) {
  const { data } = await http.post('/wms/taskQuery/queryOutsByPage', params);
  return data?.data;
}

export async function queryStocks(params) {
  const { data } = await http.post('/wms/stock/queryStocks', params);
  return data?.data;
}

// 新增的看板数据接口
export async function getTaskTypInData(params = {}) {
  const { data } = await http.get('/wms/board/getTaskTypInData', { params });
  return data;
}

export async function getOutsData(params = {}) {
  const { data } = await http.get('/wms/board/getOutsData', { params });
  return data;
}

export async function getPickTaskDataP1(params = {}) {
  const { data } = await http.get('/wms/board/getPickTaskDataP1', { params });
  return data;
}

export async function getPickTaskDataP2(params = {}) {
  const { data } = await http.get('/wms/board/getPickTaskDataP2', { params });
  return data;
}

export async function getPickTaskDataP3(params = {}) {
  const { data } = await http.get('/wms/board/getPickTaskDataP3', { params });
  return data;
}

export async function getStackerData(params = {}) {
  const { data } = await stackerHttp.get('/api/upper/pub/queryStackerInfo', params);
  return data;
}
