2025-04-02 15:30:55 +08:00
|
|
|
import { Button, Flex, Form, Input, Space } from "antd";
|
|
|
|
import { useForm } from "antd/es/form/Form";
|
2024-04-07 17:37:09 +08:00
|
|
|
import useModal from "antd/es/modal/useModal";
|
2025-04-02 15:30:55 +08:00
|
|
|
// import { get, post } from "../../../util/AjaxUtils.ts";
|
2024-04-07 17:37:09 +08:00
|
|
|
import useMessage from "antd/es/message/useMessage";
|
2025-04-02 15:30:55 +08:00
|
|
|
import { useEffect } from "react";
|
2024-04-07 17:37:09 +08:00
|
|
|
|
|
|
|
type FormDataType = {
|
|
|
|
invoiceTitle: string;
|
|
|
|
invoicePhone: string;
|
|
|
|
invoiceNo: string;
|
|
|
|
invoiceBank: string;
|
|
|
|
invoiceAddress: string;
|
|
|
|
invoiceAccount: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface EditProps {
|
2025-04-02 15:30:55 +08:00
|
|
|
invoiceId: string;
|
2024-04-07 17:37:09 +08:00
|
|
|
handleOk: () => void;
|
|
|
|
handleCancel: () => void;
|
|
|
|
}
|
2025-04-02 15:30:55 +08:00
|
|
|
import { getInvoiceInfo, updateInvoiceInfo } from '../../../request/api.ts'
|
2024-04-07 17:37:09 +08:00
|
|
|
export default function InvoiceInfoSave(props: EditProps) {
|
|
|
|
const [messageApi, messageContext] = useMessage();
|
|
|
|
const [modal, modalContext] = useModal();
|
|
|
|
const [form] = useForm<FormDataType>()
|
2025-04-02 15:30:55 +08:00
|
|
|
const getInfoData = async () => {
|
|
|
|
try {
|
|
|
|
const res: any = await getInvoiceInfo(props.invoiceId)
|
|
|
|
// console.log(res);
|
|
|
|
|
|
|
|
form.setFieldsValue(res)
|
|
|
|
} catch (error: any) {
|
|
|
|
if (error.response) {
|
|
|
|
const data = error.response.data;
|
|
|
|
messageApi.open({
|
|
|
|
type: 'error',
|
|
|
|
content: data.msg ? data.msg : `${data.path}(${data.status})`,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.error(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
const upInfoData = async () => {
|
|
|
|
try {
|
|
|
|
|
|
|
|
await updateInvoiceInfo(props.invoiceId, { ...form.getFieldsValue(), invoiceType: '企业' });
|
2024-04-07 17:37:09 +08:00
|
|
|
|
2025-04-02 15:30:55 +08:00
|
|
|
messageApi.success('保存成功');
|
|
|
|
|
|
|
|
props.handleOk();
|
|
|
|
} catch (error: any) {
|
|
|
|
if (error.response) {
|
|
|
|
const data = error.response.data;
|
|
|
|
messageApi.open({
|
|
|
|
type: 'error',
|
|
|
|
content: data.msg ? data.msg : `${data.path}(${data.status})`,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.error(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-04-07 17:37:09 +08:00
|
|
|
useEffect(() => {
|
2025-04-02 15:30:55 +08:00
|
|
|
if (!props.invoiceId) {
|
2024-04-07 17:37:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2025-04-02 15:30:55 +08:00
|
|
|
getInfoData();
|
|
|
|
|
|
|
|
// get<FormDataType>({
|
|
|
|
// messageApi,
|
|
|
|
// url: `/api/invoice-info/get/${props.invoiceInfoId}`,
|
|
|
|
// onSuccess({data}) {
|
|
|
|
// form.setFieldsValue(data);
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
}, [props.invoiceId]);
|
2024-04-07 17:37:09 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Form
|
|
|
|
name="basic"
|
|
|
|
layout="vertical"
|
|
|
|
form={form}
|
2025-04-02 15:30:55 +08:00
|
|
|
onFinish={() => {
|
2024-04-07 17:37:09 +08:00
|
|
|
modal.confirm({
|
2025-04-02 15:30:55 +08:00
|
|
|
centered: true,
|
2024-04-07 17:37:09 +08:00
|
|
|
title: '提示',
|
|
|
|
content: '确定保存吗',
|
|
|
|
okText: '确定',
|
|
|
|
cancelText: '取消',
|
|
|
|
okButtonProps: {
|
|
|
|
style: {
|
|
|
|
backgroundColor: 'var(--color-primary)'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onOk: () => {
|
2025-04-02 15:30:55 +08:00
|
|
|
// post<any>({
|
|
|
|
// messageApi,
|
|
|
|
// url: `/api/invoice-info/update/${props.invoiceInfoId}`,
|
|
|
|
// body: values,
|
|
|
|
// onSuccess() {
|
|
|
|
// messageApi.success('保存成功');
|
|
|
|
// props.handleOk();
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
upInfoData()
|
2024-04-07 17:37:09 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Form.Item
|
|
|
|
label="公司名称"
|
2025-04-02 15:30:55 +08:00
|
|
|
name="invoiceName"
|
|
|
|
rules={[{ required: true, message: '请输入公司名称' }]}
|
2024-04-07 17:37:09 +08:00
|
|
|
>
|
2025-04-02 15:30:55 +08:00
|
|
|
<Input placeholder="请输入公司名称" />
|
2024-04-07 17:37:09 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
label="纳税人识别号"
|
2025-04-02 15:30:55 +08:00
|
|
|
name="invoiceNumber"
|
|
|
|
rules={[{ required: true, message: '请输入纳税人识别号' }]}
|
2024-04-07 17:37:09 +08:00
|
|
|
>
|
2025-04-02 15:30:55 +08:00
|
|
|
<Input placeholder="请输入纳税人识别号" />
|
2024-04-07 17:37:09 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
label="公司地址"
|
2025-04-02 15:30:55 +08:00
|
|
|
name="invoiceOrgaddress"
|
|
|
|
rules={[{ required: false, message: '请输入公司地址' }]}
|
2024-04-07 17:37:09 +08:00
|
|
|
>
|
2025-04-02 15:30:55 +08:00
|
|
|
<Input placeholder="请输入公司地址" />
|
2024-04-07 17:37:09 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
label="公司电话"
|
2025-04-02 15:30:55 +08:00
|
|
|
name="invoiceOrgtel"
|
|
|
|
rules={[{ required: false, message: '请输入公司电话' }]}
|
2024-04-07 17:37:09 +08:00
|
|
|
>
|
2025-04-02 15:30:55 +08:00
|
|
|
<Input placeholder="请输入公司电话" />
|
2024-04-07 17:37:09 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
label="开户行"
|
|
|
|
name="invoiceBank"
|
2025-04-02 15:30:55 +08:00
|
|
|
rules={[{ required: false, message: '请输入开户行' }]}
|
2024-04-07 17:37:09 +08:00
|
|
|
>
|
2025-04-02 15:30:55 +08:00
|
|
|
<Input placeholder="请输入开户行" />
|
2024-04-07 17:37:09 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
label="开户行账号"
|
2025-04-02 15:30:55 +08:00
|
|
|
name="invoiceBanknumber"
|
|
|
|
rules={[{ required: false, message: '请输入开户行账号' }]}
|
2024-04-07 17:37:09 +08:00
|
|
|
>
|
2025-04-02 15:30:55 +08:00
|
|
|
<Input placeholder="请输入开户行账号" />
|
2024-04-07 17:37:09 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Flex justify="center">
|
|
|
|
<Space size={5}>
|
|
|
|
<Button type="primary" htmlType="submit"
|
2025-04-02 15:30:55 +08:00
|
|
|
style={{ backgroundColor: 'var(--color-primary)' }}>保存</Button>
|
2024-04-07 17:37:09 +08:00
|
|
|
<Button type="default" onClick={() => {
|
|
|
|
props.handleCancel();
|
|
|
|
}}>关闭</Button>
|
|
|
|
</Space>
|
|
|
|
</Flex>
|
|
|
|
</Form>
|
|
|
|
{messageContext}
|
|
|
|
{modalContext}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|