浏览代码

Merge branch 'dev' of http://git.ycjcjy.com/jgz/admin into dev

lisenzhou 2 年前
父节点
当前提交
62057eb69f
共有 3 个文件被更改,包括 90 次插入172 次删除
  1. 21
    9
      src/pages/purchase/bill/edit/index.jsx
  2. 61
    156
      src/pages/purchase/inStore/edit/index.jsx
  3. 8
    7
      src/utils/request.js

+ 21
- 9
src/pages/purchase/bill/edit/index.jsx 查看文件

12
   ProFormDigit,
12
   ProFormDigit,
13
 } from "@ant-design/pro-components";
13
 } from "@ant-design/pro-components";
14
 import { useNavigate, useSearchParams } from "react-router-dom";
14
 import { useNavigate, useSearchParams } from "react-router-dom";
15
-import { Card, Col, message, Row, Space, Form, Button } from "antd";
15
+import { Card, Col, Modal, Row, Space, Form, Button } from "antd";
16
 import { useEffect, useRef, useState } from "react";
16
 import { useEffect, useRef, useState } from "react";
17
-import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
17
+import { ExclamationCircleOutlined } from '@ant-design/icons';
18
 import { floatMultiply, floatDivide } from "@/utils/float";
18
 import { floatMultiply, floatDivide } from "@/utils/float";
19
 
19
 
20
+const { confirm } = Modal;
21
+
20
 export default (props) => {
22
 export default (props) => {
21
   const [searchParams] = useSearchParams();
23
   const [searchParams] = useSearchParams();
22
   const id = searchParams.get("id");
24
   const id = searchParams.get("id");
53
   }, [id]);
55
   }, [id]);
54
 
56
 
55
   const onFinish = async (values) => {
57
   const onFinish = async (values) => {
56
-    console.log(values, "===");
57
-
58
     let data = {
58
     let data = {
59
       id: id ? Number(id) : null,
59
       id: id ? Number(id) : null,
60
       ...values,
60
       ...values,
74
   };
74
   };
75
 
75
 
76
   const onBillFinish = ({ form }) => {
76
   const onBillFinish = ({ form }) => {
77
-    form.validateFields().then((res) => {
78
-      console.log(res, "===--");
79
-      onFinish({ ...res, isCompleted: true });
77
+    confirm({
78
+      title: '确认采购完成?',
79
+      icon: <ExclamationCircleOutlined />,
80
+      content: '确定之后, 将不能再做修改!',
81
+      onOk: () => {
82
+        form.validateFields().then((res) => {
83
+          onFinish({ ...res, isCompleted: true });
84
+        });
85
+      }
80
     });
86
     });
81
   };
87
   };
82
 
88
 
184
                         name={[name, "actAmount"]}
190
                         name={[name, "actAmount"]}
185
                         label="采购数量"
191
                         label="采购数量"
186
                         placeholder="请输入采购数量"
192
                         placeholder="请输入采购数量"
187
-                        rules={[{ required: true, message: "请输入采购数量" }]}
193
+                        rules={[
194
+                          { required: true, message: "请输入采购数量" },
195
+                          { validator: (_, val) => val > 0 ? Promise.resolve() : Promise.reject(), message: "采购数量必须大于0" },
196
+                        ]}
188
                         width={100}
197
                         width={100}
189
                         fieldProps={{
198
                         fieldProps={{
190
                           precision: 10,
199
                           precision: 10,
196
                         name={[name, "actUnitPrice"]}
205
                         name={[name, "actUnitPrice"]}
197
                         label="采购单价"
206
                         label="采购单价"
198
                         placeholder="请输入采购单价"
207
                         placeholder="请输入采购单价"
199
-                        rules={[{ required: true, message: "请输入采购单价" }]}
208
+                        rules={[
209
+                          { required: true, message: "请输入采购单价" },
210
+                          { validator: (_, val) => val > 0 ? Promise.resolve() : Promise.reject(), message: "采购单价必须大于0" },
211
+                        ]}
200
                         fieldProps={{ precision: 2, prefix: "¥" }}
212
                         fieldProps={{ precision: 2, prefix: "¥" }}
201
                         width={100}
213
                         width={100}
202
                       />
214
                       />

+ 61
- 156
src/pages/purchase/inStore/edit/index.jsx 查看文件

1
 import {
1
 import {
2
-  savePurchaseInStore,
3
   getPurchaseDetail,
2
   getPurchaseDetail,
3
+  savePurchaseInStore,
4
 } from "@/services/purchase";
4
 } from "@/services/purchase";
5
 import { getStoreList } from "@/services/stock";
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";
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
 import { floatMultiply, floatDivide } from "@/utils/float";
10
 import { floatMultiply, floatDivide } from "@/utils/float";
11
+import useBool from "@/utils/hooks/useBool";
12
+
13
+const Item = Descriptions;
18
 
14
 
19
 export default (props) => {
15
 export default (props) => {
20
   const [searchParams] = useSearchParams();
16
   const [searchParams] = useSearchParams();
21
   const id = searchParams.get("id");
17
   const id = searchParams.get("id");
22
   const [storeList, setStoreList] = useState([]);
18
   const [storeList, setStoreList] = useState([]);
23
-  const [isInStore, setIsInStore] = useState(false);
19
+  const [detail, setDetail] = useState({});
24
   const navigate = useNavigate();
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
   useEffect(() => {
33
   useEffect(() => {
28
     getStoreList({ pageSize: 9999 }).then((res) => {
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
   useEffect(() => {
39
   useEffect(() => {
39
     if (id) {
40
     if (id) {
40
       getPurchaseDetail(id).then((res) => {
41
       getPurchaseDetail(id).then((res) => {
41
-        setIsInStore(res.isInStore)
42
-        formRef.current.setFieldsValue({
42
+        setDetail({
43
           ...res,
43
           ...res,
44
           itemsList: res.itemsList?.map((x) => ({
44
           itemsList: res.itemsList?.map((x) => ({
45
             ...x,
45
             ...x,
55
     }
55
     }
56
   }, [id]);
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
   return (
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
 };

+ 8
- 7
src/utils/request.js 查看文件

18
     successTip,
18
     successTip,
19
     headers: {
19
     headers: {
20
       ...headers,
20
       ...headers,
21
-      responseType: download ? 'blob' : responseType,
22
       Authorization: token,
21
       Authorization: token,
23
-    }
22
+    },    
23
+    responseType: download ? 'blob' : responseType,
24
   };
24
   };
25
 }, function (error) {
25
 }, function (error) {
26
   // 对请求错误做些什么
26
   // 对请求错误做些什么
33
   // 对响应数据做点什么
33
   // 对响应数据做点什么
34
 
34
 
35
   const { data, config } = response;
35
   const { data, config } = response;
36
-  if (config.download) {
37
-    return downloadBlob(response.data, '下载文件');
36
+  if (config.download && !data.code) {
37
+    return downloadBlob(response, '下载文件');
38
   }
38
   }
39
   
39
   
40
   if (data.code === 1000) {
40
   if (data.code === 1000) {
128
 
128
 
129
 function downloadBlob(response) {
129
 function downloadBlob(response) {
130
   let fileName = '未知文件';
130
   let fileName = '未知文件';
131
+  const contentType = response.headers['content-type'];
131
   const contentDisposition = response.headers['content-disposition'];
132
   const contentDisposition = response.headers['content-disposition'];
132
   if (contentDisposition) {
133
   if (contentDisposition) {
133
     const parts = contentDisposition.split(';filename=');
134
     const parts = contentDisposition.split(';filename=');
134
     if (parts[1]) {
135
     if (parts[1]) {
135
-      fileName = parts[1];
136
+      fileName = decodeURIComponent(parts[1]);
136
     }
137
     }
137
   }
138
   }
138
-
139
-  const url = window.URL.createObjectURL(response.data);
139
+console.log(response);
140
+  const url = window.URL.createObjectURL(new Blob([response.data], { type: contentType }));
140
   const link = document.createElement('a');
141
   const link = document.createElement('a');
141
   link.href = url;
142
   link.href = url;
142
   link.setAttribute('download', fileName);
143
   link.setAttribute('download', fileName);