import { savePurchaseInStore, getPurchaseDetail, } from "@/services/purchase"; import { getStoreList } from "@/services/stock"; import { PageContainer, ProForm, ProFormSelect, ProFormText, ProFormDigit, } from "@ant-design/pro-components"; import { useNavigate, useSearchParams } from "react-router-dom"; import { Card, Col, message, Row, Space, Form, Button } from "antd"; import { useEffect, useRef, useState } from "react"; import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons"; import { floatMultiply, floatDivide } from "@/utils"; export default (props) => { const [searchParams] = useSearchParams(); const id = searchParams.get("id"); const [storeList, setStoreList] = useState([]); const [isInStore, setIsInStore] = useState(false); const navigate = useNavigate(); const formRef = useRef(); useEffect(() => { getStoreList({ pageSize: 9999 }).then((res) => { setStoreList( res?.records?.map((x) => ({ label: x.name, value: x.id, })) ); }); }, []); useEffect(() => { if (id) { getPurchaseDetail(id).then((res) => { setIsInStore(res.isInStore) formRef.current.setFieldsValue({ ...res, itemsList: res.itemsList?.map((x) => ({ ...x, planUnitPrice: x.planUnitPrice ? floatDivide(x.planUnitPrice, 100) : null, actUnitPrice: x.actUnitPrice ? floatDivide(x.actUnitPrice, 100) : null, })), }); }); } }, [id]); const onFinish = async (values) => { console.log(values, "==="); savePurchaseInStore(Number(id)).then((res) => { // message.success("添加成功"); navigate(-1); }); return false; }; return ( navigate(-1), render: (props, doms) => { console.log(props, doms, "renderprops"); return ( {doms?.map((x, index) => { if (index === 1 && isInStore) { return null; } return x; })} ); }, }} > {(fields, { add, remove }) => ( <> {fields.map(({ key, name, ...restField }) => ( value, }} /> value, }} /> ))} )} ); };