Исправлены расчеты цен в корзине и добавлена логика загрузки единиц для категорий. Обновлены компоненты CartInfo, CartList, CartSummary, VinCategory и VinLeftbar для корректного отображения итоговых цен и улучшения взаимодействия с пользователем.
This commit is contained in:
@ -32,7 +32,7 @@ const CartInfo: React.FC = () => {
|
||||
<h1 className="heading">Корзина</h1>
|
||||
<div className="text-block-4">
|
||||
{summary.totalItems > 0 ? (
|
||||
<>В вашей корзине {summary.totalItems} товара на <strong>{formatPrice(summary.finalPrice)}</strong></>
|
||||
<>В вашей корзине {summary.totalItems} товара на <strong>{formatPrice(summary.totalPrice - summary.totalDiscount)}</strong></>
|
||||
) : (
|
||||
'Ваша корзина пуста'
|
||||
)}
|
||||
|
@ -170,7 +170,7 @@ const CartList: React.FC<CartListProps> = ({ isSummaryStep = false }) => {
|
||||
description={item.description}
|
||||
delivery={item.deliveryTime || 'Уточняется'}
|
||||
deliveryDate={item.deliveryDate || ''}
|
||||
price={formatPrice(item.price, item.currency)}
|
||||
price={formatPrice(item.price * item.quantity, item.currency)}
|
||||
pricePerItem={`${formatPrice(item.price, item.currency)}/шт`}
|
||||
count={item.quantity}
|
||||
comment={item.comment || ''}
|
||||
|
@ -657,9 +657,7 @@ const CartSummary: React.FC<CartSummaryProps> = ({ step, setStep }) => {
|
||||
<div className="w-layout-hflex flex-block-59">
|
||||
<div className="text-block-32">Итого</div>
|
||||
<h4 className="heading-9-copy-copy">
|
||||
{formatPrice(
|
||||
summary.totalPrice - summary.totalDiscount + (selectedDeliveryAddress ? 0 : summary.deliveryPrice)
|
||||
)}
|
||||
{formatPrice(summary.totalPrice - summary.totalDiscount)}
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
@ -835,9 +833,7 @@ const CartSummary: React.FC<CartSummaryProps> = ({ step, setStep }) => {
|
||||
<div className="w-layout-hflex flex-block-59">
|
||||
<div className="text-block-32">Итого</div>
|
||||
<h4 className="heading-9-copy-copy">
|
||||
{formatPrice(
|
||||
summary.totalPrice - summary.totalDiscount + (selectedDeliveryAddress ? 0 : summary.deliveryPrice)
|
||||
)}
|
||||
{formatPrice(summary.totalPrice - summary.totalDiscount)}
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
|
@ -65,8 +65,31 @@ const VinCategory: React.FC<VinCategoryProps> = ({ catalogCode, vehicleId, ssd,
|
||||
const loading = activeTab === 'uzly' ? quickGroupsLoading : categoriesLoading;
|
||||
const error = activeTab === 'uzly' ? quickGroupsError : categoriesError;
|
||||
|
||||
// Загружаем units для категории если нет children (аналогично VinLeftbar)
|
||||
useEffect(() => {
|
||||
if (selectedCategory && activeTab === 'manufacturer') {
|
||||
const categoryId = selectedCategory.categoryid || selectedCategory.quickgroupid || selectedCategory.id;
|
||||
|
||||
// Если нет children и нет загруженных units - загружаем units
|
||||
if ((!selectedCategory.children || selectedCategory.children.length === 0) &&
|
||||
!unitsByCategory[categoryId]) {
|
||||
console.log('🔄 VinCategory: Загружаем units для категории', categoryId);
|
||||
lastCategoryIdRef.current = categoryId;
|
||||
getUnits({
|
||||
variables: {
|
||||
catalogCode,
|
||||
vehicleId,
|
||||
ssd,
|
||||
categoryId
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [selectedCategory, activeTab, catalogCode, vehicleId, ssd, getUnits, unitsByCategory]);
|
||||
|
||||
// Функция для обновления openedPath и catpath в URL
|
||||
const updatePath = (newPath: string[]) => {
|
||||
console.log('🔄 VinCategory: updatePath вызван с newPath:', newPath);
|
||||
setOpenedPath(newPath);
|
||||
if (router) {
|
||||
router.push(
|
||||
@ -86,16 +109,45 @@ const VinCategory: React.FC<VinCategoryProps> = ({ catalogCode, vehicleId, ssd,
|
||||
onCategoryClick();
|
||||
return;
|
||||
}
|
||||
if (category.children && category.children.length > 0) {
|
||||
if (openedPath[level] === (category.quickgroupid || category.categoryid || category.id)) {
|
||||
|
||||
const categoryId = category.quickgroupid || category.categoryid || category.id;
|
||||
|
||||
// Если это режим "От производителя", всегда пытаемся войти в категорию
|
||||
if (activeTab === 'manufacturer') {
|
||||
// Проверяем, открыта ли уже эта категория
|
||||
if (openedPath[level] === categoryId) {
|
||||
// Если уже открыта - закрываем
|
||||
updatePath(openedPath.slice(0, level));
|
||||
} else {
|
||||
updatePath([...openedPath.slice(0, level), (category.quickgroupid || category.categoryid || category.id)]);
|
||||
// Если не открыта - открываем (добавляем в path)
|
||||
updatePath([...openedPath.slice(0, level), categoryId]);
|
||||
|
||||
// Если у категории нет children, загружаем units
|
||||
if ((!category.children || category.children.length === 0) && !unitsByCategory[categoryId]) {
|
||||
console.log('🔄 VinCategory: handleCategoryClick загружает units для категории', categoryId);
|
||||
lastCategoryIdRef.current = categoryId;
|
||||
getUnits({
|
||||
variables: {
|
||||
catalogCode,
|
||||
vehicleId,
|
||||
ssd,
|
||||
categoryId
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Режим "Общие" - используем старую логику
|
||||
if (category.children && category.children.length > 0) {
|
||||
if (openedPath[level] === categoryId) {
|
||||
updatePath(openedPath.slice(0, level));
|
||||
} else {
|
||||
updatePath([...openedPath.slice(0, level), categoryId]);
|
||||
}
|
||||
} else if (category.link && onQuickGroupSelect) {
|
||||
// Для вкладки "Общие" с link=true используем QuickGroup
|
||||
onQuickGroupSelect(category);
|
||||
}
|
||||
} else if (category.link && onQuickGroupSelect) {
|
||||
onQuickGroupSelect(category);
|
||||
} else if (onNodeSelect) {
|
||||
onNodeSelect(category);
|
||||
}
|
||||
};
|
||||
|
||||
@ -177,14 +229,35 @@ const VinCategory: React.FC<VinCategoryProps> = ({ catalogCode, vehicleId, ssd,
|
||||
list = found.children || [];
|
||||
level++;
|
||||
}
|
||||
// Теперь level - это уровень selectedCategory, подкатегории будут на level+1
|
||||
const subcategories = selectedCategory.children || [];
|
||||
if (subcategories.length === 0) return <div style={{ color: "#888", padding: 8 }}>Нет подкатегорий</div>;
|
||||
|
||||
// Показываем либо children, либо units
|
||||
if (subcategories.length === 0) {
|
||||
// Если загружаются units для категории без children
|
||||
const categoryId = selectedCategory.categoryid || selectedCategory.quickgroupid || selectedCategory.id;
|
||||
if (activeTab === 'manufacturer' &&
|
||||
(!selectedCategory.children || selectedCategory.children.length === 0) &&
|
||||
!unitsByCategory[categoryId]) {
|
||||
return <div style={{ color: "#888", padding: 8 }}>Загружаем узлы...</div>;
|
||||
}
|
||||
return <div style={{ color: "#888", padding: 8 }}>Нет подкатегорий</div>;
|
||||
}
|
||||
|
||||
return subcategories.map((subcat: any, idx: number) => (
|
||||
<div
|
||||
className="div-block-131"
|
||||
key={subcat.quickgroupid || subcat.categoryid || subcat.unitid || subcat.id || idx}
|
||||
onClick={() => handleCategoryClick(subcat, level + 1)}
|
||||
onClick={() => {
|
||||
// Для узлов (units) из режима "От производителя" сразу открываем KnotIn
|
||||
if (activeTab === 'manufacturer' && subcat.unitid && onNodeSelect) {
|
||||
console.log('🔍 VinCategory: Открываем узел напрямую:', subcat);
|
||||
onNodeSelect({
|
||||
...subcat,
|
||||
unitid: subcat.unitid || subcat.quickgroupid || subcat.categoryid || subcat.id
|
||||
});
|
||||
} else {
|
||||
handleCategoryClick(subcat, level + 1);
|
||||
}
|
||||
}}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
<div className="text-block-57">{subcat.name}</div>
|
||||
|
@ -90,13 +90,20 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ vehicleInfo, onSearchResults, o
|
||||
}, [router.query.catpath]);
|
||||
|
||||
const handleToggle = (categoryId: string, level: number) => {
|
||||
console.log('🔄 VinLeftbar: handleToggle вызван для categoryId:', categoryId, 'level:', level, 'текущий openedPath:', openedPath);
|
||||
|
||||
if (openedPath[level] === categoryId) {
|
||||
setOpenedPathAndUrl(openedPath.slice(0, level));
|
||||
const newPath = openedPath.slice(0, level);
|
||||
console.log('🔄 VinLeftbar: Закрываем категорию, новый path:', newPath);
|
||||
setOpenedPathAndUrl(newPath);
|
||||
} else {
|
||||
setOpenedPathAndUrl([...openedPath.slice(0, level), categoryId]);
|
||||
const newPath = [...openedPath.slice(0, level), categoryId];
|
||||
console.log('🔄 VinLeftbar: Открываем категорию, новый path:', newPath);
|
||||
setOpenedPathAndUrl(newPath);
|
||||
|
||||
// Загружаем units для категории, если они еще не загружены
|
||||
if (activeTabProp === 'manufacturer' && !unitsByCategory[categoryId]) {
|
||||
console.log('🔄 VinLeftbar: Загружаем units для categoryId:', categoryId);
|
||||
lastCategoryIdRef.current = categoryId;
|
||||
getUnits({
|
||||
variables: {
|
||||
@ -330,7 +337,8 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ vehicleInfo, onSearchResults, o
|
||||
e.preventDefault();
|
||||
if (searchQuery) setSearchQuery('');
|
||||
if (onActiveTabChange) onActiveTabChange('manufacturer');
|
||||
if (onQuickGroupSelect) onQuickGroupSelect(null);
|
||||
// Не вызываем onQuickGroupSelect с null - это вызывает ошибку
|
||||
// Просто переключаем вкладку, а обработка отображения происходит через activeTab
|
||||
}}
|
||||
>
|
||||
От производителя
|
||||
@ -472,13 +480,15 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ vehicleInfo, onSearchResults, o
|
||||
) : (
|
||||
<>
|
||||
{categories.map((category: any, idx: number) => {
|
||||
const isOpen = openedPath.includes(category.quickgroupid);
|
||||
// ИСПРАВЛЕНИЕ: Используем тот же приоритет ID, что и в VinCategory
|
||||
const categoryId = category.quickgroupid || category.categoryid || category.id;
|
||||
const isOpen = openedPath.includes(categoryId);
|
||||
const subcategories = category.children && category.children.length > 0
|
||||
? category.children
|
||||
: unitsByCategory[category.quickgroupid] || [];
|
||||
: unitsByCategory[categoryId] || [];
|
||||
return (
|
||||
<div
|
||||
key={category.quickgroupid}
|
||||
key={categoryId}
|
||||
data-hover="false"
|
||||
data-delay="0"
|
||||
className={`dropdown-4 w-dropdown${isOpen ? " w--open" : ""}`}
|
||||
@ -487,7 +497,7 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ vehicleInfo, onSearchResults, o
|
||||
className={`dropdown-toggle-3 w-dropdown-toggle${isOpen ? " w--open" : ""}`}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
handleToggle(category.quickgroupid, 0);
|
||||
handleToggle(categoryId, 0);
|
||||
}}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
@ -503,14 +513,23 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ vehicleInfo, onSearchResults, o
|
||||
className="dropdown-link-3 w-dropdown-link pl-0"
|
||||
onClick={e => {
|
||||
e.preventDefault();
|
||||
// Если это конечная категория с link=true, открываем QuickGroup
|
||||
if (subcat.link && onQuickGroupSelect) {
|
||||
onQuickGroupSelect(subcat);
|
||||
} else if (onNodeSelect) {
|
||||
onNodeSelect({
|
||||
// Для вкладки "От производителя" всегда открываем узел, не используем QuickGroup
|
||||
if (onNodeSelect) {
|
||||
const nodeToSelect = {
|
||||
...subcat,
|
||||
unitid: subcat.unitid || subcat.quickgroupid || subcat.id
|
||||
};
|
||||
|
||||
// ОТЛАДКА: Логируем передачу узла
|
||||
console.log('🔍 VinLeftbar передает узел:', {
|
||||
unitId: nodeToSelect.unitid,
|
||||
unitName: nodeToSelect.name,
|
||||
hasOriginalSsd: !!subcat.ssd,
|
||||
originalSsd: subcat.ssd ? `${subcat.ssd.substring(0, 50)}...` : 'отсутствует',
|
||||
finalSsd: nodeToSelect.ssd ? `${nodeToSelect.ssd.substring(0, 50)}...` : 'отсутствует'
|
||||
});
|
||||
|
||||
onNodeSelect(nodeToSelect);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
Reference in New Issue
Block a user