|
@@ -1,4 +1,4 @@
|
1
|
|
-import React, { useState, useEffect, useRef } from 'react';
|
|
1
|
+import React, { useState, useEffect, useRef, useMemo } from 'react';
|
2
|
2
|
import { Row, Col, Card, Button, notification } from 'antd';
|
3
|
3
|
import EditableTag from '@/components/EditableTag';
|
4
|
4
|
import { getDishList } from '@/services/dish';
|
|
@@ -17,6 +17,14 @@ export default (props) => {
|
17
|
17
|
const [list, setList] = useState([]);
|
18
|
18
|
const [loading, setLoading] = useState(false);
|
19
|
19
|
const packageRef = useRef();
|
|
20
|
+ const dishRef = useRef();
|
|
21
|
+
|
|
22
|
+ const calorie = useMemo(() => {
|
|
23
|
+ return list.reduce((acc, it) => {
|
|
24
|
+ const dish = dishRef.current.filterItem(it.dishId) || {};
|
|
25
|
+ return acc + dish.calorie || 0;
|
|
26
|
+ }, 0);
|
|
27
|
+ }, [list]);
|
20
|
28
|
|
21
|
29
|
const handlePackageSubmit = ({item, amount}) => {
|
22
|
30
|
packageRef.current = item;
|
|
@@ -50,6 +58,7 @@ export default (props) => {
|
50
|
58
|
const found = list.filter(x => x.dishId === item.id)[0]
|
51
|
59
|
if (found) {
|
52
|
60
|
found.dishAmount = amount;
|
|
61
|
+ found.calorie = item.calorie || 0;
|
53
|
62
|
} else {
|
54
|
63
|
list.push({
|
55
|
64
|
guaranteeId: dataSource.id,
|
|
@@ -125,6 +134,7 @@ export default (props) => {
|
125
|
134
|
<div style={{ marginTop: '48px' }}>
|
126
|
135
|
<h3>选择菜肴</h3>
|
127
|
136
|
<Selector
|
|
137
|
+ ref={dishRef}
|
128
|
138
|
placeholder="请选择菜肴"
|
129
|
139
|
disabled={!dataSource}
|
130
|
140
|
fetch={getDishList}
|
|
@@ -134,7 +144,7 @@ export default (props) => {
|
134
|
144
|
</Col>
|
135
|
145
|
<Col span={16}>
|
136
|
146
|
<Card
|
137
|
|
- title="已选菜肴"
|
|
147
|
+ title={`已选菜肴 共计${calorie}卡`}
|
138
|
148
|
loading={loading}
|
139
|
149
|
extra={<Button disabled={!dataSource} type='primary' loading={loading} onClick={onSubmit}>保存</Button>}
|
140
|
150
|
>
|