salary-management-front/pc4mobx/hrmSalary/pages/payrollRelease/components/payrollCopyDialog/index.js

70 lines
2.2 KiB
JavaScript

/*
* Author: 黎永顺
* name:工资单发放-重构页面-工资单模板复制
* Description:
* Date: 2023/10/13
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaDialog, WeaLocaleProvider } from "ecCom";
import { Button, message } from "antd";
import { getSearchs } from "../../../../util";
import { copyConditions } from "../conditions";
import { duplicatePayroll } from "../../../../apis/payroll";
const getLabel = WeaLocaleProvider.getLabel;
@inject("payrollStore")
@observer
class Index extends Component {
constructor(props) {
super(props);
this.state = {
loading: false
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) nextProps.payrollStore.payrollCopyForm.initFormFields(copyConditions);
if (nextProps.visible !== this.props.visible && !nextProps.visible) nextProps.payrollStore.initPayrollCopyForm();
}
save = () => {
const { payrollStore: { payrollCopyForm }, copyId: id } = this.props;
payrollCopyForm.validateForm().then(f => {
if (f.isValid) {
const payload = payrollCopyForm.getFormParams();
this.setState({ loading: true });
duplicatePayroll({ id, ...payload }).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(30700, "操作成功!"));
this.props.onCancel("refresh");
} else {
message.error(errormsg);
}
});
} else {
f.showErrors();
}
}).catch(() => this.setState({ loading: false }));
};
render() {
const { loading } = this.state;
const { payrollStore: { payrollCopyForm } } = this.props;
return (
<WeaDialog
{...this.props} style={{ width: 480 }} initLoadCss
buttons={[
<Button type="primary" onClick={this.save} loading={loading}>{getLabel(537558, "保存")}</Button>
]}
>
<div className="payroll-dialog-layout">{getSearchs(payrollCopyForm, copyConditions, 1, false)}</div>
</WeaDialog>
);
}
}
export default Index;