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

/**
 * 获取信息列表
 */
export async function getAccountstatementList(params) {
  const res = await request.post(`/eom/accountstatement/page`, params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

/**
 * 更新信息
 */
export async function UpdatetAccountstatement(data) {
  const res = await request.put(`/eom/accountstatement/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询待导入的账单明细
 */
export async function getsearchDetailListByType(params) {
  const res = await request.get(
    `/eom/accountstatement/searchDetailListByType`,
    {params}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 新增信息
 */
export async function addtAccountstatement(data) {
  const res = await request.post(`/eom/accountstatement/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除
 */
export async function deletetAccountstatement(data) {
  const res = await request.delete('/eom/accountstatement/delete', {data});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 提交
 */
export async function submit(data) {
  const res = await request.post(`/bpm/accountStatementApprove/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 查询待导入的账单明细
 */
export async function getSearchMergeListByTypeAPI(data) {
  const res = await request.post(`/eom/accountstatement/searchOrderListByTypeForImport`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 保存
 */
export async function saveAccountStatementAPI(data) {
  const res = await request.post(`/eom/accountstatement/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 修改
 */
export async function updateAccountStatementAPI(data) {
  const res = await request.put(`/eom/accountstatement/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 信息详情
 */
export async function infoAccountStatementAPI(id) {
  const res = await request.get(`/eom/accountstatement/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 提交发起流程
 */
export async function submitAccountStatementApproveAPI(data) {
  const res = await request.post(`/bpm/accountStatementApprove/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 导出对账单
 */
export async function accountStatementExportAPI(id) {
  const res = await request.get(`/eom/accountstatement/export/${id}`, {
    responseType: 'blob'
  })
  if (res.data instanceof Blob) {
    return res;
  }
  return Promise.reject(new Error(res.data.message));
}
