import request from '@/utils/request';
import { data } from 'ele-admin/lib/ele-pro-table';

// 获取记录规则详情
export async function getRecordRulesDetail(id) {
  const res = await request.get(`/main/recordrules/getById/` + id, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /main/recordrules/getById/{id} 查看详情
export async function recordrulesGetById(id) {
  const res = await request.get(`/main/recordrules/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 记录规则明细表
export async function recordRulesDetailPage(body) {
  const res = await request.post(`/main/recordrulesdetail/page`, body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 规则记录分页查询
export async function recordrulesPage(body) {
  const res = await request.post(`/main/recordrules/page`, body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 规则记录分页查询 过程控制 /main/recordrules/notProduceTaskConfigRecordRulesPage
export async function recordrulesNotProduceTaskConfigRecordRulesPage(body) {
  const res = await request.post(
    `/main/recordrules/processInspectionRecordRulesPage`,
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 记录计划配置 计划 /mes/recordrulesplan/page
export async function recordrulesplanPage(body) {
  const res = await request.post(`/mes/recordrulesplan/page`, body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// /mes/recordrulesplan/delete
export async function recordrulesplanDelete(ids) {
  const res = await request.delete(`/mes/recordrulesplan/delete`, {
    data: ids
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// 获取记录规则计划详情 /mes/recordrulesplan/getById/{id}
export async function getRecordRulesPlanDetail(id) {
  const res = await request.get(`/mes/recordrulesplan/getById/` + id, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// /mes/recordrulesplan/revoke post 撤回
export async function recordrulesplanRevoke(id) {
  const res = await request.post(`/mes/recordrulesplan/revoke`, id);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// /mes/recordrulesplan/manualDispatchOrder 手动派单
export async function recordrulesplanManualDispatchOrder(body) {
  const res = await request.post(
    `/mes/recordrulesplan/manualDispatchOrder`,
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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