salary-management-front/pc4mobx/hrmSalary/pages/ledgerPage/components/copyLedgerModal.js

109 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-12-08 15:48:46 +08:00
/*
* Author: 黎永顺
* name: 复制账套
* Description:
* Date: 2022/12/8
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { copyConditions } from "../config";
2022-12-08 16:43:55 +08:00
import { duplicateLedger } from "../../../apis/ledger";
2022-12-08 15:48:46 +08:00
import { WeaDialog } from "ecCom";
2022-12-08 16:43:55 +08:00
import { Button, message } from "antd";
2022-12-08 15:48:46 +08:00
import { getSearchs } from "../../../util";
2024-09-11 18:37:01 +08:00
import { postFetch } from "../../../util/request";
2022-12-08 15:48:46 +08:00
import "./index.less";
2024-09-11 18:37:01 +08:00
@inject("ledgerStore")
2022-12-08 15:48:46 +08:00
@observer
class CopyLedgerModal extends Component {
2022-12-08 16:43:55 +08:00
constructor(props) {
super(props);
this.state = {
loading: false
};
}
2022-12-08 15:48:46 +08:00
componentDidMount() {
this.getTaxAgentSelectListAsAdmin();
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) {
const { ledgerStore, name, taxAgentId } = nextProps;
const { copyForm: form } = ledgerStore;
2024-09-11 18:37:01 +08:00
form.updateFields({ name: { value: name }, taxAgentId: { value: taxAgentId } });
2022-12-08 15:48:46 +08:00
}
}
getTaxAgentSelectListAsAdmin = () => {
2024-09-11 18:37:01 +08:00
const { ledgerStore } = this.props;
2022-12-08 15:48:46 +08:00
const { copyForm: form } = ledgerStore;
2025-02-27 16:53:46 +08:00
postFetch("/api/bs/hrmsalary/taxAgent/listAuth", { filterType: "QUERY_DATA" })
2024-09-11 18:37:01 +08:00
.then(({ status, data }) => {
if (status) {
const conditions = _.map(copyConditions, it => {
it.items = _.map(it.items, child => {
if (child.domkey[0] === "taxAgentId") {
return {
...child, options: _.map(data, it => ({ key: String(it.id), showname: it.name }))
};
} else {
return { ...child };
}
});
return { ...it };
2022-12-08 15:48:46 +08:00
});
2024-09-11 18:37:01 +08:00
form.initFormFields(conditions);
}
});
2022-12-08 15:48:46 +08:00
};
handleSubmit = () => {
2022-12-08 16:43:55 +08:00
const { ledgerStore, id, onRefreshList, onCancel } = this.props;
2022-12-08 15:48:46 +08:00
const { copyForm: form } = ledgerStore;
form.validateForm().then(f => {
if (f.isValid) {
2024-12-27 14:11:20 +08:00
const { taxAgentId, ...formParams } = form.getFormParams();
const payload = { id, ...formParams, taxAgentIds: taxAgentId.split(",") };
2022-12-08 16:43:55 +08:00
this.setState({ loading: true });
duplicateLedger(payload).then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(errormsg || "复制成功");
onRefreshList();
onCancel();
} else {
message.error(errormsg || "复制失败");
}
});
2022-12-08 15:48:46 +08:00
} else {
f.showErrors();
}
});
};
render() {
const { onCancel, ledgerStore, ...extra } = this.props;
2022-12-08 16:43:55 +08:00
const { loading } = this.state;
2022-12-08 15:48:46 +08:00
const { copyForm: form } = ledgerStore;
const buttons = [
2022-12-08 16:43:55 +08:00
<Button type="primary" onClick={this.handleSubmit} loading={loading}>保存</Button>,
2022-12-08 15:48:46 +08:00
<Button type="ghost" onClick={onCancel}> 取消 </Button>
];
return (
<WeaDialog
{...extra}
initLoadCss
className="copyWrapper"
style={{ width: 600 }}
buttons={buttons}
onCancel={onCancel}
>
{getSearchs(form, copyConditions, 1)}
</WeaDialog>
);
}
}
export default CopyLedgerModal;