salary-management-front/pc4mobx/hrmSalary/pages/calculate/calculate.js

342 lines
14 KiB
JavaScript

/*
* Author: 黎永顺
* name: 薪资核算-重构页面
* Description:
* Date: 2023/10/9
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaLocaleProvider, WeaTools, WeaTop } from "ecCom";
import { WeaForm } from "comsMobx";
import { Button, message, Modal } from "antd";
import moment from "moment";
import CalculateQuery from "./components/calculateQuery";
import CalculateTablelist from "./components/calculateTablelist";
import CalculateDialog from "./components/calculateDialog";
import ProgressModal from "../../components/progressModal";
import LogDialog from "../../components/logViewModal";
import {
backCalculate,
batAccounting,
batCalcTax,
batCalcTaxFeedback,
deleteSalaryacct,
fileSalaryAcct,
reAccounting
} from "../../apis/calculate";
import FormInfo from "../../components/FormInfo";
import { queryConditions } from "./config";
import { postFetch } from "../../util/request";
import cs from "classnames";
import "./index.less";
const getKey = WeaTools.getKey;
const getLabel = WeaLocaleProvider.getLabel;
const form = new WeaForm();
@inject("calculateStore", "taxAgentStore")
@observer
class Calculate extends Component {
constructor(props) {
super(props);
this.state = {
queryParams: {
name: "", lastOperates: [],
dateRange: [
moment(new Date()).subtract(1, "month").format("YYYY-MM"),
moment(new Date()).subtract(1, "month").format("YYYY-MM")
]
}, isRefresh: false, logDialogVisible: false, conditions: [],
progressModule: { visible: false, progress: 0, title: getLabel(111, "正在归档中请稍后") },
calcDaialog: { visible: false, title: "" }, showAdvance: false, selectedRowKeys: [],
loading: { acct: false, tax: false, feedback: false }
};
this.timer = null;
this.handleDebounce = null;
}
async componentDidMount() {
const { data } = await postFetch("/api/bs/hrmsalary/taxAgent/listAuth", { filterType: "QUERY_DATA" });
this.setState({
conditions: _.map(queryConditions, item => ({
...item, items: _.map(item.items, o => {
o = { ...o, label: getLabel(o.lanId, o.label) };
if (getKey(o) === "taxAgentIds") {
return { ...o, options: _.map(data, k => ({ key: k.id + "", showname: k.name })) };
}
return { ...o };
})
}))
}, () => form.initFormFields(this.state.conditions));
}
renderCalculateOpts = () => {
const { taxAgentStore: { PageAndOptAuth } } = this.props;
const { queryParams, isRefresh, showAdvance, loading, selectedRowKeys } = this.state;
const admin = PageAndOptAuth.opts.includes("admin");
let calculateOpts = [
// <Button type="primary" onClick={() => this.setState({
// calcDaialog: {
// visible: true,
// title: getLabel(538780, "核算")
// }
// })}>{getLabel(538780, "核算")}</Button>,
// <Button type="ghost" loading={loading.acct} disabled={_.isEmpty(selectedRowKeys)}
// onClick={this.handleBatAccounting}>{getLabel(111, "批量计算薪资")}</Button>,
// <Button type="ghost" loading={loading.tax} disabled={_.isEmpty(selectedRowKeys)}
// onClick={this.handleBatCalcTax}>{getLabel(111, "批量在线算税")}</Button>,
// <Button type="ghost" loading={loading.feedback} disabled={_.isEmpty(selectedRowKeys)}
// onClick={this.handleBatCalcTaxFeedback}>{getLabel(111, "批量获取算税结果")}</Button>,
<CalculateQuery queryParams={queryParams} onAdvance={() => this.setState({ showAdvance: !showAdvance })}
onChange={v => this.setState({
isRefresh: _.keys(v)[0] === "name" ? isRefresh : !isRefresh,
queryParams: { ...queryParams, ...v }
})} onSearch={() => this.setState({ isRefresh: !isRefresh })}/>
];
return calculateOpts;
// return !admin ? calculateOpts.slice(4) : calculateOpts;
};
handleBatCalcTax = () => {
const { selectedRowKeys: salaryAcctRecordIds, isRefresh, loading } = this.state;
this.setState({ loading: { ...loading, tax: true } });
batCalcTax({ salaryAcctRecordIds }).then(({ status, errormsg }) => {
this.setState({ loading: { ...loading, tax: false } });
if (status) {
message.success(getLabel(111, "操作成功!"));
this.setState({ isRefresh: !isRefresh });
} else {
message.error(errormsg);
}
});
};
handleBatCalcTaxFeedback = () => {
const { selectedRowKeys: salaryAcctRecordIds, isRefresh, loading } = this.state;
this.setState({ loading: { ...loading, feedback: true } });
batCalcTaxFeedback({ salaryAcctRecordIds }).then(({ status, errormsg }) => {
this.setState({ loading: { ...loading, feedback: false } });
if (status) {
message.success(getLabel(111, "操作成功!"));
this.setState({ isRefresh: !isRefresh });
} else {
message.error(errormsg);
}
});
};
handleBatAccounting = () => {
const { selectedRowKeys: salaryAcctRecordIds, isRefresh, loading } = this.state;
this.setState({ loading: { ...loading, acct: true } });
batAccounting({ salaryAcctRecordIds }).then(({ status, errormsg }) => {
this.setState({ loading: { ...loading, acct: false } });
if (status) {
message.success(getLabel(111, "操作成功!"));
this.setState({ isRefresh: !isRefresh });
} else {
message.error(errormsg);
}
});
};
handleCalcOpts = ({ key }, record) => {
const { isRefresh, progressModule } = this.state, { id } = record;
switch (key) {
case "0":
//核算
window.open(`/spa/hrmSalary/static/index.html#/main/hrmSalary/calculate/${id}`);
break;
case "1":
//删除
Modal.confirm({
title: getLabel(131329, "信息确认"),
content: getLabel(543231, "确认删除本条数据吗?"),
onOk: () => {
deleteSalaryacct([id]).then(({ status, errormsg }) => {
if (status) {
message.success(getLabel(502230, "删除成功!"));
this.setState({ isRefresh: !isRefresh });
} else {
message.error(errormsg);
}
});
}
});
break;
case "2":
//归档
if (!this.handleDebounce) {
this.handleDebounce = _.debounce(() => {
if (this.timer) clearInterval(this.timer);
this.setState({ progressModule: { ...progressModule, visible: true } });
this.timer = setInterval(() => {
if (progressModule.progress === 100 && this.timer) {
clearInterval(this.timer);
this.timer = null;
this.setState({
progressModule: { ...progressModule, visible: false, progress: 0 },
isRefresh: !isRefresh
});
}
this.setState({
progressModule: { ...progressModule, progress: progressModule.progress + 1 }
});
}, 800);
fileSalaryAcct({ id }).then(({ status, errormsg }) => {
if (status) {
clearInterval(this.timer);
this.timer = null;
this.setState({
progressModule: { ...progressModule, visible: false, progress: 0 },
isRefresh: !isRefresh
});
message.success(getLabel(503690, "归档成功"));
} else {
clearInterval(this.timer);
this.timer = null;
this.setState({
progressModule: { ...progressModule, visible: false, progress: 0 }
});
message.error(errormsg);
}
});
this.handleDebounce = null;
}, 500);
}
this.handleDebounce();
break;
case "3":
//查看详情
window.open(`/spa/hrmSalary/static/index.html#/main/hrmSalary/calcView/${id}`);
break;
case "4":
//重新核算
if (!this.handleDebounce) {
this.handleDebounce = _.debounce(() => {
reAccounting({ salaryAcctRecordId: id }).then(({ status, errormsg }) => {
if (status) {
message.success(getLabel(30700, "操作成功!"));
this.setState({ isRefresh: !isRefresh });
} else {
message.error(errormsg);
}
});
this.handleDebounce = null;
}, 500);
}
this.handleDebounce();
break;
case "5":
//回算
Modal.confirm({
title: getLabel(131329, "信息确认"),
content: getLabel(543538, "确定回算吗?回算后,正常核算的数据会被覆盖,正常核算的工资单不能继续发放或撤回!"),
onOk: () => {
if (!this.handleDebounce) {
this.handleDebounce = _.debounce(() => {
backCalculate({ salaryAcctRecordId: id }).then(({ status, errormsg }) => {
if (status) {
message.success(getLabel(544367, "回算成功!"));
this.setState({ isRefresh: !isRefresh });
} else {
message.error(errormsg);
}
});
this.handleDebounce = null;
}, 500);
}
this.handleDebounce();
}
});
break;
case "log":
//操作日志
this.onDropMenuClick(key, record.id);
break;
default:
break;
}
};
onDropMenuClick = (key, targetid = "") => {
switch (key) {
case "log":
this.setState({
logDialogVisible: true,
filterConditions: targetid ? `[{\"connectCondition\":\"AND\",\"columIndex\":\"targetid\",\"type\":\"=\",\"value\":\"${targetid}\"}]` : "[]"
});
break;
default:
break;
}
};
render() {
const {
queryParams, isRefresh, calcDaialog, progressModule, logDialogVisible, filterConditions, conditions, showAdvance,
selectedRowKeys, loading
} = this.state;
return (
<WeaTop title={getLabel(538011, "薪资核算")} icon={<i className="icon-coms-fa"/>} iconBgcolor="#F14A2D"
buttons={this.renderCalculateOpts()} className="calculate-main-layout" showDropIcon
onDropMenuClick={this.onDropMenuClick}
dropMenuDatas={[
{
key: "log", icon: <i className="iconfont icon-caozuorizhi32"/>,
content: getLabel(545781, "操作日志")
}
]}>
<div className="calculate-body">
<div className={cs("advance-calc", { "show-advance-calc": showAdvance })}>
<FormInfo center={false} itemRender={{}} form={form} formFields={conditions} colCount={2}/>
<div className="advance-calc-btns">
<Button type="primary"
onClick={() => this.setState({ isRefresh: !isRefresh })}>{getLabel(111, "搜索")}</Button>
<Button type="ghost" onClick={() => form.resetForm()}>{getLabel(111, "重置")}</Button>
<Button type="ghost"
onClick={() => this.setState({ showAdvance: !showAdvance })}>{getLabel(111, "取消")}</Button>
</div>
</div>
<div className="calc-opt-btns">
<Button type="primary" onClick={() => this.setState({
calcDaialog: {
visible: true,
title: getLabel(111, "账套生成")
}
})}>{getLabel(111, "账套生成")}</Button>
<Button type="ghost" loading={loading.acct} disabled={_.isEmpty(selectedRowKeys)}
onClick={this.handleBatAccounting}>{getLabel(111, "批量计算薪资")}</Button>
<Button type="ghost" loading={loading.tax} disabled={_.isEmpty(selectedRowKeys)}
onClick={this.handleBatCalcTax}>{getLabel(111, "批量在线算税")}</Button>
<Button type="ghost" loading={loading.feedback} disabled={_.isEmpty(selectedRowKeys)}
onClick={this.handleBatCalcTaxFeedback}>{getLabel(111, "批量获取算税结果")}</Button>
</div>
<CalculateTablelist form={form} queryParams={queryParams} isRefresh={isRefresh}
onCalcOpts={this.handleCalcOpts} selectedRowKeys={selectedRowKeys}
onSelectChange={v => this.setState({ selectedRowKeys: v })}/>
<CalculateDialog {...calcDaialog}
onCancel={(bool, id) => this.setState({
calcDaialog: { ...calcDaialog, visible: false },
isRefresh: bool === "refresh" ? !isRefresh : isRefresh
})}/>
{/*操作日志*/}
<LogDialog visible={logDialogVisible} logFunction="acctrecord" filterConditions={filterConditions}
onCancel={() => this.setState({ logDialogVisible: false })}/>
{/* 归档进度条*/}
{
progressModule.visible &&
<ProgressModal
{...progressModule}
onCancel={() => {
this.setState({
progressModule: {
...progressModule,
visible: false,
progress: 0
}
}, () => clearInterval(this.timer));
}}
/>
}
</div>
</WeaTop>
);
}
}
export default Calculate;