From 7dbf147cef5e4cfa5fed0a823f1b37a032ad10a6 Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 8 Oct 2024 11:00:06 +0500 Subject: [PATCH] ._. --- src/components/DeliveryOrdersList.jsx | 8 ++++++++ src/pages/DeliveryOrderDetails.jsx | 10 ++++++++-- src/pages/Home.jsx | 25 ++++++++++++++++++++----- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/components/DeliveryOrdersList.jsx b/src/components/DeliveryOrdersList.jsx index f02e6fa..17d90f5 100644 --- a/src/components/DeliveryOrdersList.jsx +++ b/src/components/DeliveryOrdersList.jsx @@ -31,6 +31,13 @@ const DeliveryOrdersList = ({ fetchDeliveryOrders(); }, [totalOrderId]); + const formatPrice = (price) => { + if (!price) { + return "не указана"; + } + return `${Math.round(price)} ₽`; + }; + const fetchDeliveryOrders = async () => { try { const orders = await getDeliveryOrders(totalOrderId); @@ -167,6 +174,7 @@ const DeliveryOrdersList = ({ Прогнозируемое время этапа:{" "} {formatTimeInHours(order.estimated_route_time_in_minutes)}

+

Стоимость: {formatPrice(order.price)}

{calculatingRoutes.includes(order.id) && (
diff --git a/src/pages/DeliveryOrderDetails.jsx b/src/pages/DeliveryOrderDetails.jsx index 0866abf..ec7ccd5 100644 --- a/src/pages/DeliveryOrderDetails.jsx +++ b/src/pages/DeliveryOrderDetails.jsx @@ -250,12 +250,18 @@ const DeliveryOrderDetails = () => { {accessory.accessory_name} {Math.round( - (accessory.accessory_volume * accessory.count) / 100 + (accessory.accessory_volume / 100) * + totalOrder.count_robots )} {Math.round( - (accessory.accessory_weight * accessory.count) / 100 + (Math.round( + (accessory.accessory_volume / 100) * + totalOrder.count_robots + ) / + 100) * + accessory.accessory_weight )} diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index cc409ca..b7f221d 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -52,11 +52,16 @@ const Home = () => { } }; - const formatTimeInHours = (minutes) => { - if (!minutes || minutes === 0) { - return "ещё не рассчитывалось"; - } - return (minutes / 60).toFixed(2) + " час."; + const formatDuration = (minutes) => { + const days = Math.floor(minutes / (24 * 60)); + const hours = Math.floor((minutes % (24 * 60)) / 60); + const remainingMinutes = Math.floor(minutes % 60); + + return { + days, + hours, + minutes: remainingMinutes, + }; }; const handleCreateOrder = async ({ deadline, robotsCount }) => { @@ -133,6 +138,7 @@ const Home = () => { Количество роботов Количество этапов Итоговая цена + Общее время подзаказов @@ -141,6 +147,15 @@ const Home = () => { {order.count_robots} {deliveryOrdersCount || 0} {order.price || 0} ₽ + + {(() => { + const { days, hours, minutes } = + formatDuration(totalEstimatedTime); + return days > 0 + ? `${days} дн. ${hours} ч.` + : `${hours} ч.`; + })()} +