import request from '@/utils/request';
import store from '@/store';
import Vue from 'vue';

/**
 * 列表
 */
export async function getList(params) {
  const res = await request.post('/aps/workorder/page', params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getListStop(params) {
  const res = await request.post('/aps/workorder/pageStop', params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 下达
export async function releaseWorkOrder(data) {
  const res = await request.post(`/aps/workorder/releaseWorkOrder`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 修改优先级
export async function updatePriority(data) {
  const res = await request.post(`/aps/workorder/updatePriority`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 订单拆单

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

// 删除拆单数据
export async function unpackDel(id) {
  const res = await request.delete(`/aps/workorder/delById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取用户的工厂，所属工作中中心，班组等信息
export async function getUserInfo(id) {
  const res = await request.get(`/main/user/getUserWindow/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//校验当前用户是否是对应班组班组长
export async function getcheckLoginUserIsTeamLeader(teamId) {
  const res = await request.get(
    `/main/team/checkLoginUserIsTeamLeader/${teamId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
