salary-management-front/pc4mobx/hrmSalary/pages/dataAcquisition/specialAddDeduction/index.js

454 lines
15 KiB
JavaScript
Raw Normal View History

2022-11-03 17:52:02 +08:00
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
2023-02-21 18:05:54 +08:00
import { WeaSearchGroup } from "ecCom";
import { Button, Dropdown, Menu, message, Modal } from "antd";
import DataTables from "../dataTables";
import Layout from "../layout";
import {
getSearchCondition,
getSpecialAddDeduction,
specialAddDeductionCreateData,
specialAddDeductionDeleteAllData,
specialAddDeductionDeleteSelectData,
specialAddDeductionEditData,
specialAddDeductionImportData,
specialAddDeductionPreview
} from "../../../apis/special";
import { removePropertyCondition } from "../../../util/response";
import { DataCollectionSelect } from "../cumDeduct";
import ImportFormCom from "../cumDeduct/components/importFormCom";
import { condition } from "./components/condition";
2022-11-04 11:33:58 +08:00
import AddItems from "../addItems";
2023-02-21 18:05:54 +08:00
import TableRecord from "../components/tableRecord";
2023-03-02 09:34:04 +08:00
import { specialModalColumns } from "../cumDeduct/columns";
import { convertToUrlString } from "../../../util/url";
2022-11-03 17:52:02 +08:00
2023-02-21 18:05:54 +08:00
@inject("taxAgentStore", "specialAddStore")
2022-11-03 17:52:02 +08:00
@observer
2023-02-21 18:05:54 +08:00
class Index extends Component {
2022-11-03 17:52:02 +08:00
constructor(props) {
super(props);
this.state = {
2023-02-21 18:05:54 +08:00
taxAgentId: "",
innerWidth: window.innerWidth,
saveLoading: false,
slidePayload: {
2022-11-03 17:52:02 +08:00
visible: false,
2023-02-21 18:05:54 +08:00
title: "",
children: null,
data: {}
2022-11-03 17:52:02 +08:00
},
2023-02-21 18:05:54 +08:00
importPayload: {
visible: false,
importOpts: {
taxAgentId: ""
},
importFormComponent: null,
step: 0,
2023-02-22 14:00:34 +08:00
templateLink: "/api/bs/hrmsalary/specialAddDeduction/downloadTemplate",
2023-02-21 18:05:54 +08:00
importResult: {},
slideDataSource: []
},
2023-02-21 18:05:54 +08:00
exportPayloadUrl: "",
exportPayloadType: false,
2023-02-21 18:05:54 +08:00
advanceCondition: null
2022-11-03 17:52:02 +08:00
};
2023-02-21 18:05:54 +08:00
this.tableRef = null;
2022-11-04 11:33:58 +08:00
this.addItemRef = null;
2023-02-21 18:05:54 +08:00
this.tableRecordRef = null;
2022-11-03 17:52:02 +08:00
}
componentDidMount() {
2023-02-21 18:05:54 +08:00
this.getAdvanceCondition();
2022-11-03 17:52:02 +08:00
}
2023-02-21 18:05:54 +08:00
/*
* Author: 黎永顺
* Description: 数据采集-信息保存
* Params:
* Date: 2023/2/20
*/
handleSaveDeduction = (payload) => {
const { slidePayload } = this.state;
const { data } = slidePayload;
const { id } = data;
this.setState({ saveLoading: true });
if (!_.isEmpty(data)) {
specialAddDeductionEditData({ ...payload, id }).then(({ status, errormsg }) => {
this.setState({ saveLoading: false });
2022-11-04 11:33:58 +08:00
if (status) {
message.success("编辑成功");
2023-02-21 18:05:54 +08:00
this.handleCloseSlide();
this.tableRef.getTableDate();
2022-11-04 11:33:58 +08:00
} else {
message.error(errormsg || "编辑失败");
}
});
} else {
2023-02-21 18:05:54 +08:00
specialAddDeductionCreateData(payload).then(({ status, errormsg }) => {
this.setState({ saveLoading: false });
2022-11-04 11:33:58 +08:00
if (status) {
message.success("新增成功");
2023-02-21 18:05:54 +08:00
this.handleCloseSlide();
this.tableRef.getTableDate();
2022-11-04 11:33:58 +08:00
} else {
message.error(errormsg || "新增失败");
}
});
}
};
2023-02-21 18:05:54 +08:00
/*
* Author: 黎永顺
* Description: 导入数据采集数据
* Params:
* Date: 2023/2/20
*/
handleImportFile = (params) => {
specialAddDeductionImportData(params).then(({ status, data }) => {
if (status) {
const { importPayload } = this.state;
this.setState({
importPayload: { ...importPayload, importResult: data }
2022-11-04 11:33:58 +08:00
});
2023-02-21 18:05:54 +08:00
}
});
2022-11-04 11:33:58 +08:00
};
2023-02-21 18:05:54 +08:00
/*
* Author: 黎永顺
* Description: 导入数据采集-数据查看
* Params:
* Date: 2023/2/20
*/
handlePreviewImport = (params) => {
specialAddDeductionPreview(params).then(({ status, data, errormsg }) => {
if (status) {
const { preview = [] } = data;
const { importPayload } = this.state;
this.setState({
importPayload: { ...importPayload, slideDataSource: preview }
});
} else {
message.error(errormsg || "预览失败");
}
});
};
/*
* Author: 黎永顺
* Description: 高级搜素框-表单项
* Params:
* Date: 2023/2/20
*/
getAdvanceCondition = () => {
const { specialAddStore: { advanceForm } } = this.props;
getSearchCondition().then(({ status, data }) => {
if (status) {
this.setState({ advanceCondition: removePropertyCondition(data.condition) });
advanceForm.initFormFields(removePropertyCondition(data.condition));
}
});
};
/*
* Author: 黎永顺
* Description: 一键清空
* Params:
* Date: 2023/2/20
*/
specialAddDeductionDeleteAllData = () => {
const { taxAgentId } = this.state;
const payload = { taxAgentId };
2022-11-04 16:31:24 +08:00
Modal.confirm({
title: "信息确认",
2023-02-21 18:05:54 +08:00
content: `确定清空所有专项附加扣除数据吗?若数据已参与核算,已参与核算的数据不会受影响,点击核算将会按当前列表最新数据重新核算。`,
2022-11-04 16:31:24 +08:00
onOk: () => {
2023-02-21 18:05:54 +08:00
specialAddDeductionDeleteAllData(payload).then(({ status, errormsg }) => {
2022-11-04 16:31:24 +08:00
if (status) {
message.success("删除成功");
2023-02-21 18:05:54 +08:00
this.tableRef.getTableDate();
2022-11-04 16:31:24 +08:00
} else {
message.error(errormsg || "删除失败");
}
});
}
});
};
2023-02-21 18:05:54 +08:00
/*
* Author: 黎永顺
* Description: 删除所选
* Params:
* Date: 2023/2/20
*/
specialAddDeductionDeleteSelectData = (record = {}) => {
const { selectedRowKeys: ids } = this.tableRef.state;
const { id, departmentName, username } = record;
if (ids.length === 0 && !id) {
message.warning("请选择表格数据");
return;
}
const payload = { ids: !id ? ids : [id] };
Modal.confirm({
title: "信息确认",
2023-02-21 18:05:54 +08:00
content: !id ? "确定删除所选数据吗?若数据已参与核算,已参与核算的数据不会受影响,点击核算将会按当前列表最新数据重新核算。" :
`确定删除${departmentName}${username}的累计专项附加扣除数据吗?若数据已参与核算,已参与核算的数据不会受影响,点击核算将会按当前列表最新数据重新核算。`,
onOk: () => {
2023-02-21 18:05:54 +08:00
specialAddDeductionDeleteSelectData(payload).then(({ status, errormsg }) => {
if (status) {
message.success("删除成功");
2023-02-21 18:05:54 +08:00
this.tableRef.getTableDate();
this.tableRef.handleClearRows();
} else {
message.error(errormsg || "删除失败");
}
});
}
});
};
2023-02-21 18:05:54 +08:00
/*
* Author: 黎永顺
* Description:数据采集-导出全部
* Params:
* Date: 2023/2/20
*/
handleExportAll = () => {
const { specialAddStore: { advanceForm } } = this.props;
const { taxAgentId, exportPayloadType } = this.state;
2023-02-21 18:05:54 +08:00
this.setState({
exportPayloadType: !exportPayloadType,
exportPayloadUrl: `${window.location.origin}/api/bs/hrmsalary/specialAddDeduction/export?ids=&taxAgentId=${taxAgentId}&${convertToUrlString(advanceForm.getFormParams())}`
2023-02-21 18:05:54 +08:00
});
};
/*
* Author: 黎永顺
* Description:数据采集-导出选中
* Params:
* Date: 2023/2/20
*/
handleExportSelect = () => {
const { selectedRowKeys: ids } = this.tableRef.state;
const { taxAgentId, exportPayloadType } = this.state;
2023-02-21 18:05:54 +08:00
if (ids.length === 0) {
message.warning("请选择需要导出的数据");
return;
}
this.setState({
exportPayloadType: !exportPayloadType,
2023-02-21 18:05:54 +08:00
exportPayloadUrl: `${window.location.origin}/api/bs/hrmsalary/specialAddDeduction/export?ids=${ids.join(",")}&taxAgentId=${taxAgentId}`
});
};
/*
* Author: 黎永顺
* Description: 筛选组件
* Params:
* Date: 2023/2/17
*/
getScreen = () => {
const { taxAgentStore: { taxAgentOption } } = this.props;
const { taxAgentId } = this.state;
const items = [
{
com: DataCollectionSelect({
label: "个税扣缴义务人",
value: taxAgentId,
onChange: this.screenChange,
options: [{ key: "", showname: "全部" }, ...taxAgentOption],
key: "taxAgentId"
})
}
];
return <WeaSearchGroup className="screenWrapper" showGroup needTigger={false} items={items} col={2}/>;
};
screenChange = ({ key, value }) => {
2023-02-23 15:59:28 +08:00
const { specialAddStore: { advanceForm } } = this.props;
this.setState({ [key]: value }, () => this.tableRef.getTableDate({ ...advanceForm.getFormParams(), current: 1 }));
2023-02-21 18:05:54 +08:00
};
/*
* Author: 黎永顺
* Description: 顶部操作按钮
* Params:
* Date: 2023/2/17
*/
getTopBtns = () => {
return [
<Button type="primary" onClick={this.handleOpenImport}>导入</Button>,
<Button type="ghost" onClick={() => this.handleAddData()}>新建</Button>,
<Dropdown
overlay={
<Menu className="dropdownMenuWrapper" onClick={this.handleDataMenuClick}>
<Menu.Item key="specialAddDeductionDeleteSelectData">批量删除</Menu.Item>
<Menu.Item key="specialAddDeductionDeleteAllData">一键清空</Menu.Item>
<Menu.Item key="handleExportSelect">导出选中</Menu.Item>
<Menu.Item key="handleExportAll">导出全部</Menu.Item>
</Menu>
}
>
<Button type="ghost">更多</Button>
</Dropdown>
];
};
handleDataMenuClick = ({ key: keyFunc }) => this[keyFunc]();
/*
* Author: 黎永顺
* Description:新增数据采集-专项附加扣除
* Params: screenParams规则日期必须放在数组最后一位人员信息必须第一位
* Date: 2023/2/20
*/
handleAddData = (title = "新建", editId = {}) => {
const { taxAgentStore, specialAddStore: { addForm } } = this.props;
const { slidePayload } = this.state;
const { taxAgentOption } = taxAgentStore;
addForm.initFormFields(condition);
this.setState({
slidePayload: {
...slidePayload,
visible: true,
title,
data: editId,
children: title.length <= 2 ?
<AddItems
ref={(dom) => this.addItemRef = dom}
taxAgentOption={taxAgentOption}
form={addForm}
isSpecial
editId={editId}
condition={condition}
/> :
<TableRecord
ref={(dom) => this.tableRecordRef = dom}
className="accumulated"
taxAgentOption={taxAgentOption}
url="/api/bs/hrmsalary/specialAddDeduction/getDetailList"
record={editId}
screenParams={["specialAddDeductionId"]}
/>
}
});
};
2023-02-21 18:05:54 +08:00
/*
* Author: 黎永顺
* Description:列表操作
* Params:
* Date: 2023/2/20
*/
handleTableOperate = ({ key }, record) => {
const { id } = record;
key === "handleAddData" ? getSpecialAddDeduction({ id }).then(({ status, data }) => {
if (status) this[key]("编辑", data);
}) : this.specialAddDeductionDeleteSelectData(record);
};
handleCloseSlide = () => {
const { slidePayload } = this.state;
this.setState({
slidePayload: {
...slidePayload,
visible: false,
title: "",
chidren: null,
data: {}
}
});
2023-02-21 18:05:54 +08:00
this.tableRecordRef && this.tableRecordRef.handleResetSelectKeys();
this.handleDebounce = null;
};
2023-02-21 18:05:54 +08:00
handleSaveData = () => {
const { specialAddStore: { addForm } } = this.props;
const { baseInfo } = this.addItemRef.state;
const bool = _.every(_.pick(baseInfo, ["taxAgentId", "employeeId"]), v => !!v);
if (!bool) {
Modal.warning({
title: "信息确认",
content: "必要信息不完整,红色*为必填项!"
});
return;
2022-12-12 17:26:44 +08:00
}
2023-02-21 18:05:54 +08:00
const payload = {
..._.pick(baseInfo, ["taxAgentId", "employeeId", "taxAgentName"]),
...addForm.getFormParams()
};
this.handleSaveDeduction(payload);
};
handleAdSearch = () => {
const { specialAddStore: { advanceForm } } = this.props;
this.tableRef.getTableDate({ ...advanceForm.getFormParams(), current: 1 });
};
2022-12-12 17:26:44 +08:00
2023-02-21 18:05:54 +08:00
handleResize = (innerWidth) => this.setState({ innerWidth });
/*
* Author: 黎永顺
* Description: 数据采集-导入相关
* Params:
* Date: 2023/2/20
*/
handleOpenImport = () => {
const { importPayload } = this.state;
const { importOpts } = importPayload;
const { taxAgentStore: { taxAgentOption } } = this.props;
this.setState({
importPayload: {
...importPayload,
visible: true, step: 0,
importResult: {}, slideDataSource: [],
importFormComponent: <ImportFormCom {...importOpts} taxAgentOption={taxAgentOption}
onChangeImportForm={this.handleChangeImportForm}/>
}
});
};
2023-02-21 18:05:54 +08:00
handleCloseImport = (doSearch = false) => {
const { importPayload } = this.state;
this.setState({
importPayload: {
...importPayload, visible: false, importFormComponent: null, step: 0,
importOpts: {
taxAgentId: ""
}, importResult: {}, slideDataSource: []
}
}, () => doSearch && this.tableRef.getTableDate());
};
2023-02-21 18:05:54 +08:00
handleChangeImportForm = (key, value) => {
const { importPayload } = this.state;
const { importOpts } = importPayload;
this.setState({
importPayload: { ...importPayload, importOpts: { ...importOpts, [key]: value } }
});
2022-11-03 17:52:02 +08:00
};
2023-02-21 18:05:54 +08:00
handleImportSetStep = (step) => {
const { importPayload } = this.state;
this.setState({
importPayload: { ...importPayload, step }
});
};
2022-12-12 17:14:14 +08:00
2022-11-03 17:52:02 +08:00
render() {
2023-02-21 18:05:54 +08:00
const { taxAgentStore: { showOperateBtn }, specialAddStore: { advanceForm } } = this.props;
const {
taxAgentId, slidePayload, saveLoading, exportPayloadUrl, advanceCondition, importPayload,
exportPayloadType
} = this.state;
2023-02-21 18:05:54 +08:00
const tablePayload = { taxAgentId };
2022-11-03 17:52:02 +08:00
return (
2023-02-21 18:05:54 +08:00
<Layout title="专项附加扣除" btns={this.getTopBtns()} leftComp={this.getScreen()}
onResizeWindowInnerWidth={this.handleResize} slidePayload={slidePayload}
onClose={this.handleCloseSlide} onSave={this.handleSaveData}
slideLoading={saveLoading} exportPayloadUrl={exportPayloadUrl}
exportPayloadType={exportPayloadType}
2023-02-21 18:05:54 +08:00
form={advanceForm} condition={advanceCondition} onAdSearch={this.handleAdSearch}
onImportSetStep={this.handleImportSetStep} onCancel={this.handleCloseImport}
importPayload={importPayload} onImportFile={this.handleImportFile}
2023-02-22 14:00:34 +08:00
onPreviewImport={this.handlePreviewImport} detailOptBtns={[]}
2023-03-02 09:34:04 +08:00
columns={specialModalColumns}
2023-02-21 18:05:54 +08:00
>
<DataTables
ref={dom => this.tableRef = dom}
url="/api/bs/hrmsalary/specialAddDeduction/list"
payload={tablePayload}
2023-02-22 14:00:34 +08:00
isSpecial
2023-02-21 18:05:54 +08:00
showOperateBtn={showOperateBtn}
onTableOperate={this.handleTableOperate}
onViewDetails={(record) => this.handleAddData("专项附加扣除记录", record)}
2023-02-23 15:59:28 +08:00
form={advanceForm}
2023-02-21 18:05:54 +08:00
/>
</Layout>
2022-11-03 17:52:02 +08:00
);
}
}
2023-02-21 18:05:54 +08:00
export default Index;