._.
This commit is contained in:
parent
e648aeaea5
commit
05f77f2ad6
18
src/api.jsx
18
src/api.jsx
@ -523,3 +523,21 @@ export const getDeliveryAccessories = async (deliveryOrderId) => {
|
|||||||
throw 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 React, { useState, useEffect } from "react";
|
||||||
import { getDeliveryAccessories } from "../api.jsx";
|
import { getDeliveryAccessories, getDeliveryOrderDetails } from "../api.jsx";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { getCoordinates } from "../geocoder.jsx";
|
import { getCoordinates } from "../geocoder.jsx";
|
||||||
import {
|
import {
|
||||||
@ -25,6 +25,7 @@ const DeliveryOrderDetails = () => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [coordinates, setCoordinates] = useState([]);
|
const [coordinates, setCoordinates] = useState([]);
|
||||||
const [route, setRoute] = useState([]);
|
const [route, setRoute] = useState([]);
|
||||||
|
const [totalCost, setTotalCost] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchDeliveryAccessories();
|
fetchDeliveryAccessories();
|
||||||
@ -32,12 +33,16 @@ const DeliveryOrderDetails = () => {
|
|||||||
|
|
||||||
const fetchDeliveryAccessories = async () => {
|
const fetchDeliveryAccessories = async () => {
|
||||||
try {
|
try {
|
||||||
|
const deliveryOrderDetails = await getDeliveryOrderDetails(
|
||||||
|
deliveryOrderId
|
||||||
|
);
|
||||||
|
setTotalCost(deliveryOrderDetails.price);
|
||||||
|
|
||||||
const accessories = await getDeliveryAccessories(deliveryOrderId);
|
const accessories = await getDeliveryAccessories(deliveryOrderId);
|
||||||
setDeliveryAccessories(accessories);
|
setDeliveryAccessories(accessories);
|
||||||
|
|
||||||
const coords = await Promise.all(
|
const coords = await Promise.all(
|
||||||
accessories.map(async (accessory) => {
|
accessories.map(async (accessory) => {
|
||||||
console.log(accessory);
|
|
||||||
if (accessory.latitude && accessory.longitude) {
|
if (accessory.latitude && accessory.longitude) {
|
||||||
return {
|
return {
|
||||||
city: accessory.city_name,
|
city: accessory.city_name,
|
||||||
@ -84,6 +89,7 @@ const DeliveryOrderDetails = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="content-container">
|
<div className="content-container">
|
||||||
|
<h2>Общая стоимость подзаказа: {totalCost} руб.</h2>{" "}
|
||||||
<ol className="city-list">
|
<ol className="city-list">
|
||||||
{deliveryAccessories.map((accessory, index) => {
|
{deliveryAccessories.map((accessory, index) => {
|
||||||
const coord = coordinates.find(
|
const coord = coordinates.find(
|
||||||
@ -91,7 +97,7 @@ const DeliveryOrderDetails = () => {
|
|||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<li key={accessory.id} className="city-item">
|
<li key={accessory.id} className="city-item">
|
||||||
<strong>{index + 1}. Доставка:</strong> {accessory.name}
|
<strong>Доставка:</strong> {accessory.accessory_name}
|
||||||
<span className="city-info">
|
<span className="city-info">
|
||||||
(Город: {accessory.city_name}, Координаты:{" "}
|
(Город: {accessory.city_name}, Координаты:{" "}
|
||||||
{coord
|
{coord
|
||||||
@ -103,8 +109,7 @@ const DeliveryOrderDetails = () => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<li className="city-item">
|
<li className="city-item">
|
||||||
<strong>{deliveryAccessories.length + 1}. Конечный пункт:</strong>{" "}
|
<strong>Конечный пункт:</strong> {DELIVERY_CITY.name}
|
||||||
{DELIVERY_CITY.name}
|
|
||||||
<span className="city-info">
|
<span className="city-info">
|
||||||
(Координаты: {DELIVERY_CITY.latitude}, {DELIVERY_CITY.longitude}
|
(Координаты: {DELIVERY_CITY.latitude}, {DELIVERY_CITY.longitude}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -17,14 +17,6 @@ const Home = () => {
|
|||||||
setEndPoint(e.target.value);
|
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(() => {
|
useEffect(() => {
|
||||||
if (startCoords && endCoords) {
|
if (startCoords && endCoords) {
|
||||||
const routeUrl = `https://router.project-osrm.org/route/v1/driving/${startCoords.lng},${startCoords.lat};${endCoords.lng},${endCoords.lat}?overview=full`;
|
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