._.
This commit is contained in:
parent
e648aeaea5
commit
05f77f2ad6
18
src/api.jsx
18
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;
|
||||
}
|
||||
};
|
||||
@ -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 = () => {
|
||||
</div>
|
||||
) : (
|
||||
<div className="content-container">
|
||||
<h2>Общая стоимость подзаказа: {totalCost} руб.</h2>{" "}
|
||||
<ol className="city-list">
|
||||
{deliveryAccessories.map((accessory, index) => {
|
||||
const coord = coordinates.find(
|
||||
@ -91,7 +97,7 @@ const DeliveryOrderDetails = () => {
|
||||
);
|
||||
return (
|
||||
<li key={accessory.id} className="city-item">
|
||||
<strong>{index + 1}. Доставка:</strong> {accessory.name}
|
||||
<strong>Доставка:</strong> {accessory.accessory_name}
|
||||
<span className="city-info">
|
||||
(Город: {accessory.city_name}, Координаты:{" "}
|
||||
{coord
|
||||
@ -103,8 +109,7 @@ const DeliveryOrderDetails = () => {
|
||||
);
|
||||
})}
|
||||
<li className="city-item">
|
||||
<strong>{deliveryAccessories.length + 1}. Конечный пункт:</strong>{" "}
|
||||
{DELIVERY_CITY.name}
|
||||
<strong>Конечный пункт:</strong> {DELIVERY_CITY.name}
|
||||
<span className="city-info">
|
||||
(Координаты: {DELIVERY_CITY.latitude}, {DELIVERY_CITY.longitude}
|
||||
)
|
||||
|
||||
@ -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`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user