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

148 lines
6.4 KiB
JavaScript
Raw Normal View History

2022-12-12 16:10:11 +08:00
/*
* Author: 黎永顺
* name: 新增调薪计薪规
* Description:
* Date: 2022/12/12
*/
import React, { Component } from "react";
2025-02-18 15:42:40 +08:00
import { inject, observer } from "mobx-react";
2025-02-18 15:48:37 +08:00
import { WeaDialog, WeaFormItem, WeaHelpfulTip, WeaLocaleProvider, WeaSelect, WeaTools } from "ecCom";
2025-02-18 15:42:40 +08:00
import FormInfo from "../../../components/FormInfo";
import { WeaSwitch } from "comsMobx";
2025-02-18 17:30:21 +08:00
import { Button } from "antd";
2022-12-12 16:10:11 +08:00
import { listSalarySobItem } from "../../../apis/ledger";
2025-02-18 15:42:40 +08:00
import { monthDays, ruleConditions } from "../config";
2025-02-18 17:30:21 +08:00
import "./index.less";
2022-12-12 16:10:11 +08:00
2025-02-18 15:42:40 +08:00
const { getLabel } = WeaLocaleProvider;
const getKey = WeaTools.getKey;
@inject("ledgerStore")
@observer
2022-12-12 16:10:11 +08:00
class LedgerAdjustRuleAddModal extends Component {
constructor(props) {
super(props);
2025-02-18 17:30:21 +08:00
this.state = { conditions: [] };
2022-12-12 16:10:11 +08:00
}
componentWillReceiveProps(nextProps, nextContext) {
2025-02-18 15:42:40 +08:00
if (nextProps.visible !== this.props.visible && nextProps.visible) this.listSalarySobItem(nextProps.salarySobId);
2025-02-18 17:30:21 +08:00
if (nextProps.visible !== this.props.visible && !nextProps.visible) this.props.ledgerStore.initRuleForm();
2022-12-12 16:10:11 +08:00
}
2022-12-13 16:10:48 +08:00
listSalarySobItem = (salarySobId) => {
2022-12-14 15:37:55 +08:00
const { salaryRuleItemsList } = this.props;
2022-12-12 16:10:11 +08:00
const payload = {
2025-02-18 15:42:40 +08:00
excludeSalaryItemIds: _.map(salaryRuleItemsList, item => item.salaryItemId), salarySobId
2022-12-12 16:10:11 +08:00
};
listSalarySobItem(payload).then(({ status, data }) => {
if (status) {
this.setState({
2025-02-18 15:42:40 +08:00
conditions: _.map(ruleConditions, item => ({
...item, items: _.map(item.items, o => {
2025-02-18 17:30:21 +08:00
o = { ...o, label: getLabel(o.lanId, o.label) };
2025-02-18 15:42:40 +08:00
if (getKey(o) === "salaryItemId") {
return {
2025-02-18 17:30:21 +08:00
...o, options: _.map(data, it => ({ key: it.salaryItemId.toString(), showname: it.salaryItemName }))
2025-02-18 15:42:40 +08:00
};
} else if (getKey(o) === "dayOfMonth") {
2025-02-18 17:30:21 +08:00
return { ...o, options: monthDays };
} else if (getKey(o) === "beforeAdjustmentType" || getKey(o) === "afterAdjustmentType") {
return {
...o,
options: _.map(o.options, k => ({
...k,
showname: !k.helpfultip ? getLabel(k.lanId, k.showname) : <span>
<span style={{ marginRight: 4 }}>{getLabel(k.lanId, k.showname)}</span>
2025-02-18 17:34:03 +08:00
<WeaHelpfulTip title={`=${getLabel(k.helpfultiplanId, k.helpfultip)}`}/>
2025-02-18 17:30:21 +08:00
</span>
}))
};
2025-02-18 15:42:40 +08:00
}
2025-02-18 17:30:21 +08:00
return o;
2025-02-18 15:42:40 +08:00
})
}))
}, () => this.props.ledgerStore.ruleForm.initFormFields(this.state.conditions));
2022-12-12 16:10:11 +08:00
}
});
};
2022-12-13 16:10:48 +08:00
handleSave = () => {
2025-02-18 17:30:21 +08:00
const { salaryRuleItemsList, onSave, ledgerStore: { ruleForm } } = this.props;
ruleForm.validateForm().then(f => {
if (f.isValid) {
const { salaryItemId } = ruleForm.getFormParams(), { fieldMap } = ruleForm;
const fields = _.map(salaryItemId.split(","), o => ({
...ruleForm.getFormParams(),
salaryItemId: o,
salaryItemName: _.find(fieldMap["salaryItemId"]["options"], k => k.key === o).showname
}));
this.props.onCancel(onSave([...salaryRuleItemsList, ...fields]));
} else {
f.showErrors();
}
2022-12-13 16:10:48 +08:00
});
};
2022-12-12 16:10:11 +08:00
render() {
2025-02-19 16:26:58 +08:00
const { ledgerStore: { ruleForm } } = this.props, { conditions } = this.state;
2025-02-18 15:42:40 +08:00
const buttons = [<Button type="primary" onClick={this.handleSave}>{getLabel(111, "保存")}</Button>];
const itemRender = {
salaryItemId: (field, textAreaProps, form, formParams) => {
return (<WeaSwitch fieldConfig={{ ...field, ...textAreaProps }} form={form} formParams={formParams}/>);
},
2025-02-18 17:30:21 +08:00
dayOfMonth: () => null,
beforeAdjustmentType: () => null,
afterAdjustmentType: () => null
2025-02-18 15:42:40 +08:00
};
const childrenComponents = {
salaryItemId: () => {
2025-02-18 17:30:21 +08:00
const { dayOfMonth, beforeAdjustmentType, afterAdjustmentType } = ruleForm.getFormParams();
2025-02-18 15:42:40 +08:00
const coms = [], { fieldMap } = ruleForm;
coms.push(
2025-02-18 17:30:21 +08:00
<WeaFormItem label={<span>
<span className="title">{getLabel(111, "计薪规则")}</span>
<WeaHelpfulTip
title={getLabel(111, "该规则适用于一个薪资核算周期内只调整一次薪资或个税扣缴义务人的情况,其他情况默认按照分段计薪规则核算")}/>
</span>} labelCol={{ span: 6 }} wrapperCol={{ span: 18 }}>
2025-02-18 15:42:40 +08:00
<div className="cust">
<div className="child">
<div className="lbl">{fieldMap["dayOfMonth"].label}</div>
2025-02-18 17:30:21 +08:00
<WeaSelect value={dayOfMonth} options={monthDays} style={{ width: 100 }}
onChange={v => ruleForm.updateFields({ dayOfMonth: { value: v } })}/>
2025-02-18 15:48:37 +08:00
<div className="rbl">{getLabel(111, "(含)之前")}</div>
2022-12-12 16:10:11 +08:00
</div>
2025-02-18 17:30:21 +08:00
<div className="child">
<div className="lbl">{fieldMap["beforeAdjustmentType"].label}</div>
<WeaSelect value={beforeAdjustmentType} detailtype={fieldMap["beforeAdjustmentType"]["detailtype"]}
options={fieldMap["beforeAdjustmentType"]["options"]} style={{ flex: 1 }}
onChange={v => ruleForm.updateFields({ beforeAdjustmentType: { value: v } })}/>
</div>
<div className="child">
<div className="lbl">{getLabel(111, "否则调薪生效日期在10号之后")}</div>
</div>
<div className="child">
<div className="lbl">{fieldMap["afterAdjustmentType"].label}</div>
<WeaSelect value={afterAdjustmentType} detailtype={fieldMap["afterAdjustmentType"]["detailtype"]}
options={fieldMap["afterAdjustmentType"]["options"]} style={{ flex: 1 }}
onChange={v => ruleForm.updateFields({ afterAdjustmentType: { value: v } })}/>
</div>
2022-12-12 16:10:11 +08:00
</div>
</WeaFormItem>
2025-02-18 15:42:40 +08:00
);
2025-02-18 17:30:21 +08:00
return [{ com: <div className="calcRules">{coms}</div>, col: 1 }];
2025-02-18 15:42:40 +08:00
}
};
return (
2025-02-18 17:30:21 +08:00
<WeaDialog {...this.props} initLoadCss style={{ width: 750, height: 236 }} buttons={buttons}
className="adjustRuleModalWrapper">
2025-02-18 15:42:40 +08:00
<FormInfo className="form-dialog-layout" center={false} itemRender={itemRender}
childrenComponents={childrenComponents} form={ruleForm} formFields={conditions}/>
2022-12-12 16:10:11 +08:00
</WeaDialog>
);
}
}
export default LedgerAdjustRuleAddModal;