salary-management-front/pc4mobx/hrmSalary/pages/custom-pages/lingyue/components/generateDataDialog.js

92 lines
2.8 KiB
JavaScript

/*
* 领悦报表生成数据弹窗
*
* @Author: 黎永顺
* @Date: 2024/8/28
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
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 * as API from "../../../../apis/custom-apis/lingyue";
import { dataConditions } from "./conditions";
const getLabel = WeaLocaleProvider.getLabel;
const APIFOX = {
"salarySum": API.generateSalaryReport,
"socialFundSum": API.generateSIReport,
"fundSum": API.generateFundReport
};
@inject("LYStore")
@observer
class GenerateDataDialog extends Component {
constructor(props) {
super(props);
this.state = {
loading: false, conditions: []
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) this.initLYForm(nextProps);
if (nextProps.visible !== this.props.visible && !nextProps.visible) nextProps.LYStore.initDataForm();
}
initLYForm = (props) => {
const { type } = props || this.props;
this.setState({
conditions: _.map(dataConditions, item => ({
...item,
items: _.map(item.items, o => ({
...o, label: type === "salarySum" ? getLabel(111, "薪资所属月") : getLabel(o.lanId, o.label)
}))
}))
}, () => {
const { LYStore: { dataForm } } = this.props;
dataForm.initFormFields(this.state.conditions);
});
};
save = () => {
const { LYStore: { dataForm }, type, onSearch } = this.props;
dataForm.validateForm().then(f => {
if (f.isValid) {
this.setState({ loading: true });
const payload = { ...dataForm.getFormParams() };
APIFOX[type](payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(30700, "操作成功!"));
this.props.onCancel(onSearch());
} else {
message.error(errormsg);
}
});
} else {
f.showErrors();
}
}).catch(() => this.setState({ loading: false }));
};
render() {
const { conditions, loading } = this.state;
const { LYStore: { dataForm } } = this.props;
return (
<WeaDialog
{...this.props} style={{ width: 480, height: 80 }} initLoadCss title={getLabel(111, "生成数据")}
buttons={[
<Button type="primary" onClick={this.save} loading={loading}>{getLabel(537558, "保存")}</Button>
]}
>
<div className="form-dialog-layout">{getSearchs(dataForm, conditions, 1, false)}</div>
</WeaDialog>
);
}
}
export default GenerateDataDialog;