This commit is contained in:
Андрей Дувакин 2024-10-08 11:00:06 +05:00
parent 68468ee72e
commit 7dbf147cef
3 changed files with 36 additions and 7 deletions

View File

@ -31,6 +31,13 @@ const DeliveryOrdersList = ({
fetchDeliveryOrders();
}, [totalOrderId]);
const formatPrice = (price) => {
if (!price) {
return "не указана";
}
return `${Math.round(price)}`;
};
const fetchDeliveryOrders = async () => {
try {
const orders = await getDeliveryOrders(totalOrderId);
@ -167,6 +174,7 @@ const DeliveryOrdersList = ({
Прогнозируемое время этапа:{" "}
{formatTimeInHours(order.estimated_route_time_in_minutes)}
</p>
<p>Стоимость: {formatPrice(order.price)}</p>
{calculatingRoutes.includes(order.id) && (
<div className="spinner-border" role="status">
<span className="visually-hidden"></span>

View File

@ -250,12 +250,18 @@ const DeliveryOrderDetails = () => {
<td>{accessory.accessory_name}</td>
<td>
{Math.round(
(accessory.accessory_volume * accessory.count) / 100
(accessory.accessory_volume / 100) *
totalOrder.count_robots
)}
</td>
<td>
{Math.round(
(accessory.accessory_weight * accessory.count) / 100
(Math.round(
(accessory.accessory_volume / 100) *
totalOrder.count_robots
) /
100) *
accessory.accessory_weight
)}
</td>
</tr>

View File

@ -52,11 +52,16 @@ const Home = () => {
}
};
const formatTimeInHours = (minutes) => {
if (!minutes || minutes === 0) {
return "ещё не рассчитывалось";
}
return (minutes / 60).toFixed(2) + " час.";
const formatDuration = (minutes) => {
const days = Math.floor(minutes / (24 * 60));
const hours = Math.floor((minutes % (24 * 60)) / 60);
const remainingMinutes = Math.floor(minutes % 60);
return {
days,
hours,
minutes: remainingMinutes,
};
};
const handleCreateOrder = async ({ deadline, robotsCount }) => {
@ -133,6 +138,7 @@ const Home = () => {
<th>Количество роботов</th>
<th>Количество этапов</th>
<th>Итоговая цена</th>
<th>Общее время подзаказов</th>
</tr>
</thead>
<tbody>
@ -141,6 +147,15 @@ const Home = () => {
<td>{order.count_robots}</td>
<td>{deliveryOrdersCount || 0}</td>
<td>{order.price || 0} </td>
<td>
{(() => {
const { days, hours, minutes } =
formatDuration(totalEstimatedTime);
return days > 0
? `${days} дн. ${hours} ч.`
: `${hours} ч.`;
})()}
</td>
</tr>
</tbody>
</table>