salary-management-front/pc4mobx/hrmSalary/pages/declare/components/declareDialog/index.js

126 lines
4.5 KiB
JavaScript

/*
* Author: 黎永顺
* name: 个税申报重构- 申报
* Description:
* Date: 2023/10/12
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaDialog, WeaLocaleProvider, WeaTools } from "ecCom";
import { Button, message } from "antd";
import { getSearchs } from "../../../../util";
import { getTaxAgentSelectListAsAdmin } from "../../../../apis/taxAgent";
import { saveDeclare, taxdeclarationGetRate } from "../../../../apis/declare";
import { declareConditions } from "./condition";
import * as API from "../../../../apis/ruleconfig";
const getKey = WeaTools.getKey;
const getLabel = WeaLocaleProvider.getLabel;
@inject("declareStore")
@observer
class Index extends Component {
constructor(props) {
super(props);
this.state = {
conditions: [], loading: false
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) this.getTaxAgentSelectListAsAdmin(nextProps);
if (nextProps.visible !== this.props.visible && !nextProps.visible) this.props.declareStore.initDeclareForm();
}
getTaxAgentSelectListAsAdmin = async (props) => {
const { data: sysinfo } = await API.sysinfo();
const { declareStore: { declareForm } } = props;
getTaxAgentSelectListAsAdmin().then(({ status, data }) => {
if (status) {
this.setState({
conditions: _.map(declareConditions, item => ({
...item,
items: _.map(item.items, o => {
if (getKey(o) === "taxAgentId") {
return {
...o, options: _.map(data, g => ({ key: g.id, showname: g.content }))
// helpfulTitle: getLabel(563420, "提示:可选择单个个税扣缴义务人进行申报,若不选择,则批量对管理下的所有个税扣缴义务人进行申报;")
};
} else if (getKey(o) === "salaryMonth") {
return {
...o,
label: sysinfo["TAX_DECLARATION_DATE_TYPE"] === "1" ? getLabel(111, "税款所属期") : getLabel(111, "薪资所属月")
};
}
return { ...o };
})
}))
}, () => declareForm.initFormFields(this.state.conditions));
}
});
};
save = () => {
const { declareStore: { declareForm } } = this.props;
declareForm.validateForm().then(f => {
if (f.isValid) {
const { salaryMonth, ...payload } = declareForm.getFormParams();
this.setState({ loading: true });
saveDeclare({
...payload, salaryMonth: salaryMonth + "-01",
taxCycle: `${salaryMonth}-01`,
salaryDate: `${salaryMonth}-01`
}).then(async ({ status, data, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.destroy();
message.loading(getLabel(111, "生成中..."), 0);
this.timer = setInterval(async () => {
const { status: resStatus, data: result } = await taxdeclarationGetRate({ index: data });
const { status: rateStatus, finish, msg } = result;
if (resStatus && rateStatus) {
if (finish) {
clearInterval(this.timer);
message.destroy();
message.success(getLabel(30700, "操作成功"));
this.props.onCancel("refresh");
}
} else {
clearInterval(this.timer);
message.destroy();
message.warning(msg);
}
}, 1000);
} else {
clearInterval(this.timer);
message.destroy();
message.warning(errormsg);
}
}).catch(() => {
message.destroy();
clearInterval(this.timer);
this.setState({ loading: false });
});
} else {
f.showErrors();
}
});
};
render() {
const { conditions, loading } = this.state;
const { declareStore: { declareForm } } = this.props;
return (
<WeaDialog
{...this.props} style={{ width: 500, height: 174 }} initLoadCss
buttons={[
<Button type="primary" onClick={this.save} loading={loading}>{getLabel(543618, "生成申报表")}</Button>
]}
>
<div className="declare-dialog-layout">{getSearchs(declareForm, conditions, 1, false)}</div>
</WeaDialog>
);
}
}
export default Index;