import request from '@/utils/request';

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

//新建
export async function save(data) {
  const res = await request.post(`/mes/please_entrust_management/add`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// 删除
export async function remove(data) {
  const res = await request.delete('/mes/please_entrust_management/remove', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//提交
export async function submit(data) {
  const res = await request.post('/bpm/please_entrust/submit', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

//直接提交
export async function addSubmit(data) {
  const res = await request.post(
    '/mes/please_entrust_management/addAndSubmit',
    data
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取详情
export async function pleaseEntrustDetail(id) {
  const res = await request.get(`/mes/please_entrust_management/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取工单的物品清单
export async function pleaseEntrustGoodsDetail(data) {
  const res = await request.post(
    `/mes/please_entrust_management/listDetail`,
    data
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取工单的所有物品清单
export async function pleaseEntrustAllGoodsDetail(data) {
  const res = await request.post(
    `/mes/please_entrust_management/preDetail`,
    data
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//保存物品清单
export async function pleaseEntrustSaveDetail(data) {
  const res = await request.post(
    `/mes/please_entrust_management/saveDetail`,
    data
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//确认收货
export async function pleaseTReceiveGoods(data) {
  const res = await request.post(
    `/mes/please_entrust_management/receiveDetailEnd`,
    data
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
