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

//薪资帐套列表
export const getLedgerList = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/list", params);
};

//启用/禁用薪资帐套
export const changeLedgerStatus = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/disable", params);
};

//复制薪资帐套
export const duplicateLedger = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/duplicate", params);
};

//删除薪资帐套
export const deleteLedger = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/delete", params);
};

//薪资帐套基本信息表单
export const getLedgerBasicForm = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salarysob/basic/getForm", "get", params);
};

//保存薪资帐套基本信息
export const saveLedgerBasic = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/basic/save", params);
};

//薪资帐套外部人员范围（包含）列表
export const getLedgerPersonRangeExtList = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/ext/list", params);
};
//薪资帐套人员范围（包含）列表
export const getLedgerPersonRangeInclude = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/listInclude", params);
};

//薪资帐套人员范围（排除）列表
export const getLedgerPersonRangeExclude = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/listExclude", params);
};

//保存薪资帐套外部人员范围
export const saveLedgerPersonExtRange = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/ext/save", params);
};
//删除薪资帐套外部人员范围
export const deleteLedgerPersonExtRange = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/ext/delete", params);
};
//保存薪资帐套人员范围
export const saveLedgerPersonRange = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/save", params);
};
//编辑薪资帐套人员范围
export const editLedgerPersonRange = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/edit", params);
};

//删除薪资帐套人员范围
export const deleteLedgerPersonRange = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/delete", params);
};

//保存薪资帐套薪资项目
export const saveLedgerItem = params => {
  const { itemGroups, items, ...extra } = params;
  const payload = {
    itemGroups: _.map(itemGroups, item => {
      return {
        ...item,
        items: _.map(item.items, it => {
          delete it.formulaContent;
          return { ...it };
        })
      };
    }),
    items: _.map(items, child => {
      delete child.formulaContent;
      return { ...child };
    }) || [],
    ...extra
  };
  return postFetch("/api/bs/hrmsalary/salarysob/item/save", payload);
};

//薪资帐套薪资项目详情
export const getLedgerItemForm = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salarysob/item/getForm", "get", params);
};

//薪资帐套校验规则列表
export const getLedgerRuleList = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/checkrule/list", params);
};

//保存薪资帐套校验规则
export const saveLedgerRule = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/checkrule/save", params);
};

//删除薪资帐套校验规则
export const deleteLedgerRule = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/checkrule/delete", params);
};

// 薪资项目可选列表
export const listSalaryItem = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/item/listSalaryItem", params);
};

// 员工信息字段列表
export const empFieldList = () => {
  return WeaTools.callApi("/api/bs/hrmsalary/salarysob/empField/list", "GET", {});
};

// 调薪计薪规则可选的薪资项目列表
export const listSalarySobItem = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/adjustmentrule/listSalarySobItem", params);
};

// 调薪计薪规则保存
export const saveAdjustmentRule = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/adjustmentrule/save", params);
};

// 调薪计薪规则列表
export const listAdjustmentRule = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/adjustmentrule/list", params);
};

//获取回算薪资项目
export const getAggregate = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salarysob/backitem/getAggregate", "GET", params);
};

//编辑回算薪资项目详情
export const getBackitemForm = params => {
  return WeaTools.callApi("/api/bs/hrmsalary/salarysob/backitem/getForm", "GET", params);
};
//保存回算薪资项目详情
export const salarysobBackitemSave = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/backitem/save", params);
};
//预览人员范围导入
export const salarysobRangePreview = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/preview", params);
};
//导入人员范围
export const salarysobRangeImportData = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/range/importData", params);
};
//薪资账套-获取薪资账套中薪资项目明细
export const getSalaryItemForm = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/item/getSalaryItemForm", params);
};
//薪资核算规则配置-获取薪资审批规则表单
export const getSalaryApprovalForm = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/salaryApproval/getForm", params);
};
//薪资核算规则配置-保存薪资审批规则表单
export const salaryApprovalSaveForm = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/salaryApproval/saveForm", params);
};
//薪资核算规则配置-获取能够添加的项目
export const getListSalaryItem = params => {
  return postFetch("/api/bs/hrmsalary/salarysob/salaryApproval/listSalaryItem", params);
};
