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

446 lines
15 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaLocaleProvider, WeaSearchGroup, WeaTools } 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
} from "../../../apis/special";
import { removePropertyCondition } from "../../../util/response";
import { DataCollectionSelect } from "../cumDeduct";
import ImportFormCom from "../cumDeduct/components/importFormCom";
import { condition } from "./components/condition";
import AddItems from "../addItems";
import TableRecord from "../components/tableRecord";
import { convertToUrlString } from "../../../util/url";
import { postFetch } from "../../../util/request";
const getKey = WeaTools.getKey;
const getLabel = WeaLocaleProvider.getLabel;
@inject("taxAgentStore", "specialAddStore")
@observer
class Index extends Component {
constructor(props) {
super(props);
this.state = {
taxAgentId: "",
innerWidth: window.innerWidth,
saveLoading: false,
slidePayload: {
visible: false,
title: "",
children: null,
data: {}
},
importPayload: {
visible: false,
importOpts: {
taxAgentId: ""
},
importFormComponent: null,
templateLink: "/api/bs/hrmsalary/specialAddDeduction/downloadTemplate",
importResult: {},
previewUrl: "/api/bs/hrmsalary/specialAddDeduction/preview"
},
exportPayloadUrl: "",
exportPayloadType: false,
advanceCondition: null,
targetid: "",
taxAgentOption: []
};
this.tableRef = null;
this.addItemRef = null;
this.tableRecordRef = null;
}
componentDidMount() {
this.getAdvanceCondition();
}
/*
* Author: 黎永顺
* Description: æ•°æ<C2B0>®é‡‡é†-ä¿¡æ<C2A1>¯ä¿<C3A4>å­˜
* 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 });
if (status) {
message.success("ç¼è¾æˆ<C3A6>功");
this.handleCloseSlide();
this.tableRef.getTableDate();
} else {
message.error(errormsg || "编辑失败");
}
});
} else {
specialAddDeductionCreateData(payload).then(({ status, errormsg }) => {
this.setState({ saveLoading: false });
if (status) {
message.success(°å¢žæˆ<C3A6>功");
this.handleCloseSlide();
this.tableRef.getTableDate();
} else {
message.error(errormsg || "新增失败");
}
});
}
};
/*
* Author: 黎永顺
* Description: 高级æ<C2A7>œç´ æ¡†-表å<C2A8>•项
* Params:
* Date: 2023/2/20
*/
getAdvanceCondition = async () => {
const { data: authTaxAgent } = await postFetch("/api/bs/hrmsalary/taxAgent/listAuth", { filterType: "QUERY_DATA" });
const { specialAddStore: { advanceForm } } = this.props;
getSearchCondition().then(({ status, data }) => {
if (status) {
this.setState({
advanceCondition: removePropertyCondition(data.condition),
taxAgentOption: _.map(authTaxAgent, g => ({ key: String(g.id), showname: g.name }))
});
advanceForm.initFormFields(removePropertyCondition(data.condition));
}
});
};
/*
* Author: 黎永顺
* Description: 一键清空
* Params:
* Date: 2023/2/20
*/
specialAddDeductionDeleteAllData = () => {
const { taxAgentId } = this.state;
const payload = { taxAgentId };
Modal.confirm({
title: "ä¿¡æ<C2A1>¯ç¡®è®¤",
content: `确定清空所有专项附加扣除数æ<EFBFBD>®å<EFBFBD>—?è¥æ•°æ<C2B0>®å·²å<C2B2>与核算,已å<C2B2>与核算的数æ<C2B0>®ä¸<C3A4>会å<C5A1>—å½±å“<C3A5>,ç¹å‡»æ ¸ç®—将会按当å‰<C3A5>åˆ—è¡¨æœ€æ°æ•°æ<C2B0>®é‡<C3A9>æ°æ ¸ç®—ã€`,
onOk: () => {
specialAddDeductionDeleteAllData(payload).then(({ status, errormsg }) => {
if (status) {
message.success(ˆ é™¤æˆ<C3A6>功");
this.tableRef.getTableDate();
} else {
message.error(errormsg || "删除失败");
}
});
}
});
};
/*
* 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("请选æ©è¡¨æ ¼æ•°æ<C2B0>®");
return;
}
const payload = { ids: !id ? ids : [id] };
Modal.confirm({
title: "ä¿¡æ<C2A1>¯ç¡®è®¤",
content: !id ? "确定删除所选数æ<C2B0>®å<C2AE>—?è¥æ•°æ<C2B0>®å·²å<C2B2>与核算,已å<C2B2>与核算的数æ<C2B0>®ä¸<C3A4>会å<C5A1>—å½±å“<C3A5>,ç¹å‡»æ ¸ç®—将会按当å‰<C3A5>åˆ—è¡¨æœ€æ°æ•°æ<C2B0>®é‡<C3A9>æ°æ ¸ç®—ã€" :
`确定删除${departmentName}${username}的累计专项附加扣除数æ<EFBFBD>®å<EFBFBD>—?è¥æ•°æ<C2B0>®å·²å<C2B2>与核算,已å<C2B2>与核算的数æ<C2B0>®ä¸<C3A4>会å<C5A1>—å½±å“<C3A5>,ç¹å‡»æ ¸ç®—将会按当å‰<C3A5>åˆ—è¡¨æœ€æ°æ•°æ<C2B0>®é‡<C3A9>æ°æ ¸ç®—ã€`,
onOk: () => {
specialAddDeductionDeleteSelectData(payload).then(({ status, errormsg }) => {
if (status) {
message.success(ˆ é™¤æˆ<C3A6>功");
this.tableRef.getTableDate();
this.tableRef.handleClearRows();
} else {
message.error(errormsg || "删除失败");
}
});
}
});
};
/*
* Author: 黎永顺
* Description:æ•°æ<C2B0>®é‡‡é†-导出全部
* Params:
* Date: 2023/2/20
*/
handleExportAll = () => {
const { specialAddStore: { advanceForm } } = this.props;
const { taxAgentId, exportPayloadType } = this.state;
this.setState({
exportPayloadType: !exportPayloadType,
exportPayloadUrl: `${window.location.origin}/api/bs/hrmsalary/specialAddDeduction/export?ids=&taxAgentId=${taxAgentId}&${convertToUrlString(advanceForm.getFormParams())}`
});
};
/*
* Author: 黎永顺
* Description:æ•°æ<C2B0>®é‡‡é†-导出选中
* Params:
* Date: 2023/2/20
*/
handleExportSelect = () => {
const { selectedRowKeys: ids } = this.tableRef.state;
const { taxAgentId, exportPayloadType } = this.state;
if (ids.length === 0) {
message.warning("请选æ©éœ€è¦<C3A8>导出的数æ<C2B0>®");
return;
}
this.setState({
exportPayloadType: !exportPayloadType,
exportPayloadUrl: `${window.location.origin}/api/bs/hrmsalary/specialAddDeduction/export?ids=${ids.join(",")}&taxAgentId=${taxAgentId}`
});
};
/*
* Author: 黎永顺
* Description: 筛选组件
* Params:
* Date: 2023/2/17
*/
getScreen = () => {
const { taxAgentId, taxAgentOption } = 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 }) => {
const { specialAddStore: { advanceForm } } = this.props;
this.setState({ [key]: value }, () => this.tableRef.getTableDate({ ...advanceForm.getFormParams(), current: 1 }));
};
/*
* Author: 黎永顺
* Description: 顶部æ“<C3A6>作按é®
* 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">æ¹é<EFBFBD>删é¤</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:æ°å¢žæ•°æ<C2B0>®é‡‡é†-专项附加扣除
* Params: screenParams规则:日期必须放在数组最å<E282AC>Žä¸€ä½<C3A4>,人å˜ä¿¡æ<C2A1>¯å¿…须第一ä½<C3A4>
* Date: 2023/2/20
*/
handleAddData = async (title = "新建", editId = {}) => {
const { data } = await postFetch("/api/bs/hrmsalary/taxAgent/listAuth", { filterType: "ADMIN_DATA" });
const taxAgentOption = _.map(data, o => ({ key: String(o.id), showname: o.name }));
const { specialAddStore: { addForm } } = this.props;
const { slidePayload } = this.state;
const conditions = _.map(condition, (it, idx) => {
if (idx === 0) {
return {
...it, title: getLabel(82743, "基础信æ<C2A1>¯"),
items: _.map(it.items, o => {
if (getKey(o) === "taxAgentId") {
return {
...o, label: getLabel(o.lanId, o.label),
options: taxAgentOption, viewAttr: _.isEmpty(editId) ? 3 : 1
};
}
return {
...o, label: getLabel(o.lanId, o.label), viewAttr: _.isEmpty(editId) ? 3 : 1
};
})
};
} else if (idx === 1) {
return {
...it, title: getLabel(83871, "æ•°æ<C2B0>®é‡‡é†"),
items: _.map(it.items, o => ({
...o, label: getLabel(o.lanId, o.label)
}))
};
}
});
addForm.initFormFields(conditions);
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={conditions}
/> :
<TableRecord
ref={(dom) => this.tableRecordRef = dom}
className="accumulated"
taxAgentOption={taxAgentOption}
url="/api/bs/hrmsalary/specialAddDeduction/getDetailList"
record={editId}
screenParams={["specialAddDeductionId"]}
/>
}
});
};
/*
* Author: 黎永顺
* Description:列表æ“<C3A6>作
* Params:
* Date: 2023/2/20
*/
handleTableOperate = ({ key }, record) => {
const { id } = record;
key === "handleAddData" ? getSpecialAddDeduction({ id }).then(({ status, data }) => {
if (status) this[key]("编辑", data);
}) : key === "log" ? this.setState({ targetid: id }) : this.specialAddDeductionDeleteSelectData(record);
};
handleCloseSlide = () => {
const { slidePayload } = this.state;
this.setState({
slidePayload: {
...slidePayload,
visible: false,
title: "",
children: null,
data: {}
}
});
this.tableRecordRef && this.tableRecordRef.handleResetSelectKeys();
this.handleDebounce = null;
this.props.specialAddStore.initAddForm();
};
handleSaveData = () => {
const { specialAddStore: { addForm } } = this.props, { slidePayload } = this.state;
const taxAgentOption = slidePayload.children.props.taxAgentOption;
addForm.validateForm().then(f => {
if (f.isValid) {
const payload = {
...addForm.getFormParams(),
taxAgentName: _.find(taxAgentOption, it => it.key === addForm.getFormParams().taxAgentId).showname
};
this.handleSaveDeduction(payload);
} else {
Modal.warning({
title: "ä¿¡æ<C2A1>¯ç¡®è®¤",
content: "å¿…è¦<C3A8>ä¿¡æ<C2A1>¯ä¸<C3A4>完整,红色*为必填项ï¼<C3AF>"
});
}
});
};
handleAdSearch = () => {
const { specialAddStore: { advanceForm } } = this.props;
this.tableRef.getTableDate({ ...advanceForm.getFormParams(), current: 1 });
};
handleResize = (innerWidth) => this.setState({ innerWidth });
/*
* Author: 黎永顺
* Description: æ•°æ<C2B0>®é‡‡é†-导入相关
* Params:
* Date: 2023/2/20
*/
handleOpenImport = async () => {
const { data } = await postFetch("/api/bs/hrmsalary/taxAgent/listAuth", { filterType: "ADMIN_DATA" });
const taxAgentOption = _.map(data, o => ({ key: String(o.id), showname: o.name }));
const { importPayload } = this.state;
const { importOpts } = importPayload;
this.setState({
importPayload: {
...importPayload,
visible: true, step: 0,
importResult: {}, slideDataSource: [],
importFormComponent: <ImportFormCom {...importOpts} taxAgentOption={taxAgentOption}
onChangeImportForm={this.handleChangeImportForm}/>
}
});
};
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());
};
handleChangeImportForm = (key, value) => {
const { importPayload } = this.state;
const { importOpts } = importPayload;
this.setState({
importPayload: { ...importPayload, importOpts: { ...importOpts, [key]: value } }
});
};
render() {
const { specialAddStore: { advanceForm } } = this.props;
const {
taxAgentId, slidePayload, saveLoading, exportPayloadUrl, advanceCondition, importPayload,
exportPayloadType, targetid
} = this.state;
const tablePayload = { taxAgentId };
return (
<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} logFunction="specialAddDeduction"
form={advanceForm} condition={advanceCondition} onAdSearch={this.handleAdSearch}
onCancel={this.handleCloseImport} detailOptBtns={[]}
importPayload={importPayload} onImportFile={specialAddDeductionImportData}
targetid={targetid} onClearTargrtid={() => this.setState({ targetid: "" })}
>
<DataTables
ref={dom => this.tableRef = dom}
url="/api/bs/hrmsalary/specialAddDeduction/list"
payload={tablePayload}
isSpecial
onTableOperate={this.handleTableOperate}
onViewDetails={(record) => this.handleAddData("专项附加扣除记录", record)}
form={advanceForm}
/>
</Layout>
);
}
}
export default Index;