salary-management-front/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerSlide.js

546 lines
22 KiB
JavaScript

/*
* Author: 黎永顺
* name: 新增编辑薪资账套
* Description:
* Date: 2022/12/8
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaLocaleProvider, WeaSlideModal, WeaSteps } from "ecCom";
import { Button, message, Modal } from "antd";
import LedgerBaseSetting from "./ledgerBaseSetting";
import LedgerAssociatedPersonnel from "./ledgerAssociatedPersonnel";
import LedgerSalaryAdjustmentRules from "./ledgerSalaryAdjustmentRules";
import LedgerBackCalculatedSalaryItem from "./ledgerBackCalculatedSalaryItem";
import LedgerSalaryItem from "./ledgerSalaryItem";
import LedgerAccountApprRule from "./ledgerAccountApprRule";
import IncomeTaxFields from "./incomeTaxFields";
import IncomeTaxFieldsCorresponding from "./incomeTaxFieldsCorresponding";
import CumulativeFields from "./cumulativeFields";
import WeaTopTitle from "../../../components/custom-title/weaTopTitle";
import WeaReqTitle from "../../../components/custom-title/weaReqTitle";
import {
salaryApprovalSaveForm,
addupruleSave,
saveAdjustmentRule,
saveLedgerBasic,
saveLedgerItem,
taxreportruleSave,
taxruleSave
} from "../../../apis/ledger";
import { sysConfCodeRule } from "../../../apis/ruleconfig";
import "./index.less";
const { getLabel } = WeaLocaleProvider;
const Step = WeaSteps.Step;
@inject("taxAgentStore", "ledgerStore")
@observer
class LedgerSlide extends Component {
constructor(props) {
super(props);
this.state = {
current: 0, loading: false, baseSettingInfo: {}, adjustRules: [],
empFields: [], itemGroups: [], saveSalarySobId: "",
salaryApprovalStatus: false,
taxruleFields: [], taxruleKeys: "", //个税字段对应
incomeTaxFields: [], incomeTaxKeys: "", //个税申报字段对应
addupruleFields: [], addupruleKeys: "", //累计字段对应
taxableItems: "" //薪资类型 1||489 对应显示个税设置-累计字段对应
};
}
async componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) {
const { data } = await sysConfCodeRule({ code: "SALARY_APPROVAL_STATUS" });
this.setState({ salaryApprovalStatus: data === "1" });
}
}
componentWillUnmount() {
this.setState({
saveSalarySobId: ""
});
}
/*
* Author: 黎永顺
* Description: 保存基本信息
* Params:
* Date: 2022/12/12
*/
saveLedgerBasic = () => {
const { baseSettingInfo, current } = this.state;
const { editId } = this.props;
const { description, canEdit, ...extra } = baseSettingInfo;
const bool = _.every(Object.keys(extra), key => !!extra[key]);
if (!bool || _.isEmpty(baseSettingInfo)) {
Modal.warning({
title: "信息确认",
content: "必要信息不完整,红色*为必填项!"
});
return false;
}
this.setState({ loading: true });
saveLedgerBasic({ ...extra, description, id: editId }).then(({ status, data, errormsg }) => {
this.setState({ loading: false });
if (status) {
const { onRefreshList } = this.props;
message.success("保存成功");
onRefreshList();
!editId && this.setState({ current: current + 1, saveSalarySobId: data });
} else {
message.error(errormsg || "保存失败");
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
* Description: 保存调薪计薪规则
* Params:
* Date: 2022/12/12
*/
saveLedgerAdjustRule = () => {
const { adjustRules, saveSalarySobId } = this.state;
const payload = {
salarySobId: this.props.editId || saveSalarySobId,
ruleParams: adjustRules
};
this.setState({ loading: true });
saveAdjustmentRule(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success("保存成功");
} else {
message.success(errormsg || "保存失败");
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
* Description: 薪资项目保存
* Params:
* Date: 2022/12/14
*/
saveLedgerItem = () => {
const { empFields, itemGroups, saveSalarySobId } = this.state;
const { editId: salarySobId } = this.props;
const payload = {
empFields: _.map(empFields, it => {
if (!it.salarySobId) delete it.id;
return { ...it };
}),
itemGroups: _.map(_.filter(itemGroups, it => it.name !== "未分类"), (item, index) => {
return {
...item, sortedIndex: index,
items: _.map(item.items, it => {
delete it.originFormulaContent;
delete it.originSqlContent;
// if (it.id && it.id.length > 4) delete it.id;
return { ...it };
})
};
}),
items: _.map(_.find(itemGroups, it => it.name === "未分类").items, child => {
// if (child.id && child.id.length > 4) delete child.id;
delete child.originFormulaContent;
delete child.originSqlContent;
return { ...child };
}) || [],
salarySobId: salarySobId || saveSalarySobId
};
this.setState({ loading: true });
saveLedgerItem(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success("保存成功");
} else {
message.error(errormsg || "保存失败");
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
* Description:个税字段对应-保存
* Params:
* Date: 2023/8/16
*/
taxRuleSave = () => {
const { editId } = this.props;
const { taxruleKeys, taxruleFields, saveSalarySobId, taxableItems } = this.state;
const payload = {
salarySobId: editId || saveSalarySobId,
incomeCategoryParams: _.map(taxruleFields, it => {
if (it.incomeCategoryId === taxruleKeys) {
return {
incomeCategory: it.incomeCategoryId,
taxRuleParams: _.map(it.taxReportRules, child => {
return {
taxIndex: child.reportColumnDataIndex,
salaryItemId: _.map(child.salaryItem, o => o.id).join(",")
};
})
};
}
return {
incomeCategory: it.incomeCategoryId,
taxRuleParams: []
};
})
};
this.setState({ loading: true });
taxruleSave(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(22619, "保存成功!"));
!editId && (taxableItems && taxableItems.toString() !== "1" && taxableItems.toString() !== "489") && this.handleClose();
} else {
message.error(errormsg || getLabel(22620, "保存失败!"));
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
* Description:个税申报字段对应-保存
* Params:
* Date: 2023/8/16
*/
taxreportruleSave = () => {
const { editId } = this.props;
const { incomeTaxKeys, incomeTaxFields, saveSalarySobId } = this.state;
const payload = {
salarySobId: editId || saveSalarySobId,
incomeCategoryParams: _.map(incomeTaxFields, it => {
if (it.incomeCategoryId === incomeTaxKeys) {
return {
incomeCategory: it.incomeCategoryId,
taxReportRuleParams: _.map(it.taxReportRules, child => {
return {
reportColumnDataIndex: child.reportColumnDataIndex,
salaryItemId: _.map(child.salaryItem, o => o.id).join(",")
};
})
};
}
return {
incomeCategory: it.incomeCategoryId,
taxReportRuleParams: []
};
})
};
this.saveTaxreportrule(payload);
};
saveTaxreportrule = (payload) => {
this.setState({ loading: true });
taxreportruleSave(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(22619, "保存成功!"));
} else {
message.error(errormsg || getLabel(22620, "保存失败!"));
}
}).catch(() => this.setState({ loading: false }));
};
/*
* Author: 黎永顺
* Description:保存薪资账套下的累计字段对应关系
* Params:
* Date: 2023/8/17
*/
addupruleSave = () => {
const {
taxableItems, incomeTaxFields, incomeTaxKeys, addupruleFields,
addupruleKeys, saveSalarySobId
} = this.state;
const { editId } = this.props;
if ((!editId && taxableItems && taxableItems.toString() !== "1" && taxableItems.toString() !== "489")) {
const payload = {
salarySobId: editId || saveSalarySobId,
incomeCategoryParams: _.map(incomeTaxFields, it => {
if (it.incomeCategoryId === incomeTaxKeys) {
return {
incomeCategory: it.incomeCategoryId,
taxReportRuleParams: _.map(it.taxReportRules, child => {
return {
reportColumnDataIndex: child.reportColumnDataIndex,
salaryItemId: _.map(child.salaryItem, o => o.id).join(",")
};
})
};
}
return {
incomeCategory: it.incomeCategoryId,
taxReportRuleParams: []
};
})
};
this.saveTaxreportrule(payload);
} else {
const payload = {
salarySobId: editId || saveSalarySobId,
incomeCategoryParams: _.map(addupruleFields, it => {
if (it.incomeCategoryId === addupruleKeys) {
return {
incomeCategory: it.incomeCategoryId,
addUpRuleParams: _.map(it.addUpRules, child => {
return {
addUpColumnDataIndex: child.addUpColumnDataIndex,
salaryItemId: _.map(child.salaryItem, o => o.id).join(",")
};
})
};
}
return {
incomeCategory: it.incomeCategoryId,
taxReportRuleParams: []
};
})
};
this.setState({ loading: true });
addupruleSave(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(22619, "保存成功!"));
!editId && this.handleClose();
} else {
message.error(errormsg || getLabel(22620, "保存失败!"));
}
}).catch(() => this.setState({ loading: false }));
}
};
handleClose = () => this.setState({ current: 0, baseSettingInfo: {} }, () => this.props.onCancel());
/*
* Author: 黎永顺
* Description: 基础信息字段切换
* Params:
* Date: 2022/12/9
*/
handleChangeSaveParams = (baseSettingInfo) => this.setState({ baseSettingInfo });
/*
* Author: 黎永顺
* Description: 薪资项目保存数据
* Params:
* Date: 2022/12/14
*/
handleSaveSalaryItemParams = (empFields, itemGroups) => {
this.setState({ empFields, itemGroups });
};
handleDefaultSave = () => {
const { saveSalarySobId } = this.state;
const { state: { approvalId } } = this.approRef.wrappedInstance;
const { ledgerStore: { AARForm } } = this.props;
const { approvalItemGroup, isOpenApproval, ...extra } = AARForm.getFormParams();
const group = _.map(approvalItemGroup, (item, index) => ({
groupName: item.groupName, sorted: index,
approvalItems: _.map(item.approvalItems, (o, oi) => ({
salaryItemId: o.salaryItemId, sorted: oi,
salaryItemName: o.salaryItemName
}))
}));
if (isOpenApproval === "1" && _.isEmpty(extra.approvalWorkflowUrl)) {
AARForm.showError("approvalWorkflowUrl", getLabel(111, "\"审批流程地址\"未填写"));
return;
} else if (isOpenApproval === "1" && _.isEmpty(group)) {
AARForm.showError("approvalItemGroup", getLabel(111, "\"审批薪资项目\"未填写"));
return;
}
const payload = {
...extra, isOpenApproval: isOpenApproval === "1", id: approvalId,
salarySobId: this.props.editId || saveSalarySobId,
approvalItemGroup: group
};
this.setState({ loading: true });
salaryApprovalSaveForm(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(111, "保存成功!"));
saveSalarySobId && this.handleClose();
} else {
message.error(errormsg);
}
});
};
render() {
const { visible, editId, taxAgentStore: { showOperateBtn } } = this.props;
const { current, taxableItems, saveSalarySobId, loading, salaryApprovalStatus } = this.state;
let tabs = [
{
key: 0, title: getLabel(82751, "基础设置"),
createBtns: [
<Button type="primary" loading={loading}
onClick={this.saveLedgerBasic}>{getLabel(111, "保存并进入下一步")}</Button>
],
editBtns: [
<Button type="primary" loading={loading} onClick={this.saveLedgerBasic}>{getLabel(111, "保存")}</Button>
],
children: <LedgerBaseSetting
{...this.props} onSaveParams={this.handleChangeSaveParams}
onTaxableItemsChange={(val) => this.setState({ taxableItems: val })}
/>
},
{
key: 1, title: getLabel(543467, "关联人员"),
createBtns: [
<Button type="ghost" onClick={this.handleClose}>{getLabel(111, "完成,跳过所有步骤")}</Button>,
<Button type="primary"
onClick={() => this.setState({ current: current + 1 })}>{getLabel(111, "下一步")}</Button>
],
editBtns: [],
children: <LedgerAssociatedPersonnel {...this.props} saveSalarySobId={saveSalarySobId}/>
},
{
key: 2, title: getLabel(542362, "薪资项目"),
createBtns: [
<Button type="ghost" onClick={this.handleClose}>{getLabel(111, "完成,跳过所有步骤")}</Button>,
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading} onClick={() => {
this.setState({ current: current + 1 }, () => this.saveLedgerItem());
}}>{getLabel(111, "保存并进入下一步")}</Button>
],
editBtns: [
<Button type="primary" loading={loading} onClick={this.saveLedgerItem}>{getLabel(111, "保存")}</Button>
],
children: <LedgerSalaryItem {...this.props} saveSalarySobId={saveSalarySobId}
onSaveSalaryItem={this.handleSaveSalaryItemParams}/>
},
{
key: 3, title: getLabel(543468, "回算薪资项目"),
createBtns: [
<Button type="ghost" onClick={this.handleClose}>{getLabel(111, "完成,跳过所有步骤")}</Button>,
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary"
onClick={() => this.setState({ current: current + 1 })}>{getLabel(111, "下一步")}</Button>
],
editBtns: [],
children: <LedgerBackCalculatedSalaryItem {...this.props} saveSalarySobId={saveSalarySobId}/>
},
{
key: 4, title: getLabel(543469, "调薪计薪规则"),
createBtns: [
<Button type="ghost" onClick={this.handleClose}>{getLabel(111, "完成,跳过所有步骤")}</Button>,
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading}
onClick={() => this.setState({ current: current + 1 }, () => this.saveLedgerAdjustRule())}>{getLabel(111, "保存并进入下一步")}</Button>
],
editBtns: [
<Button type="primary" loading={loading}
onClick={this.saveLedgerAdjustRule}>{getLabel(111, "保存")}</Button>
],
children: <LedgerSalaryAdjustmentRules {...this.props} saveSalarySobId={saveSalarySobId}
onSaveParams={(adjustRules) => this.setState({ adjustRules })}/>
},
{
key: 5, title: getLabel(111, "个税申报配置"),
createBtns: [
<Button type="ghost" onClick={this.handleClose}>{getLabel(111, "完成,跳过所有步骤")}</Button>,
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading}
onClick={() => this.setState({ current: current + 1 }, () => this.taxreportruleSave())}>{getLabel(111, "保存并进入下一步")}</Button>
],
editBtns: [<Button type="primary" loading={loading}
onClick={this.taxreportruleSave}>{getLabel(111, "保存")}</Button>],
children: <IncomeTaxFields {...this.props} saveSalarySobId={saveSalarySobId}
onSetTaxreportrule={(incomeTaxFields, selectedKey) => this.setState({
incomeTaxFields,
incomeTaxKeys: selectedKey
})}/>
},
{
key: 6, title: getLabel(111, "同步个税配置"),
createBtns:
!(taxableItems && taxableItems.toString() !== "1" && taxableItems.toString() !== "489") ?
[
<Button type="ghost" onClick={this.handleClose}>{getLabel(111, "完成,跳过所有步骤")}</Button>,
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading}
onClick={() => this.setState({ current: current + 1 }, () => this.taxRuleSave())}>{getLabel(111, "保存并进入下一步")}</Button>
] : [
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading} onClick={this.taxRuleSave}>{getLabel(111, "完成")}</Button>
],
editBtns: [<Button type="primary" loading={loading}
onClick={this.taxRuleSave}>{getLabel(111, "保存")}</Button>],
children: <IncomeTaxFieldsCorresponding {...this.props} saveSalarySobId={saveSalarySobId}
onSetTaxreportrule={(taxruleFields, selectedKey) => this.setState({
taxruleFields, taxruleKeys: selectedKey
})}/>
},
{
key: 7, title: getLabel(111, "累计字段对应"),
createBtns: [
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading} onClick={this.addupruleSave}>{getLabel(111, "完成")}</Button>
],
editBtns: [<Button type="primary" loading={loading}
onClick={this.addupruleSave}>{getLabel(111, "保存")}</Button>],
children: <CumulativeFields {...this.props} saveSalarySobId={saveSalarySobId}
onSetAdduprule={(addupruleFields, selectedKey) => this.setState({
addupruleFields, addupruleKeys: selectedKey
})}/>
},
{
key: 8, title: getLabel(111, "核算审批规则"),
createBtns: [
<Button type="ghost"
onClick={() => this.setState({ current: current - 1 })}>{getLabel(111, "上一步")}</Button>,
<Button type="primary" loading={loading} onClick={this.handleDefaultSave}>{getLabel(111, "完成")}</Button>
],
editBtns: [
<Button type="primary" loading={loading}
onClick={this.handleDefaultSave}>{getLabel(111, "保存")}</Button>
],
children: <LedgerAccountApprRule {...this.props} ref={dom => this.approRef = dom}
saveSalarySobId={saveSalarySobId}/>
}
];
(taxableItems && taxableItems.toString() !== "1" && taxableItems.toString() !== "489") &&
(tabs = _.map(_.filter(tabs, o => o.key !== 7), (k, j) => ({ ...k, key: j })));
!salaryApprovalStatus && tabs.pop();
return (
<WeaSlideModal
className="ledgerSlideLayout slideOuterWrapper"
visible={visible}
top={0}
width={100}
height={100}
direction="right"
measure="%"
title={
!editId ? <WeaTopTitle buttons={_.find(tabs, o => current === o.key).createBtns}/> :
<WeaReqTitle buttons={showOperateBtn ? _.find(tabs, o => current === o.key).editBtns : []}
tabDatas={tabs} selectedKey={String(current)}
onChange={cur => this.setState({ current: parseInt(cur) })}/>
}
content={
<div className="ledgerSlideContent">
{
!editId &&
<WeaSteps current={current} style={{ margin: "20px 0" }}>
{
_.map(tabs, item => {
const { key, title } = item;
return <Step description={title} key={key}/>;
})
}
</WeaSteps>
}
{_.find(tabs, o => current === o.key).children}
</div>
}
onClose={this.handleClose}
/>
);
}
}
export default LedgerSlide;