import request from '@/utils/request';
import { setToken } from '@/utils/token-util';

/**
 * 登录
 */
export async function login(data) {
  const res = await request.post('/main/user/login', data);
  if (res.data.code == 0) {
    setToken(res.data.data.token, data.remember);
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取验证码
 */
export async function getCaptcha() {
  const res = await request.get('/captcha');
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function pickOrderPage(params) {
  const res = await request.get(`/mes/pickorder/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function saleordersendrecordPage(params) {
  const res = await request.get(`/eom/saleordersendrecord/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function getById(id) {
  const res = await request.get(`/eom/saleordersendrecord/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function purchaseorderreceive(params) {
  const res = await request.get(`/eom/purchaseorderreceive/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function oneId(id) {
  const res = await request.get(`/eom/purchaseorderreceive/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function purchaseorderGetById(id) {
  const res = await request.get(`/eom/purchaseorder/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function contactlink(params) {
  const res = await request.get(`/eom/contactlink/list`, { params });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取委外单列表
export async function getOutsourcedOrdersList(params) {
  const res = await request.get(`/mes/applyoutsource/page`, { params });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取受托收货单列表
export async function getSaleentrustedreceiveList(params) {
  const res = await request.get(`/eom/saleentrustedreceive/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取项目立项列表
export async function getProjectsList(data) {
  const res = await request.post(`/pro/projects/page`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
