This commit is contained in:
Андрей Дувакин 2024-10-08 09:49:47 +05:00
parent 66e2f4362d
commit 6ef4ec1fda

View File

@ -1,4 +1,10 @@
import { getDeliveryOrders, updateDeliveryOrderRoute } from "../api.jsx"; import {
getDeliveryOrders,
updateDeliveryOrderRoute,
getDeliveryOrderDetails,
getDeliveryAccessories,
} from "../api.jsx";
import { getCoordinates } from "../geocoder.jsx";
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import polyline from "@mapbox/polyline"; import polyline from "@mapbox/polyline";
@ -56,65 +62,66 @@ const DeliveryOrdersList = ({
await Promise.all( await Promise.all(
ordersToCalculate.map(async (order) => { ordersToCalculate.map(async (order) => {
try { try {
// const deliveryOrderDetails = await getDeliveryOrderDetails(order.id); const deliveryOrderDetails = await getDeliveryOrderDetails(order.id);
const accessories = await getDeliveryAccessories(
deliveryOrderDetails.id
);
// const coords = await Promise.all( const coords = await Promise.all(
// accessories.map(async (accessory) => { accessories.map(async (accessory) => {
// if (accessory.latitude && accessory.longitude) { if (accessory.latitude && accessory.longitude) {
// return { return {
// city: accessory.city_name, city: accessory.city_name,
// latitude: accessory.latitude, latitude: accessory.latitude,
// longitude: accessory.longitude, longitude: accessory.longitude,
// accessory_name: accessory_name:
// accessory.accessory_name + accessory.accessory_name +
// Math.round( Math.round(
// (accessory.accessory_volume * accessory.count) / 100 (accessory.accessory_volume * accessory.count) / 100
// ) + ) +
// "шт.", "шт.",
// }; };
// } else { } else {
// const coords = await getCoordinates(accessory.city_name); const coords = await getCoordinates(accessory.city_name);
// return { return {
// city: accessory.city_name, city: accessory.city_name,
// accessory_name: accessory_name:
// accessory.accessory_name + accessory.accessory_name +
// ": " + ": " +
// Math.round( Math.round(
// (accessory.accessory_volume * accessory.count) / 100 (accessory.accessory_volume * accessory.count) / 100
// ) + ) +
// "шт.", "шт.",
// ...coords, ...coords,
// }; };
// } }
// }) })
// ); );
// if (fullCoordinates.length > 1) { if (fullCoordinates.length > 1) {
// const waypoints = fullCoordinates const waypoints = fullCoordinates
// .map(({ longitude, latitude }) => `${longitude},${latitude}`) .map(({ longitude, latitude }) => `${longitude},${latitude}`)
// .join(";"); .join(";");
// const routeUrl = `https://router.project-osrm.org/route/v1/driving/${waypoints}?overview=full`; const routeUrl = `https://router.project-osrm.org/route/v1/driving/${waypoints}?overview=full`;
// const response = await fetch(routeUrl); const response = await fetch(routeUrl);
// const data = await response.json(); const data = await response.json();
// if (data.routes && data.routes.length > 0) { if (data.routes && data.routes.length > 0) {
// const geometry = data.routes[0].geometry; const geometry = data.routes[0].geometry;
// const decodedRoute = polyline.decode(geometry); const decodedRoute = polyline.decode(geometry);
// setRoute(decodedRoute); const duration = data.routes[0].duration;
// const duration = data.routes[0].duration;
// setOrderDuration(duration);
// await updateDeliveryOrderRoute( await updateDeliveryOrderRoute(
// order.id, order.id,
// duration / 60, duration / 60,
// decodedRoute decodedRoute
// ); );
// } }
// } }
// const fullCoordinates = [...coords, DELIVERY_CITY]; const fullCoordinates = [...coords, DELIVERY_CITY];
const routeUrl = `https://router.project-osrm.org/route/v1/driving/${order.start_longitude},${order.start_latitude};${order.end_longitude},${order.end_latitude}?overview=full`; const routeUrl = `https://router.project-osrm.org/route/v1/driving/${order.start_longitude},${order.start_latitude};${order.end_longitude},${order.end_latitude}?overview=full`;
const response = await fetch(routeUrl); const response = await fetch(routeUrl);