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 getWarehouseList() {
  const res = await request.post(`/wms/warehouse/select/warehouseList`, {
    params: { status: 1 }
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询首页头部统计
 */
export async function getCount(body) {
  const res = await request.post(`/mes/index/count`, body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询工单完成统计
 */
export async function getCompletionCount(body) {
  const res = await request.post(`/mes/index/completionCount`, body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询工单列表
 */

export async function getOrderList(body) {
  const res = await request.post(`/mes/index/getOrderList`, body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 不良占比
export async function queryProportionDefectiveTypes(params) {
  const res = await request.post(
    `/qms/quality_work_order/queryProportionDefectiveTypes` + params
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生产日报表
export async function getProductionReport(params) {
  const res = await request.get(`/mes/productionReport/v1/daily`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
