|
@@ -1,45 +1,45 @@
|
1
|
1
|
import {
|
2
|
|
- savePurchaseInStore,
|
3
|
2
|
getPurchaseDetail,
|
|
3
|
+ savePurchaseInStore,
|
4
|
4
|
} from "@/services/purchase";
|
5
|
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
|
6
|
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";
|
|
7
|
+import { Card, Descriptions, Button } from "antd";
|
|
8
|
+import { useEffect, useMemo, useState } from "react";
|
|
9
|
+import moment from "moment";
|
17
|
10
|
import { floatMultiply, floatDivide } from "@/utils/float";
|
|
11
|
+import useBool from "@/utils/hooks/useBool";
|
|
12
|
+
|
|
13
|
+const Item = Descriptions;
|
18
|
14
|
|
19
|
15
|
export default (props) => {
|
20
|
16
|
const [searchParams] = useSearchParams();
|
21
|
17
|
const id = searchParams.get("id");
|
22
|
18
|
const [storeList, setStoreList] = useState([]);
|
23
|
|
- const [isInStore, setIsInStore] = useState(false);
|
|
19
|
+ const [detail, setDetail] = useState({});
|
24
|
20
|
const navigate = useNavigate();
|
|
21
|
+ const [loading, startLoading, cancelLoading] = useBool();
|
|
22
|
+
|
|
23
|
+ const dtStr = useMemo(() => detail.completedDate ? moment(detail.completedDate).format('YYYY-MM-DD'): '', [detail.completedDate]);
|
|
24
|
+
|
|
25
|
+ const onSumbit = () => {
|
|
26
|
+ startLoading()
|
|
27
|
+ savePurchaseInStore(id).then(() => {
|
|
28
|
+ cancelLoading()
|
|
29
|
+ setDetail({ ...detail, isInStore: true })
|
|
30
|
+ }).catch(cancelLoading)
|
|
31
|
+ }
|
25
|
32
|
|
26
|
|
- const formRef = useRef();
|
27
|
33
|
useEffect(() => {
|
28
|
34
|
getStoreList({ pageSize: 9999 }).then((res) => {
|
29
|
|
- setStoreList(
|
30
|
|
- res?.records?.map((x) => ({
|
31
|
|
- label: x.name,
|
32
|
|
- value: x.id,
|
33
|
|
- }))
|
34
|
|
- );
|
|
35
|
+ setStoreList(res.records || []);
|
35
|
36
|
});
|
36
|
37
|
}, []);
|
37
|
38
|
|
38
|
39
|
useEffect(() => {
|
39
|
40
|
if (id) {
|
40
|
41
|
getPurchaseDetail(id).then((res) => {
|
41
|
|
- setIsInStore(res.isInStore)
|
42
|
|
- formRef.current.setFieldsValue({
|
|
42
|
+ setDetail({
|
43
|
43
|
...res,
|
44
|
44
|
itemsList: res.itemsList?.map((x) => ({
|
45
|
45
|
...x,
|
|
@@ -55,143 +55,48 @@ export default (props) => {
|
55
|
55
|
}
|
56
|
56
|
}, [id]);
|
57
|
57
|
|
58
|
|
- const onFinish = async (values) => {
|
59
|
|
- console.log(values, "===");
|
60
|
|
-
|
61
|
|
-
|
62
|
|
-
|
63
|
|
- savePurchaseInStore(Number(id)).then((res) => {
|
64
|
|
- // message.success("添加成功");
|
65
|
|
- navigate(-1);
|
66
|
|
- });
|
67
|
|
-
|
68
|
|
- return false;
|
69
|
|
- };
|
70
|
|
-
|
71
|
|
-
|
72
|
|
-
|
73
|
58
|
return (
|
74
|
|
- <PageContainer>
|
75
|
|
- <Card>
|
76
|
|
- <ProForm
|
77
|
|
-
|
78
|
|
- formRef={formRef}
|
79
|
|
- layout={"horizontal"}
|
80
|
|
- labelCol={{ span: 2 }}
|
81
|
|
- wrapperCol={{ span: 8 }}
|
82
|
|
- onFinish={onFinish}
|
83
|
|
- submitter={{
|
84
|
|
- searchConfig: {
|
85
|
|
- resetText: "返回",
|
86
|
|
- submitText:'入库'
|
87
|
|
- },
|
88
|
|
- onReset: () => navigate(-1),
|
89
|
|
- render: (props, doms) => {
|
90
|
|
- console.log(props, doms, "renderprops");
|
91
|
|
- return (
|
92
|
|
- <Row>
|
93
|
|
- <Col span={8} offset={2}>
|
94
|
|
- <Space>
|
95
|
|
- {doms?.map((x, index) => {
|
96
|
|
- if (index === 1 && isInStore) {
|
97
|
|
- return null;
|
98
|
|
- }
|
99
|
|
- return x;
|
100
|
|
- })}
|
101
|
|
- </Space>
|
102
|
|
- </Col>
|
103
|
|
- </Row>
|
104
|
|
- );
|
105
|
|
- },
|
106
|
|
- }}
|
107
|
|
- >
|
108
|
|
- <ProFormText
|
109
|
|
- name="title"
|
110
|
|
- label="采购计划"
|
111
|
|
- placeholder="请输入采购计划"
|
112
|
|
- disabled
|
113
|
|
- width={480}
|
114
|
|
- />
|
115
|
|
- <ProFormText
|
116
|
|
- name="planDate"
|
117
|
|
- label="计划时间"
|
118
|
|
- placeholder="请输入计划时间"
|
119
|
|
- disabled
|
120
|
|
- width={480}
|
121
|
|
- />
|
122
|
|
- <Form.Item
|
123
|
|
- label="采购清单"
|
124
|
|
- labelCol={{ span: 2 }}
|
125
|
|
- wrapperCol={{ span: 22 }}
|
|
59
|
+ <Card
|
|
60
|
+ title={<div>采购单</div>}
|
|
61
|
+ extra={(
|
|
62
|
+ <>
|
|
63
|
+ <Button
|
|
64
|
+ type="primary"
|
|
65
|
+ disabled={detail.isInStore || !detail.isCompleted}
|
|
66
|
+ loading={loading}
|
|
67
|
+ onClick={onSumbit}
|
126
|
68
|
>
|
127
|
|
- <Form.List name="itemsList">
|
128
|
|
- {(fields, { add, remove }) => (
|
129
|
|
- <>
|
130
|
|
- {fields.map(({ key, name, ...restField }) => (
|
131
|
|
- <Space
|
132
|
|
- key={key}
|
133
|
|
- style={{ display: "flex" }}
|
134
|
|
- align="baseline"
|
135
|
|
- >
|
136
|
|
- <ProFormSelect
|
137
|
|
- {...restField}
|
138
|
|
- name={[name, "storeId"]}
|
139
|
|
- label="库存名称"
|
140
|
|
- placeholder="请选择库存名称"
|
141
|
|
- disabled
|
142
|
|
- options={storeList}
|
143
|
|
- />
|
|
69
|
+ 入库
|
|
70
|
+ </Button>
|
|
71
|
+ <Button style={{ marginLeft: '2em' }} onClick={() => navigate(-1)}>返回</Button>
|
|
72
|
+ </>
|
|
73
|
+ )}
|
|
74
|
+ >
|
|
75
|
+ <Descriptions title="基本信息" bordered>
|
|
76
|
+ <Item label="采购时间">{dtStr}</Item>
|
|
77
|
+ <Item label="计划时间">{detail.planDate}</Item>
|
|
78
|
+ </Descriptions>
|
|
79
|
+ <Descriptions title="明细信息" bordered style={{ marginTop: '24px' }} column={5}>
|
|
80
|
+ {
|
|
81
|
+ (detail.itemsList || []).reduce((acc, it, inx) => {
|
|
82
|
+
|
|
83
|
+ const store = storeList.filter(x => x.id === it.storeId)[0] || {};
|
|
84
|
+ const planUnitPrice = it.planUnitPrice ? `${it.planUnitPrice} 元` : '-';
|
|
85
|
+ const planAmount = it.planAmount ? `${it.planAmount} ${store.unit}` : '-';
|
|
86
|
+ const actUnitPrice = it.actUnitPrice ? `${it.actUnitPrice} 元` : '-';
|
|
87
|
+ const actAmount = it.actAmount ? `${it.actAmount} ${store.unit}` : '-';
|
144
|
88
|
|
145
|
|
- <ProFormDigit
|
146
|
|
- {...restField}
|
147
|
|
- name={[name, "planAmount"]}
|
148
|
|
- label="计划数量"
|
149
|
|
- placeholder="请输入计划数量"
|
150
|
|
- disabled
|
151
|
|
- width={100}
|
152
|
|
- fieldProps={{
|
153
|
|
- precision: 10,
|
154
|
|
- formatter: (value) => value,
|
155
|
|
- }}
|
156
|
|
- />
|
157
|
|
- <ProFormDigit
|
158
|
|
- {...restField}
|
159
|
|
- name={[name, "planUnitPrice"]}
|
160
|
|
- label="预估单价"
|
161
|
|
- placeholder="请输入预估单价"
|
162
|
|
- disabled
|
163
|
|
- fieldProps={{ precision: 2, prefix: "¥" }}
|
164
|
|
- width={100}
|
165
|
|
- />
|
166
|
|
- <ProFormDigit
|
167
|
|
- {...restField}
|
168
|
|
- name={[name, "actAmount"]}
|
169
|
|
- label="采购数量"
|
170
|
|
- placeholder="请输入采购数量"
|
171
|
|
- disabled
|
172
|
|
- width={100}
|
173
|
|
- fieldProps={{
|
174
|
|
- precision: 10,
|
175
|
|
- formatter: (value) => value,
|
176
|
|
- }}
|
177
|
|
- />
|
178
|
|
- <ProFormDigit
|
179
|
|
- {...restField}
|
180
|
|
- name={[name, "actUnitPrice"]}
|
181
|
|
- label="采购单价"
|
182
|
|
- placeholder="请输入采购单价"
|
183
|
|
- disabled
|
184
|
|
- fieldProps={{ precision: 2, prefix: "¥" }}
|
185
|
|
- width={100}
|
186
|
|
- />
|
187
|
|
- </Space>
|
188
|
|
- ))}
|
189
|
|
- </>
|
190
|
|
- )}
|
191
|
|
- </Form.List>
|
192
|
|
- </Form.Item>
|
193
|
|
- </ProForm>
|
194
|
|
- </Card>
|
195
|
|
- </PageContainer>
|
|
89
|
+ return acc.concat([
|
|
90
|
+ <Item key={`t-${inx}-1`} label="采购物品名称">{store.name}</Item>,
|
|
91
|
+ <Item key={`t-${inx}-2`} label="计划采购单价">{planUnitPrice}</Item>,
|
|
92
|
+ <Item key={`t-${inx}-3`} label="计划采购数量">{planAmount}</Item>,
|
|
93
|
+ <Item key={`t-${inx}-4`} label="实际采购单价">{actUnitPrice}</Item>,
|
|
94
|
+ <Item key={`t-${inx}-5`} label="实际采购数量">{actAmount}</Item>,
|
|
95
|
+ ]
|
|
96
|
+ )
|
|
97
|
+ }, [])
|
|
98
|
+ }
|
|
99
|
+ </Descriptions>
|
|
100
|
+ </Card>
|
196
|
101
|
);
|
197
|
102
|
};
|