diff --git a/src/api.jsx b/src/api.jsx index 4b1f80b..e1d3af4 100755 --- a/src/api.jsx +++ b/src/api.jsx @@ -522,4 +522,22 @@ export const getDeliveryAccessories = async (deliveryOrderId) => { console.log("Ошибка при загрузке доставок:", error); throw error; } +}; + +export const getDeliveryOrderDetails = async (deliveryOrderId) => { + try { + const response = await axios.get( + `${API_URL}/delivery-orders/${deliveryOrderId}`, + { + headers: { + Authorization: `Bearer ${getAuthToken()}`, + Accept: "application/json", + }, + } + ); + return response.data; + } catch (error) { + console.log("Ошибка при загрузке деталей заказа доставки:", error); + throw error; + } }; \ No newline at end of file diff --git a/src/pages/DeliveryOrderDetails.jsx b/src/pages/DeliveryOrderDetails.jsx index c3e6790..aabd084 100644 --- a/src/pages/DeliveryOrderDetails.jsx +++ b/src/pages/DeliveryOrderDetails.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { getDeliveryAccessories } from "../api.jsx"; +import { getDeliveryAccessories, getDeliveryOrderDetails } from "../api.jsx"; import { useParams } from "react-router-dom"; import { getCoordinates } from "../geocoder.jsx"; import { @@ -25,6 +25,7 @@ const DeliveryOrderDetails = () => { const [loading, setLoading] = useState(true); const [coordinates, setCoordinates] = useState([]); const [route, setRoute] = useState([]); + const [totalCost, setTotalCost] = useState(0); useEffect(() => { fetchDeliveryAccessories(); @@ -32,12 +33,16 @@ const DeliveryOrderDetails = () => { const fetchDeliveryAccessories = async () => { try { + const deliveryOrderDetails = await getDeliveryOrderDetails( + deliveryOrderId + ); + setTotalCost(deliveryOrderDetails.price); + const accessories = await getDeliveryAccessories(deliveryOrderId); setDeliveryAccessories(accessories); const coords = await Promise.all( - accessories.map(async (accessory) => { - console.log(accessory); + accessories.map(async (accessory) => { if (accessory.latitude && accessory.longitude) { return { city: accessory.city_name, @@ -84,6 +89,7 @@ const DeliveryOrderDetails = () => { ) : (
+

Общая стоимость подзаказа: {totalCost} руб.

{" "}
    {deliveryAccessories.map((accessory, index) => { const coord = coordinates.find( @@ -91,7 +97,7 @@ const DeliveryOrderDetails = () => { ); return (
  1. - {index + 1}. Доставка: {accessory.name} + Доставка: {accessory.accessory_name} (Город: {accessory.city_name}, Координаты:{" "} {coord @@ -103,8 +109,7 @@ const DeliveryOrderDetails = () => { ); })}
  2. - {deliveryAccessories.length + 1}. Конечный пункт:{" "} - {DELIVERY_CITY.name} + Конечный пункт: {DELIVERY_CITY.name} (Координаты: {DELIVERY_CITY.latitude}, {DELIVERY_CITY.longitude} ) diff --git a/src/pages/Map.jsx b/src/pages/Map.jsx index 479edce..1825912 100644 --- a/src/pages/Map.jsx +++ b/src/pages/Map.jsx @@ -17,14 +17,6 @@ const Home = () => { setEndPoint(e.target.value); }; - const handleSearch = () => { - // Замените на реальный геокодер для получения координат на основе адресов - const start = { lat: 55.7558, lng: 37.6173 }; // Москва - const end = { lat: 59.9343, lng: 30.3351 }; // Санкт-Петербург - setStartCoords(start); - setEndCoords(end); - }; - useEffect(() => { if (startCoords && endCoords) { const routeUrl = `https://router.project-osrm.org/route/v1/driving/${startCoords.lng},${startCoords.lat};${endCoords.lng},${endCoords.lat}?overview=full`;