/* * Author: 黎永顺 * name: 社保福利台账-核算-导入 * Description: * Date: 2024/3/5 */ import React, { Component } from "react"; import { WeaLocaleProvider } from "ecCom"; import { Badge, Button, message } from "antd"; import ImportDialog from "../../../../components/importDialog"; import ImportHeaderSetDialog from "./importHeaderSetDialog"; import * as API from "../../../../apis/standingBook"; const getLabel = WeaLocaleProvider.getLabel; class StandingBookCalcImportDialog extends Component { constructor(props) { super(props); this.state = { headerFieldsDialog: { visible: false, itemsByGroup: [], selectItems: [] }, importDialog: { visible: false, title: "", nextloading: false, link: null, importResult: {}, imageId: "", previewUrl: "/api/bs/hrmsalary/siaccount/welfare/preview" } }; } async componentWillReceiveProps(nextProps, nextContext) { if (nextProps.visible !== this.props.visible && nextProps.visible) { const { fieldUrl } = nextProps; const { data } = await API[fieldUrl](); this.setState({ importDialog: { ...this.state.importDialog, importResult: {}, link: this.handleExportTemp, title: getLabel(24023, "数据导入") }, headerFieldsDialog: { ...this.state.headerFieldsDialog, itemsByGroup: data, selectItems: _.map(_.filter(data, k => k.checked), o => o.fieldId) } }); } this.setState({ importDialog: { ...this.state.importDialog, visible: nextProps.visible } }); } handleImport = (payload) => { const { importDialog, headerFieldsDialog: { selectItems } } = this.state; if (_.isEmpty(selectItems)) { message.error(getLabel(111, "请选择表头字段")); } else { const { importUrl, importparams = {} } = this.props; this.setState({ importDialog: { ...importDialog, nextloading: true } }); API[importUrl]({ ...payload, ...importparams }).then(({ data, status, errormsg }) => { this.setState({ importDialog: { ...importDialog, nextloading: false } }); if (status) { this.setState({ importDialog: { ...importDialog, ...payload, importResult: data } }); } else { message.warning(errormsg); } }).catch(() => this.setState({ importDialog: { ...importDialog, nextloading: false } })); } }; handleExportTemp = () => { const { tmpUrl, billMonth, paymentOrganization } = this.props; const { headerFieldsDialog: { selectItems, itemsByGroup } } = this.state; if (_.isEmpty(selectItems)) { message.error(getLabel(111, "请选择表头字段")); } else { const payload = { billMonth, paymentOrganization: Number(paymentOrganization), welfareNames: _.map(_.filter(itemsByGroup, k => selectItems.includes(k.fieldId)), o => o.salaryItemName) }; const promise = API[tmpUrl](payload); } }; handleSelectedField = () => { this.setState({ headerFieldsDialog: { ...this.state.headerFieldsDialog, visible: true } }); }; /* * Author: 黎永顺 * Description:表单选项 * Params: * Date: 2023/9/18 */ renderFormComponent = () => { const { selectItems } = this.state.headerFieldsDialog; return
; }; render() { const { importDialog, headerFieldsDialog } = this.state; const { cacheUrl } = this.props; return ( this.setState(({ importDialog: { ...importDialog, importResult: {}, imageId: "" } }))} nextCallback={imageId => this.setState({ importDialog: { ...importDialog, imageId } })} nextUplaodCallback={imageId => this.handleImport({ imageId })} /> {/*表头设置*/} this.setState({ headerFieldsDialog: { ...headerFieldsDialog, visible: false } })} onAdd={selectItems => this.setState({ headerFieldsDialog: { ...headerFieldsDialog, visible: false, selectItems } }, () => { const { selectItems: welfareNames } = this.state.headerFieldsDialog; const promise = API[cacheUrl]({ welfareNames }); })} /> ); } } export default StandingBookCalcImportDialog;