salary-management-front/pc4mobx/hrmSalary/pages/socialSecurityBenefits/standingBook/standingBook.js

148 lines
5.6 KiB
JavaScript
Raw Normal View History

/*
* Author: 黎永顺
* name: 社保福利台账重构
* version: 1.0
* Description:
* Date: 2024/1/23
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaLocaleProvider, WeaTop } from "ecCom";
import { Button, message } from "antd";
import * as API from "../../../apis/standingBook";
import { getCalculateProgress } from "../../../apis/calculate";
import WelfareRecordQuery from "./components/welfareRecordQuery";
import WelfareRecordList from "./components/welfareRecordList";
import Accountdialog from "./components/accountDialog";
import ProgressModal from "../../../components/progressModal";
import { convertToUrlString } from "../../../util/url";
import moment from "moment";
import "./index.less";
const getLabel = WeaLocaleProvider.getLabel;
@inject("standingBookStore", "taxAgentStore")
@observer
class StandingBook extends Component {
constructor(props) {
super(props);
this.state = {
queryForm: {
startTime: moment(new Date()).subtract(1, "year").startOf("year").format("YYYY-MM"),
endTime: moment(new Date()).endOf("year").format("YYYY-MM"),
taxAgents: ""
}, progressVisible: false, progress: 0,
accountDialog: { visible: false, title: "", loading: false, options: [] }
};
this.wfListRef = null;
this.timer = null;
}
/*
* Author: 黎永顺
* Description: 社保福利台账重构-核算
* Params:
* Date: 2024/1/23
*/
handleAccount = async (formVal) => {
const { billMonth, ...extra } = formVal;
const payload = {
billMonth: moment(billMonth).format("YYYY-MM"),
...extra
};
this.setState({ accountDialog: { ...this.state.accountDialog, loading: true } });
const { data: creator, status, errormsg } = await API.save(payload);
if (status) {
this.setState({
accountDialog: { ...this.state.accountDialog, loading: false },
progressVisible: true
}, () => {
this.timer = setInterval(() => {
getCalculateProgress(moment(billMonth).format("YYYY-MM")).then(({ status, data }) => {
if (status) {
if (!data.status) {
clearInterval(this.timer);
this.setState({ progressVisible: false, progress: 0 });
message.error(data.message);
return;
}
if (this.state.progress !== 100) {
this.setState({
progress: (Number(data.progress).toFixed(2)) * 100
});
} else {
clearInterval(this.timer);
this.setState({ progressVisible: false, progress: 0 }, () => {
message.success(getLabel(543232, "核算成功"));
this.setState({
accountDialog: { ...this.state.accountDialog, visible: false }
}, () => {
this.wfListRef.wrappedInstance.getWelfareRecordList();
const calcPayload = { ...payload, creator };
window.open(`/spa/hrmSalary/static/index.html#/main/hrmSalary/socialSecurityBenefits/standingBookDetail?${convertToUrlString(calcPayload)}`);
});
});
}
} else {
clearInterval(this.timer);
this.setState({ progressVisible: false, progress: 0 });
}
}).catch(() => {
clearInterval(this.timer);
this.setState({ progressVisible: false, progress: 0 });
});
}, 600);
});
} else {
message.error(errormsg);
clearInterval(this.timer);
this.setState({
accountDialog: { ...this.state.accountDialog, loading: false },
progressVisible: false, progress: 0
});
}
};
render() {
const { accountDialog, queryForm } = this.state;
const { taxAgentStore: { showOperateBtn } } = this.props;
const rightBtns = [<Button type="primary" onClick={() => this.setState({
accountDialog: { ...accountDialog, visible: true, title: getLabel(538780, "核算") }
})}>{getLabel(538780, "核算")}</Button>];
return (
<div className="salary-welfare-record">
<WeaTop title={getLabel(538002, "社保福利台账")} icon={<i className="icon-coms-fa"/>}
iconBgcolor="#F14A2D" buttons={showOperateBtn ? rightBtns : []}>
<div className="salary-welfare-record-content">
<WelfareRecordQuery
onSearch={(payload) => {
this.setState({
queryForm: { ...queryForm, ...payload }
}, () => this.wfListRef.wrappedInstance.getWelfareRecordList());
}}
onPutAccountOptions={options => this.setState({ accountDialog: { ...accountDialog, options } })}
/>
<WelfareRecordList ref={dom => this.wfListRef = dom} queryForm={queryForm}/>
</div>
<Accountdialog {...accountDialog}
onCancel={() => this.setState({
accountDialog: { ...accountDialog, visible: false, title: "", loading: false }
})} onOk={this.handleAccount}
/>
{/*核算进度条*/}
{
this.state.progressVisible &&
<ProgressModal visible={this.state.progressVisible} progress={this.state.progress}
onCancel={() => {
this.setState({ progressVisible: false, progress: 0 }, () => clearInterval(this.timer));
}}
/>
}
</WeaTop>
</div>
);
}
}
export default StandingBook;