From 644653c08d73d6e4c7b242f47d67bc0658cf616e Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 8 Oct 2024 10:05:00 +0500 Subject: [PATCH] ._. --- src/api.jsx | 4 - src/components/DeliveryOrdersList.jsx | 142 +++++++++++++------------- src/pages/Home.jsx | 2 + 3 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/api.jsx b/src/api.jsx index 662b349..abbf654 100755 --- a/src/api.jsx +++ b/src/api.jsx @@ -566,10 +566,6 @@ export const updateDeliveryOrderRoute = async ( estimatedRouteTime, route ) => { - console.log({ - estimated_route_time_in_minutes: estimatedRouteTime, - route: route, - }); try { const response = await axios.put( `${API_URL}/delivery-orders/${deliveryOrderId}/route`, diff --git a/src/components/DeliveryOrdersList.jsx b/src/components/DeliveryOrdersList.jsx index be9f2f4..c56f071 100644 --- a/src/components/DeliveryOrdersList.jsx +++ b/src/components/DeliveryOrdersList.jsx @@ -53,84 +53,84 @@ const DeliveryOrdersList = ({ }; const calculateRoutes = async () => { - const ordersToCalculate = deliveryOrders.filter( - (order) => !order.estimated_route_time_in_minutes - ); + const ordersToCalculate = deliveryOrders.filter( + (order) => !order.estimated_route_time_in_minutes + ); - setCalculatingRoutes(ordersToCalculate.map((order) => order.id)); + setCalculatingRoutes(ordersToCalculate.map((order) => order.id)); - await Promise.all( - ordersToCalculate.map(async (order) => { - try { - const deliveryOrderDetails = await getDeliveryOrderDetails(order.id); - const accessories = await getDeliveryAccessories( - deliveryOrderDetails.id - ); + await Promise.all( + ordersToCalculate.map(async (order) => { + try { + const deliveryOrderDetails = await getDeliveryOrderDetails(order.id); + const accessories = await getDeliveryAccessories( + deliveryOrderDetails.id + ); - const coords = await Promise.all( - accessories.map(async (accessory) => { - if (accessory.latitude && accessory.longitude) { - return { - city: accessory.city_name, - latitude: accessory.latitude, - longitude: accessory.longitude, - accessory_name: - accessory.accessory_name + - Math.round( - (accessory.accessory_volume * accessory.count) / 100 - ) + - "шт.", - }; - } else { - const coords = await getCoordinates(accessory.city_name); - return { - city: accessory.city_name, - accessory_name: - accessory.accessory_name + - ": " + - Math.round( - (accessory.accessory_volume * accessory.count) / 100 - ) + - "шт.", - ...coords, - }; + const coords = await Promise.all( + accessories.map(async (accessory) => { + if (accessory.latitude && accessory.longitude) { + return { + city: accessory.city_name, + latitude: accessory.latitude, + longitude: accessory.longitude, + accessory_name: + accessory.accessory_name + + Math.round( + (accessory.accessory_volume * accessory.count) / 100 + ) + + "шт.", + }; + } else { + const coords = await getCoordinates(accessory.city_name); + return { + city: accessory.city_name, + accessory_name: + accessory.accessory_name + + ": " + + Math.round( + (accessory.accessory_volume * accessory.count) / 100 + ) + + "шт.", + ...coords, + }; + } + }) + ); + + const fullCoordinates = [...coords, DELIVERY_CITY]; + + if (fullCoordinates.length > 1) { + const waypoints = fullCoordinates + .map(({ longitude, latitude }) => `${longitude},${latitude}`) + .join(";"); + + const routeUrl = `https://router.project-osrm.org/route/v1/driving/${waypoints}?overview=full`; + + const response = await fetch(routeUrl); + const data = await response.json(); + + if (data.routes && data.routes.length > 0) { + const geometry = data.routes[0].geometry; + const decodedRoute = polyline.decode(geometry); + const duration = data.routes[0].duration; + + await updateDeliveryOrderRoute( + order.id, + duration / 60, + decodedRoute + ); } - }) - ); - - const fullCoordinates = [...coords, DELIVERY_CITY]; - - if (fullCoordinates.length > 1) { - const waypoints = fullCoordinates - .map(({ longitude, latitude }) => `${longitude},${latitude}`) - .join(";"); - - const routeUrl = `https://router.project-osrm.org/route/v1/driving/${waypoints}?overview=full`; - - const response = await fetch(routeUrl); - const data = await response.json(); - - if (data.routes && data.routes.length > 0) { - const geometry = data.routes[0].geometry; - const decodedRoute = polyline.decode(geometry); - const duration = data.routes[0].duration; - - await updateDeliveryOrderRoute( - order.id, - duration / 60, - decodedRoute - ); } + } catch (error) { + console.error("Ошибка при расчете маршрута для подзаказа:", error); } - } catch (error) { - console.error("Ошибка при расчете маршрута для подзаказа:", error); - } - }) - ); - - fetchDeliveryOrders(); -}; + }) + ); + await fetchDeliveryOrders(); + setCalculatingRoutes([]); + }; const ordersToCalculate = deliveryOrders.filter( (order) => !order.estimated_route_time_in_minutes diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index fabd650..9f6c56d 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -124,6 +124,7 @@ const Home = () => { Статус Количество роботов Количество этапов + Итоговая цена @@ -131,6 +132,7 @@ const Home = () => { {order.status_name || "Неизвестный статус"} {order.count_robots} {deliveryOrdersCount || 0} + {order.price || 0} руб.