import { WeaTools } from "ecCom";
import { postFetch } from "../util/request";

// 薪资记录--薪资核算列表
export const getSalaryAcctList = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/list", params);
};

// 薪资记录--保存薪资核算的基本信息
export const saveBasic = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/basic/save", params);
};
// 薪资记录--批量薪资核算
export const batSaveBasic = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/basic/batSave", params);
};
// 薪资记录--批量新建并核算
export const batSaveAndAcct = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/batSaveAndAcct", params);
};

// 薪资记录--薪资核算详情
export const salaryacctGetForm = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/getForm", "GET", params);
};

// 核算人员--薪资核算环比上期减少人员列表
export const reducedemployeeList = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/reducedemployee/list", params);
};
// 核算人员--薪资核算环比上月增加人员
export const addedemployeeList = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/addedemployee/list", params);
};

// 核算人员--薪资核算人员确认列表
export const acctemployeeList = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctemployee/list", params);
};

// 核算人员--检查薪资核算人员的个税扣缴义务人
export const checkTaxAgent = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctemployee/checkTaxAgent", params);
};

// 薪资记录--获取薪资核算的薪资周期、考勤周期等
export const getSalarySobCycle = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/getSalarySobCycle", "GET", params);
};

// 核算人员--添加薪资核算人员
export const saveAcctemployee = params => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctemployee/save", params);
};

// 核算人员--导出环比减少人员
export const exportReducedEmployee = (id) => {
  fetch("/api/bs/hrmsalary/salaryacct/reducedemployee/export?salaryAcctRecordId=" + id).then(res => res.blob().then(blob => {
    var filename = `导出环比减少人员.xlsx`;
    var a = document.createElement("a");
    var url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }));
};

// 核算人员--导出人员范围
export const exportAcctEmployee = (id) => {
  fetch("/api/bs/hrmsalary/salaryacct/acctemployee/export?salaryAcctRecordId=" + id).then(res => res.blob().then(blob => {
    var filename = `导出环比减少人员.xlsx`;
    var a = document.createElement("a");
    var url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }));
};

// 核算人员--删除薪资核算人员
export const deleteAcctemployee = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctemployee/delete", params);
};

// 核算结果--列表
export const acctResultList = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/list", params);
};

// 核算结果--薪资核算
export const acctresultAccounting = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/accounting", params);
};

// 线下比对-列表
export const comparisonresultList = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/accounting", params);
};

// 核算人员--刷新薪资核算人员的个税扣缴义务人
export const refreshTaxAgent = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctemployee/refreshTaxAgent", params);
};
// 核算人员--刷新薪资核算人员的
export const refreshAcctemployee = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctemployee/refresh", params);
};
// 薪资核算-编辑表单
export const acctresultDetail = (params) => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/acctresult/detail", "GET", params);
};

// 薪资记录--删除薪资核算记录
export const deleteSalaryacct = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/delete", params);
};

// 薪资记录--归档薪资核算记录
export const fileSalaryAcct = (params) => {
  // return WeaTools.callApi(`/api/bs/hrmsalary/salaryacct/file`, "GET", params);
  return fetch(`/api/bs/hrmsalary/salaryacct/file?id=${params.id}`, {
    method: "GET",
    mode: "cors",
    headers: {
      "Content-Type": "application/json"
    }
  }).then(res => res.json());
};
// 薪资记录-批量归档
export const batFile = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/batFile", params);
};
// 薪资记录-回算
export const backCalculate = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/backCalculate", params);
};

// 薪资记录-重新核算
export const reAccounting = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/reAccounting", params);
};
// 薪资记录-批量重新核算
export const batReAccounting = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/batReAccounting", params);
};

// 薪资结果-编辑表单保存
export const saveAcctResult = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/save", params);
};

// 核算结果--导入核算结果前生成导入模板时可选的薪资项目
export const getImportField = (params) => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/acctresult/importField", "GET", params);
};

// 核算结果-导入模板
export const getImportTemplate = (salaryItemIds, salaryAcctRecordId) => {
  fetch("/api/bs/hrmsalary/salaryacct/acctresult/importtemplate/export?salaryItemIds=" + salaryItemIds + "&salaryAcctRecordId=" + salaryAcctRecordId).then(res => res.blob().then(blob => {
    var filename = `薪资核算.xlsx`;
    var a = document.createElement("a");
    var url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }));
};

// 核算结果-导入预览
export const previewAcctResult = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/preview", params);
};

// 核算结果-导入
export const importAcctResult = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/importSalaryAcctResult", params);
};

// 核算结果-导出全部
export const exportAcctResult = (salaryAcctRecordId, ids) => {
  fetch("/api/bs/hrmsalary/salaryacct/acctresult/export?salaryAcctRecordId=" + salaryAcctRecordId + "&ids=" + ids).then(res => res.blob().then(blob => {
    var filename = `薪资核算.xlsx`;
    var a = document.createElement("a");
    var url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }));
};

// 线下对比-列表
export const comparisonResultList = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/comparisonresult/list", params);
};

// 线下对比--结果导入模板
export const exportImportTemplate = (salaryAcctRecordId) => {
  fetch("/api/bs/hrmsalary/salaryacct/comparisonresult/importtemplate/export?salaryAcctRecordId=" + salaryAcctRecordId).then(res => res.blob().then(blob => {
    var filename = `线下对比导入模板.xlsx`;
    var a = document.createElement("a");
    var url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }));
};

// 线下对比--导入预览
export const previewComparisonResult = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/comparisonresult/preview", params);
};

// 线下对比--导入
export const importComparisonExcelAcctResult = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/comparisonresult/importExcelAcctResult", params);
};

// 线下对比-导出
export const exportComparisonResult = (salaryAcctRecordId) => {
  fetch("/api/bs/hrmsalary/salaryacct/comparisonresult/export?salaryAcctRecordId=" + salaryAcctRecordId).then(res => res.blob().then(blob => {
    var filename = `线下对比结果.xlsx`;
    var a = document.createElement("a");
    var url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }));
};

// 核算进度条
export const getCalculateProgress = (id = "", paymentOrganization = "") => {
  const extra = paymentOrganization ? `_${paymentOrganization}` : paymentOrganization;
  return WeaTools.callApi(`/api/bs/hrmsalary/progress/getRate?cacheKey=ACCT_PROGRESS_${id}${extra}`, "get", {});
};

// 核算进度条
export const getColumnDesc = (params) => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/acctresult/getColumnDesc", "get", params);
};

// 更新薪资核算结果的锁定状态
export const updateLockStatus = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/updateLockStatus", params);
};
// 更新薪资核算结果的锁定状态
export const updateLockEmpStatus = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/lockEmp", params);
};
// 单元格锁定
export const updateLockEmpCellStatus = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/lock", params);
};
// 导入薪资核算添加表头字段缓存
export const cacheImportField = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/cacheImportField", params);
};
//薪资核算-页面查看权限
export const salaryacctAcctresultCheckAuth = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/acctresult/checkAuth", "GET", params);
};

//薪资核算-导出核算结果前生成可选的薪资项目
export const getExportField = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/acctresult/exportField", "GET", params);
};

//薪资核算-导出薪资核算添加表头字段缓存
export const customCacheExportField = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/cacheExportField", params);
};
//薪资核算-批量更新
export const salaryacctBatchUpdate = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/batchUpdate", params);
};
//薪资核算-自定义导出模板保存新建
export const saveExportTemplate = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/saveExportTemplate", params);
};
//薪资核算-获取自定义导出模板列表
export const getExportTemplateList = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/exportTemplateList", params);
};
//薪资核算-删除自定义导出模板列表
export const deleteExportTemplate = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/deleteExportTemplate", params);
};
//薪资核算-获取导出模板详细信息
export const getExportTemplateForm = (params) => {
  return postFetch("/api/bs/hrmsalary/salaryacct/acctresult/getExportTemplateForm", params);
};
//薪资审批-薪资核算页面获取审批信息
export const getApprovalInfoByRecordId = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salarysob/salaryApproval/getApprovalInfoByRecordId", "GET", params);
};
//薪资核算-薪资项目改变否
export const getCompareSobConfig = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/compareSobConfig", "GET", params);
};
//薪资核算-更新薪资账套
export const updateSobConfig = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salaryacct/updateSobConfig", "GET", params);
};


