123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- 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 (
- <PageContainer>
- <Card>
- <ProForm
-
- formRef={formRef}
- layout={"horizontal"}
- labelCol={{ span: 2 }}
- wrapperCol={{ span: 8 }}
- onFinish={onFinish}
- submitter={{
- searchConfig: {
- resetText: "返回",
- submitText:'入库'
- },
- onReset: () => navigate(-1),
- render: (props, doms) => {
- console.log(props, doms, "renderprops");
- return (
- <Row>
- <Col span={8} offset={2}>
- <Space>
- {doms?.map((x, index) => {
- if (index === 1 && isInStore) {
- return null;
- }
- return x;
- })}
- </Space>
- </Col>
- </Row>
- );
- },
- }}
- >
- <ProFormText
- name="title"
- label="采购计划"
- placeholder="请输入采购计划"
- disabled
- width={480}
- />
- <ProFormText
- name="planDate"
- label="计划时间"
- placeholder="请输入计划时间"
- disabled
- width={480}
- />
- <Form.Item
- label="采购清单"
- labelCol={{ span: 2 }}
- wrapperCol={{ span: 22 }}
- >
- <Form.List name="itemsList">
- {(fields, { add, remove }) => (
- <>
- {fields.map(({ key, name, ...restField }) => (
- <Space
- key={key}
- style={{ display: "flex" }}
- align="baseline"
- >
- <ProFormSelect
- {...restField}
- name={[name, "storeId"]}
- label="库存名称"
- placeholder="请选择库存名称"
- disabled
- options={storeList}
- />
-
- <ProFormDigit
- {...restField}
- name={[name, "planAmount"]}
- label="计划数量"
- placeholder="请输入计划数量"
- disabled
- width={100}
- fieldProps={{
- precision: 10,
- formatter: (value) => value,
- }}
- />
- <ProFormDigit
- {...restField}
- name={[name, "planUnitPrice"]}
- label="预估单价"
- placeholder="请输入预估单价"
- disabled
- fieldProps={{ precision: 2, prefix: "¥" }}
- width={100}
- />
- <ProFormDigit
- {...restField}
- name={[name, "actAmount"]}
- label="采购数量"
- placeholder="请输入采购数量"
- disabled
- width={100}
- fieldProps={{
- precision: 10,
- formatter: (value) => value,
- }}
- />
- <ProFormDigit
- {...restField}
- name={[name, "actUnitPrice"]}
- label="采购单价"
- placeholder="请输入采购单价"
- disabled
- fieldProps={{ precision: 2, prefix: "¥" }}
- width={100}
- />
- </Space>
- ))}
- </>
- )}
- </Form.List>
- </Form.Item>
- </ProForm>
- </Card>
- </PageContainer>
- );
- };
|