This commit is contained in:
Андрей Дувакин 2024-10-08 11:18:39 +05:00
parent 7dbf147cef
commit 09d0b03834

View File

@ -43,7 +43,6 @@ const DeliveryOrderDetails = () => {
useEffect(() => { useEffect(() => {
fetchDeliveryOrder(); fetchDeliveryOrder();
fetchDeliveryAccessories();
}, [deliveryOrderId]); }, [deliveryOrderId]);
const formatDuration = (minutes) => { const formatDuration = (minutes) => {
@ -74,6 +73,9 @@ const DeliveryOrderDetails = () => {
try { try {
const order = await getTotalOrder(orderId); const order = await getTotalOrder(orderId);
setTotalOrder(order); setTotalOrder(order);
if (order) {
fetchDeliveryAccessories(order);
}
} catch (error) { } catch (error) {
if (error.response && error.response.status === 401) { if (error.response && error.response.status === 401) {
navigate("/login"); navigate("/login");
@ -82,7 +84,7 @@ const DeliveryOrderDetails = () => {
} }
}; };
const fetchDeliveryAccessories = async () => { const fetchDeliveryAccessories = async (totalOrder) => {
try { try {
const deliveryOrderDetails = await getDeliveryOrderDetails( const deliveryOrderDetails = await getDeliveryOrderDetails(
deliveryOrderId deliveryOrderId
@ -95,12 +97,17 @@ const DeliveryOrderDetails = () => {
const accessories = await getDeliveryAccessories(deliveryOrderId); const accessories = await getDeliveryAccessories(deliveryOrderId);
setDeliveryAccessories(accessories); setDeliveryAccessories(accessories);
const totalWeightCalculated = accessories.reduce((acc, accessory) => { if (totalOrder) {
return ( const totalWeightCalculated = accessories.reduce((acc, accessory) => {
acc + Math.round((accessory.accessory_weight * accessory.count) / 100) return (
); acc +
}, 0); Math.round(
setTotalWeight(totalWeightCalculated); (accessory.accessory_weight / 100) * totalOrder.count_robots
)
);
}, 0);
setTotalWeight(totalWeightCalculated);
}
const coords = await Promise.all( const coords = await Promise.all(
accessories.map(async (accessory) => { accessories.map(async (accessory) => {
@ -256,12 +263,8 @@ const DeliveryOrderDetails = () => {
</td> </td>
<td> <td>
{Math.round( {Math.round(
(Math.round( (accessory.accessory_weight / 100) *
(accessory.accessory_volume / 100) * totalOrder.count_robots
totalOrder.count_robots
) /
100) *
accessory.accessory_weight
)} )}
</td> </td>
</tr> </tr>