index.jsx 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import {
  2. savePurchaseInStore,
  3. getPurchaseDetail,
  4. } from "@/services/purchase";
  5. import { getStoreList } from "@/services/stock";
  6. import {
  7. PageContainer,
  8. ProForm,
  9. ProFormSelect,
  10. ProFormText,
  11. ProFormDigit,
  12. } from "@ant-design/pro-components";
  13. import { useNavigate, useSearchParams } from "react-router-dom";
  14. import { Card, Col, message, Row, Space, Form, Button } from "antd";
  15. import { useEffect, useRef, useState } from "react";
  16. import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
  17. import { floatMultiply, floatDivide } from "@/utils";
  18. export default (props) => {
  19. const [searchParams] = useSearchParams();
  20. const id = searchParams.get("id");
  21. const [storeList, setStoreList] = useState([]);
  22. const [isInStore, setIsInStore] = useState(false);
  23. const navigate = useNavigate();
  24. const formRef = useRef();
  25. useEffect(() => {
  26. getStoreList({ pageSize: 9999 }).then((res) => {
  27. setStoreList(
  28. res?.records?.map((x) => ({
  29. label: x.name,
  30. value: x.id,
  31. }))
  32. );
  33. });
  34. }, []);
  35. useEffect(() => {
  36. if (id) {
  37. getPurchaseDetail(id).then((res) => {
  38. setIsInStore(res.isInStore)
  39. formRef.current.setFieldsValue({
  40. ...res,
  41. itemsList: res.itemsList?.map((x) => ({
  42. ...x,
  43. planUnitPrice: x.planUnitPrice
  44. ? floatDivide(x.planUnitPrice, 100)
  45. : null,
  46. actUnitPrice: x.actUnitPrice
  47. ? floatDivide(x.actUnitPrice, 100)
  48. : null,
  49. })),
  50. });
  51. });
  52. }
  53. }, [id]);
  54. const onFinish = async (values) => {
  55. console.log(values, "===");
  56. savePurchaseInStore(Number(id)).then((res) => {
  57. // message.success("添加成功");
  58. navigate(-1);
  59. });
  60. return false;
  61. };
  62. return (
  63. <PageContainer>
  64. <Card>
  65. <ProForm
  66. formRef={formRef}
  67. layout={"horizontal"}
  68. labelCol={{ span: 2 }}
  69. wrapperCol={{ span: 8 }}
  70. onFinish={onFinish}
  71. submitter={{
  72. searchConfig: {
  73. resetText: "返回",
  74. submitText:'入库'
  75. },
  76. onReset: () => navigate(-1),
  77. render: (props, doms) => {
  78. console.log(props, doms, "renderprops");
  79. return (
  80. <Row>
  81. <Col span={8} offset={2}>
  82. <Space>
  83. {doms?.map((x, index) => {
  84. if (index === 1 && isInStore) {
  85. return null;
  86. }
  87. return x;
  88. })}
  89. </Space>
  90. </Col>
  91. </Row>
  92. );
  93. },
  94. }}
  95. >
  96. <ProFormText
  97. name="title"
  98. label="采购计划"
  99. placeholder="请输入采购计划"
  100. disabled
  101. width={480}
  102. />
  103. <ProFormText
  104. name="planDate"
  105. label="计划时间"
  106. placeholder="请输入计划时间"
  107. disabled
  108. width={480}
  109. />
  110. <Form.Item
  111. label="采购清单"
  112. labelCol={{ span: 2 }}
  113. wrapperCol={{ span: 22 }}
  114. >
  115. <Form.List name="itemsList">
  116. {(fields, { add, remove }) => (
  117. <>
  118. {fields.map(({ key, name, ...restField }) => (
  119. <Space
  120. key={key}
  121. style={{ display: "flex" }}
  122. align="baseline"
  123. >
  124. <ProFormSelect
  125. {...restField}
  126. name={[name, "storeId"]}
  127. label="库存名称"
  128. placeholder="请选择库存名称"
  129. disabled
  130. options={storeList}
  131. />
  132. <ProFormDigit
  133. {...restField}
  134. name={[name, "planAmount"]}
  135. label="计划数量"
  136. placeholder="请输入计划数量"
  137. disabled
  138. width={100}
  139. fieldProps={{
  140. precision: 10,
  141. formatter: (value) => value,
  142. }}
  143. />
  144. <ProFormDigit
  145. {...restField}
  146. name={[name, "planUnitPrice"]}
  147. label="预估单价"
  148. placeholder="请输入预估单价"
  149. disabled
  150. fieldProps={{ precision: 2, prefix: "¥" }}
  151. width={100}
  152. />
  153. <ProFormDigit
  154. {...restField}
  155. name={[name, "actAmount"]}
  156. label="采购数量"
  157. placeholder="请输入采购数量"
  158. disabled
  159. width={100}
  160. fieldProps={{
  161. precision: 10,
  162. formatter: (value) => value,
  163. }}
  164. />
  165. <ProFormDigit
  166. {...restField}
  167. name={[name, "actUnitPrice"]}
  168. label="采购单价"
  169. placeholder="请输入采购单价"
  170. disabled
  171. fieldProps={{ precision: 2, prefix: "¥" }}
  172. width={100}
  173. />
  174. </Space>
  175. ))}
  176. </>
  177. )}
  178. </Form.List>
  179. </Form.Item>
  180. </ProForm>
  181. </Card>
  182. </PageContainer>
  183. );
  184. };