import request from '@/utils/request';
import { download } from '@/utils/file';

//需求---------------------------------------------------------------
export async function getPageSalesDemand(data) {
  const res = await request.get('/eom/afterSalesDemand/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 关闭需求
export async function closeDemand(id) {
  const res = await request.post(`/eom/afterSalesDemand/close/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//新增
export async function saveSalesDemand(data) {
  const res = await request.post('/eom/afterSalesDemand/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//根据id查询详情
export async function getSalesDemandById(id) {
  const res = await request.get(`/eom/afterSalesDemand/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//修改
export async function updateSalesDemand(data) {
  const res = await request.put('/eom/afterSalesDemand/update', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//删除
export async function deleteSalesDemand(data) {
  const res = await request.delete('/eom/afterSalesDemand/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//撤回
export async function revokeSalesDemand(data) {
  const res = await request.post(`/eom/afterSalesDemand/retract`, data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//审核
export async function auditSalesDemand(data) {
  const res = await request.post('/eom/afterSalesDemand/audit', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 计划-------------------------------------------------------------------
export async function getSalesPlan(data) {
  const res = await request.get('/eom/afterSalesPlan/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//删除
export async function deleteSalesPlan(data) {
  const res = await request.delete('/eom/afterSalesPlan/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//根据id查询详情
export async function getSalesPlanById(id) {
  const res = await request.get(`/eom/afterSalesPlan/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//修改
export async function updateSalesPlan(data) {
  const res = await request.put('/eom/afterSalesPlan/update', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//派单
export async function dispatchOrders(data) {
  const res = await request.put('/eom/afterSalesPlan/sendOrder', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//撤回
export async function planRevocation(id) {
  const res = await request.get(`/eom/afterSalesPlan/revocation/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//申请备品备件
export async function saveOrUpdateSalesPlan(data) {
  const res = await request.post('/eom/afterSalesPlan/saveOrUpdate', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//生成报价单
export async function generateQuotationSheet(id) {
  const res = await request.get(
    `/eom/afterSalesPlan/generateQuotationSheet/${id}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//下载报价单
export async function SalesPlanDownload(id) {
  const res = await request.get(`/eom/afterSalesPlan/download/${id}`, {
    responseType: 'blob'
  });

  download(res.data, '报价单.xlsx');
}

//工单------------------------------------------------------------------------
export async function getSalesWorkOrder(data) {
  const res = await request.get('/eom/afterSalesWorkOrder/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//删除
export async function deleteSalesWorkOrder(data) {
  const res = await request.delete('/eom/afterSalesWorkOrder/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取信息
export async function getSalesWorkOrderById(id) {
  const res = await request.get(`/eom/afterSalesWorkOrder/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//申请备品备件
export async function saveOrUpdateSalesWorkOrder(data) {
  const res = await request.post('/eom/afterSalesWorkOrder/saveOrUpdate', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//接收
export async function receiveSalesWorkOrder(data) {
  const res = await request.put('/eom/afterSalesWorkOrder/receive', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//转派
export async function reassignmentSalesWorkOrder(data) {
  const res = await request.put('/eom/afterSalesWorkOrder/reassignment', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//报工
export async function reportWorkingSalesWorkOrder(data) {
  const res = await request.put('/eom/afterSalesWorkOrder/reportWorking', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
//修改
export async function updateScheme(data) {
  const res = await request.put('/eom/afterSalesWorkOrder/updateScheme', data);
  if (res.data.code === '0') {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

//验收
export async function checkAndAccept(data) {
  const res = await request.post(
    '/eom/afterSalesWorkOrder/checkAndAccept',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//评论

//表格
export async function evaluatePage(data) {
  const res = await request.get('/eom/afterSalesEvaluation/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//保存
export async function evaluateSave(data) {
  const res = await request.post('/eom/afterSalesEvaluation/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件申请记录 表格
export async function accessoryPage(data) {
  const res = await request.get('/eom/sparePartsApply/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件申请记录 表格 新增
export async function accessorySave(data) {
  const res = await request.post('/eom/sparePartsApply/saveOrUpdate', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件申请记录 表格 修改
export async function accessoryUpdate(data) {
  const res = await request.put('/eom/sparePartsApply/update', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件申请记录 表格 删除
export async function accessoryDelete(data) {
  const res = await request.delete('/eom/sparePartsApply/delete', { data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 故障知识库 表格
export async function knowledgePage(data) {
  const res = await request.get('/eom/faultKnowledgeBase/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 故障知识库 表格 新增
export async function faultKnowledgeSave(data) {
  const res = await request.post('/eom/faultKnowledgeBase/saveBatch', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 故障知识库 表格 修改
export async function faultKnowledgeUpdate(data) {
  const res = await request.put('/eom/faultKnowledgeBase/update', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 故障知识库 表格 删除
export async function faultDelete(data) {
  const res = await request.delete('/eom/faultKnowledgeBase/delete', { data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件回收记录 表格
export async function recyclePage(data) {
  const res = await request.get('/eom/afterSalesAccessoryApply/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件回收记录 表格 新增
export async function recycleSave(data) {
  const res = await request.post('/eom/afterSalesAccessoryApply/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件回收记录 表格 修改
export async function recycleUpdate(data) {
  const res = await request.put('/eom/afterSalesAccessoryApply/update', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件回收记录 表格 详情
export async function recycleDetails(id) {
  const res = await request.get(`/eom/afterSalesAccessoryApply/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件回收记录 表格 删除
export async function recycleDelete(data) {
  const res = await request.delete('/eom/afterSalesAccessoryApply/delete', {
    data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 配件申请记录 表格 详情
export async function spareParDetails(id) {
  const res = await request.get(`/eom/sparePartsApply/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 需求提交
export async function demandSubmit(data) {
  const res = await request.post('/eom/afterSalesDemand/audit', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 需求派单
export async function demanDispatch(data) {
  const res = await request.post('/eom/afterSalesDemand/dispatch', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 计划 按钮 权限
export async function checkByPlanId(id) {
  const res = await request.get(`/eom/afterSalesPlan/checkByPlanId/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 需求 按钮 权限
export async function checkByWorkId(id) {
  const res = await request.get(`/eom/afterSalesWorkOrder/checkByWorkId/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 评论 校验当前登录人是否可以评论
export async function afterSalesEvaluation(id) {
  const res = await request.get(
    `/eom/afterSalesEvaluation/checkByWorkId/${id}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 售后费用 表格
export async function aftersalesrealcost(params) {
  const res = await request.get(`/eom/aftersalesrealcost/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 售后费用 详情
export async function salesrealcostinfo(id) {
  const res = await request.get(`/eom/aftersalesrealcost/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 售后费用 保存
export async function costSave(data) {
  const res = await request.post(`/eom/aftersalesrealcost/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 售后费用 修改
export async function costUpdate(data) {
  const res = await request.put(`/eom/aftersalesrealcost/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 售后费用 删除
export async function costDelete(data) {
  const res = await request.delete(`/eom/aftersalesrealcost/delete`, { data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
