salary-management-front/pc4mobx/hrmSalary/pages/variableSalary/components/salaryFileImportDialog/index.js

97 lines
3.5 KiB
JavaScript

/*
* 浮动薪酬
* 薪资档案导入
* @Author: 黎永顺
* @Date: 2024/8/8
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { WeaCheckbox, WeaLocaleProvider } from "ecCom";
import ImportDialog from "../../../../components/importDialog";
import * as API from "../../../../apis/variableSalary";
import { convertToUrlString } from "../../../../util/url";
const getLabel = WeaLocaleProvider.getLabel;
class Index extends Component {
constructor(props) {
super(props);
this.state = {
importDialog: {
nextloading: false, link: "/api/bs/hrmsalary/variableSalary/downloadTemplate",
importResult: {}, imageId: "", hasData: false,
previewUrl: "/api/bs/hrmsalary/variableSalary/preview"
}
};
}
componentWillReceiveProps(nextProps, nextContext) {
const { importDialog } = this.state;
if (nextProps.visible !== this.props.visible && nextProps.visible) {
const { baseTableStore: { VSalryForm }, salaryMonth, taxAgentIds } = nextProps;
const payload = {
salaryMonth, taxAgentIds, ...VSalryForm.getFormParams(), hasData: importDialog.hasData
};
this.setState({ importDialog: { ...importDialog, link: `${importDialog.link}?${convertToUrlString(payload)}` } });
} else {
this.setState({
importDialog: {
nextloading: false, link: "/api/bs/hrmsalary/variableSalary/downloadTemplate", hasData: false,
importResult: {}, imageId: "", previewUrl: "/api/bs/hrmsalary/variableSalary/preview"
}
});
}
}
handleImport = (payload) => {
const { salaryMonth, taxAgentIds } = this.props;
const { importDialog } = this.state;
this.setState({ importDialog: { ...importDialog, nextloading: true } });
API.importVariableSalary({
...payload, salaryMonth, taxAgentIds: _.isEmpty(taxAgentIds) ? [] : taxAgentIds.split(",")
}).then(({ data, status }) => {
this.setState({ importDialog: { ...importDialog, nextloading: false } });
if (status) {
this.setState({
importDialog: { ...importDialog, ...payload, importResult: data }
});
}
}).catch(() => this.setState({ importDialog: { ...importDialog, nextloading: false } }));
};
render() {
const { importDialog } = this.state;
return (
<ImportDialog
{...this.props} {...importDialog}
onResetImportResult={() => this.setState({
importDialog: { ...importDialog, importResult: {}, imageId: "", link: null }
})}
exportDataDom={
<WeaCheckbox
value={importDialog.hasData ? "1" : "0"}
content={getLabel(543208, "导出现有数据")}
helpfulTip={getLabel(111, "提示:建议先导出现有最新数据,修改后再导入")}
onChange={val => {
const { baseTableStore: { VSalryForm }, salaryMonth, taxAgentIds } = this.props;
const payload = { salaryMonth, taxAgentIds, ...VSalryForm.getFormParams(), hasData: val === "1" };
this.setState({
importDialog: {
...importDialog, hasData: val === "1",
link: `/api/bs/hrmsalary/variableSalary/downloadTemplate?${convertToUrlString(payload)}`
}
});
}}
/>
}
nextCallback={imageId => this.setState({ importDialog: { ...importDialog, imageId } })}
nextUplaodCallback={imageId => this.handleImport({ imageId })}
/>
);
}
}
export default Index;