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

312 lines
9.9 KiB
JavaScript
Raw Normal View History

2022-12-08 17:18:56 +08:00
/*
* Author: 黎永顺
* name: 新增编辑薪资账套
* Description:
* Date: 2022/12/8
*/
import React, { Component } from "react";
2022-12-08 17:27:04 +08:00
import { inject, observer } from "mobx-react";
import { WeaSlideModal, WeaSteps } from "ecCom";
2022-12-09 14:16:11 +08:00
import { Button, message, Modal } from "antd";
2022-12-08 17:27:04 +08:00
import SlideModalTitle from "../../../components/slideModalTitle";
2022-12-09 14:16:11 +08:00
import LedgerBaseSetting from "./ledgerBaseSetting";
2022-12-12 11:38:43 +08:00
import LedgerAssociatedPersonnel from "./ledgerAssociatedPersonnel";
2022-12-12 15:16:10 +08:00
import LedgerSalaryAdjustmentRules from "./ledgerSalaryAdjustmentRules";
2022-12-13 16:10:48 +08:00
import LedgerBackCalculatedSalaryItem from "./ledgerBackCalculatedSalaryItem";
2022-12-14 15:37:55 +08:00
import LedgerSalaryItem from "./ledgerSalaryItem";
import { saveAdjustmentRule, saveLedgerBasic, saveLedgerItem } from "../../../apis/ledger";
2022-12-09 14:16:11 +08:00
import "./index.less";
2022-12-08 17:18:56 +08:00
2022-12-08 17:27:04 +08:00
const Step = WeaSteps.Step;
const tabs = [
{ key: 0, title: "基础设置" },
{ key: 1, title: "关联人员" },
2022-12-12 11:38:43 +08:00
{ key: 2, title: "薪资项目" },
{ key: 3, title: "回算薪资项目" },
{ key: 4, title: "调薪计薪规则" }
2022-12-08 17:27:04 +08:00
];
2023-07-24 18:22:24 +08:00
@inject("taxAgentStore", "ledgerStore")
2022-12-08 17:27:04 +08:00
@observer
2022-12-08 17:18:56 +08:00
class LedgerSlide extends Component {
2022-12-08 17:27:04 +08:00
constructor(props) {
super(props);
this.state = {
current: 0,
loading: false,
2022-12-13 16:10:48 +08:00
baseSettingInfo: {},
2022-12-14 15:37:55 +08:00
adjustRules: [],
empFields: [], itemGroups: [],
saveSalarySobId: ""
2022-12-08 17:27:04 +08:00
};
}
2022-12-14 15:37:55 +08:00
componentWillUnmount() {
this.setState({
saveSalarySobId: ""
});
}
2022-12-13 16:10:48 +08:00
/*
* Author: 黎永顺
* Description: 保存基本信息
* Params:
* Date: 2022/12/12
*/
2022-12-09 14:16:11 +08:00
saveLedgerBasic = () => {
const { baseSettingInfo, current } = this.state;
2022-12-12 10:24:07 +08:00
const { editId } = this.props;
const { description, canEdit, ...extra } = baseSettingInfo;
const bool = _.every(Object.keys(extra), key => !!extra[key]);
2022-12-09 14:16:11 +08:00
if (!bool || _.isEmpty(baseSettingInfo)) {
Modal.warning({
title: "信息确认",
content: "必要信息不完整,红色*为必填项!"
});
return false;
}
this.setState({ loading: true });
2022-12-14 15:37:55 +08:00
saveLedgerBasic({ ...extra, description, id: editId }).then(({ status, data, errormsg }) => {
2022-12-09 14:16:11 +08:00
this.setState({ loading: false });
if (status) {
const { onRefreshList } = this.props;
message.success("保存成功");
onRefreshList();
2022-12-14 15:37:55 +08:00
!editId && this.setState({ current: current + 1, saveSalarySobId: data });
2022-12-09 14:16:11 +08:00
} else {
message.error(errormsg || "保存失败");
}
}).catch(() => this.setState({ loading: false }));
};
2022-12-13 16:10:48 +08:00
/*
* Author: 黎永顺
* Description: 保存调薪计薪规则
* Params:
* Date: 2022/12/12
*/
saveLedgerAdjustRule = () => {
2022-12-14 15:37:55 +08:00
const { adjustRules, saveSalarySobId } = this.state;
2022-12-13 16:10:48 +08:00
const payload = {
2022-12-14 15:37:55 +08:00
salarySobId: this.props.editId || saveSalarySobId,
2022-12-13 16:10:48 +08:00
ruleParams: adjustRules
};
this.setState({ loading: true });
saveAdjustmentRule(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success("保存成功");
2022-12-14 15:37:55 +08:00
this.handleClose();
2022-12-13 16:10:48 +08:00
} else {
message.success(errormsg || "保存失败");
}
}).catch(() => this.setState({ loading: false }));
2022-12-14 15:37:55 +08:00
};
/*
* Author: 黎永顺
* Description: 薪资项目保存
* Params:
* Date: 2022/12/14
*/
saveLedgerItem = () => {
const { empFields, itemGroups, saveSalarySobId } = this.state;
const { editId: salarySobId } = this.props;
const payload = {
2023-02-17 11:18:09 +08:00
empFields: _.map(empFields, it => {
if (Object.prototype.toString.call(it.id) === "[object Number]") delete it.id;
return { ...it };
}),
2023-02-09 15:36:23 +08:00
itemGroups: _.map(_.filter(itemGroups, it => it.name !== "未分类"), item => {
return {
...item,
items: _.map(item.items, it => {
// delete it.formulaContent;
2023-02-27 18:28:05 +08:00
// if (it.id && it.id.length > 4) delete it.id;
2023-02-09 15:36:23 +08:00
return { ...it };
})
};
}),
items: _.map(_.find(itemGroups, it => it.name === "未分类").items, child => {
2023-02-28 18:16:17 +08:00
// if (child.id && child.id.length > 4) delete child.id;
// delete child.formulaContent;
2023-02-09 15:36:23 +08:00
return { ...child };
}) || [],
2022-12-14 15:37:55 +08:00
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 }));
};
2022-12-08 17:27:04 +08:00
handleChangeSlideTab = (current) => {
this.setState({ current: Number(current) });
};
2022-12-09 14:16:11 +08:00
handleClose = () => {
this.setState({ current: 0 }, () => this.props.onCancel());
};
/*
* Author: 黎永顺
* Description: 基础信息字段切换
* Params:
* Date: 2022/12/9
*/
handleChangeSaveParams = (baseSettingInfo) => {
this.setState({ baseSettingInfo });
};
2022-12-14 15:37:55 +08:00
/*
* Author: 黎永顺
* Description: 薪资项目保存数据
* Params:
* Date: 2022/12/14
*/
handleSaveSalaryItemParams = (empFields, itemGroups) => {
this.setState({ empFields, itemGroups });
};
2022-12-08 17:27:04 +08:00
renderChildren = () => {
2022-12-14 15:37:55 +08:00
const { current, saveSalarySobId } = this.state;
2022-12-08 17:27:04 +08:00
let CurrentDom = null;
switch (current) {
case 0:
2022-12-09 14:16:11 +08:00
CurrentDom = <LedgerBaseSetting {...this.props} onSaveParams={this.handleChangeSaveParams}/>;
2022-12-08 17:27:04 +08:00
break;
2022-12-12 11:38:43 +08:00
case 1:
2022-12-14 15:37:55 +08:00
CurrentDom = <LedgerAssociatedPersonnel {...this.props} saveSalarySobId={saveSalarySobId}/>;
break;
case 2:
CurrentDom = <LedgerSalaryItem {...this.props} saveSalarySobId={saveSalarySobId}
onSaveSalaryItem={this.handleSaveSalaryItemParams}/>;
2022-12-12 11:38:43 +08:00
break;
2022-12-13 16:10:48 +08:00
case 3:
2022-12-14 15:37:55 +08:00
CurrentDom = <LedgerBackCalculatedSalaryItem {...this.props} saveSalarySobId={saveSalarySobId}/>;
2022-12-13 16:10:48 +08:00
break;
2022-12-12 15:16:10 +08:00
case 4:
2022-12-13 16:10:48 +08:00
CurrentDom =
2022-12-14 15:37:55 +08:00
<LedgerSalaryAdjustmentRules {...this.props} saveSalarySobId={saveSalarySobId}
onSaveParams={(adjustRules) => this.setState({ adjustRules })}/>;
2022-12-12 15:16:10 +08:00
break;
2022-12-08 17:27:04 +08:00
default:
CurrentDom = null;
break;
}
return CurrentDom;
};
2022-12-09 14:16:11 +08:00
renderCustomOperate = () => {
const { taxAgentStore: { showOperateBtn }, editId } = this.props;
const { current, loading } = this.state;
let CurrentDom = [];
//管理员操作权限
if (showOperateBtn) {
switch (current) {
case 0:
CurrentDom = [
<Button
type="primary"
loading={loading}
onClick={this.saveLedgerBasic}
>{editId ? "保存" : "保存并进入下一步"}</Button>
];
break;
case 1:
2022-12-12 11:38:43 +08:00
CurrentDom = !editId ? [
2022-12-14 15:37:55 +08:00
<Button type="ghost" onClick={this.handleClose}>完成跳过所有步骤</Button>,
2022-12-09 14:16:11 +08:00
<Button type="primary" onClick={() => this.setState({ current: current + 1 })}>下一步</Button>
2022-12-12 11:38:43 +08:00
] : [];
2022-12-09 14:16:11 +08:00
break;
case 2:
CurrentDom = !editId ?
[
2022-12-14 15:37:55 +08:00
<Button type="ghost" onClick={this.handleClose}>完成跳过所有步骤</Button>,
2022-12-09 14:16:11 +08:00
<Button type="ghost" onClick={() => this.setState({ current: current - 1 })}>上一步</Button>,
2022-12-14 15:37:55 +08:00
<Button
type="primary"
loading={loading}
onClick={() => {
this.setState({ current: current + 1 }, () => {
this.saveLedgerItem();
});
}}
>保存并进入下一步</Button>
] : [
<Button type="primary" loading={loading} onClick={this.saveLedgerItem}>保存</Button>
];
2022-12-09 14:16:11 +08:00
break;
case 3:
CurrentDom = !editId ?
[
2022-12-14 15:37:55 +08:00
<Button type="ghost" onClick={this.handleClose}>完成跳过所有步骤</Button>,
2022-12-09 14:16:11 +08:00
<Button type="ghost" onClick={() => this.setState({ current: current - 1 })}>上一步</Button>,
2022-12-14 15:37:55 +08:00
<Button type="primary" onClick={() => this.setState({ current: current + 1 })}>下一步</Button>
2022-12-09 14:16:11 +08:00
] : [];
break;
case 4:
CurrentDom = !editId ?
[
<Button type="ghost" onClick={() => this.setState({ current: current - 1 })}>上一步</Button>,
2022-12-13 16:10:48 +08:00
<Button type="primary" loading={loading} onClick={this.saveLedgerAdjustRule}>完成</Button>
2022-12-12 15:16:10 +08:00
] : [
2022-12-13 16:10:48 +08:00
<Button type="primary" loading={loading} onClick={this.saveLedgerAdjustRule}>保存</Button>
2022-12-12 15:16:10 +08:00
];
2022-12-09 14:16:11 +08:00
break;
default:
break;
}
}
return CurrentDom;
};
2022-12-08 17:27:04 +08:00
2022-12-08 17:18:56 +08:00
render() {
2022-12-12 10:24:07 +08:00
const { title, visible, editId, taxAgentStore: { showOperateBtn } } = this.props;
const { current } = this.state;
2022-12-08 17:18:56 +08:00
return (
2022-12-08 17:27:04 +08:00
<WeaSlideModal
className="slideOuterWrapper"
visible={visible}
top={0}
2022-12-09 14:16:11 +08:00
width={65}
2022-12-08 17:27:04 +08:00
height={100}
direction="right"
measure="%"
title={
<SlideModalTitle
subtitle={title}
2022-12-12 10:24:07 +08:00
tabs={editId ? tabs : []}
2022-12-08 17:27:04 +08:00
loading={false}
showOperateBtn={showOperateBtn}
editable={false}
onSave={() => {
}}
selectedTab={current}
customOperate={this.renderCustomOperate()}
subItemChange={this.handleChangeSlideTab}
/>
}
content={
2022-12-09 14:16:11 +08:00
<div className="ledgerSlideContent">
2022-12-08 17:27:04 +08:00
{
2022-12-12 10:24:07 +08:00
!editId &&
2022-12-08 17:27:04 +08:00
<WeaSteps current={current} style={{ margin: "20px 0" }}>
{
_.map(tabs, item => {
const { key, title } = item;
return <Step description={title} key={key}/>;
})
}
</WeaSteps>
}
{
this.renderChildren()
}
</div>
}
2022-12-09 14:16:11 +08:00
onClose={this.handleClose}
2022-12-08 17:27:04 +08:00
/>
2022-12-08 17:18:56 +08:00
);
}
}
export default LedgerSlide;