/* * Author: 黎永顺 * name: 复制账套 * Description: * Date: 2022/12/8 */ import React, { Component } from "react"; import { inject, observer } from "mobx-react"; import { copyConditions } from "../config"; import { duplicateLedger } from "../../../apis/ledger"; import { WeaDialog } from "ecCom"; import { Button, message } from "antd"; import { getSearchs } from "../../../util"; import { postFetch } from "../../../util/request"; import "./index.less"; @inject("ledgerStore") @observer class CopyLedgerModal extends Component { constructor(props) { super(props); this.state = { loading: false }; } componentDidMount() { this.getTaxAgentSelectListAsAdmin(); } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.visible !== this.props.visible && nextProps.visible) { const { ledgerStore, name, taxAgentId } = nextProps; const { copyForm: form } = ledgerStore; form.updateFields({ name: { value: name }, taxAgentId: { value: taxAgentId } }); } } getTaxAgentSelectListAsAdmin = () => { const { ledgerStore } = this.props; const { copyForm: form } = ledgerStore; postFetch("/api/bs/hrmsalary/taxAgent/listAuth", { filterType: "QUERY_DATA" }) .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 }; }); form.initFormFields(conditions); } }); }; handleSubmit = () => { const { ledgerStore, id, onRefreshList, onCancel } = this.props; const { copyForm: form } = ledgerStore; form.validateForm().then(f => { if (f.isValid) { const { taxAgentId, ...formParams } = form.getFormParams(); const payload = { id, ...formParams, taxAgentIds: taxAgentId.split(",") }; this.setState({ loading: true }); duplicateLedger(payload).then(({ status, errormsg }) => { this.setState({ loading: false }); if (status) { message.success(errormsg || "复制成功"); onRefreshList(); onCancel(); } else { message.error(errormsg || "复制失败"); } }); } else { f.showErrors(); } }); }; render() { const { onCancel, ledgerStore, ...extra } = this.props; const { loading } = this.state; const { copyForm: form } = ledgerStore; const buttons = [ , ]; return ( {getSearchs(form, copyConditions, 1)} ); } } export default CopyLedgerModal;