Удалены модальные окна выбора бренда из компонентов PartDetailCard, KnotParts, VinPartCard и VinQuick. Вместо этого добавлена логика для перехода на страницу выбора бренда при клике на деталь. Обновлены компоненты для передачи параметров catalogCode и vehicleId. Исправлены типы и улучшена читаемость кода.
This commit is contained in:
@ -3,7 +3,6 @@ import { useRouter } from 'next/router';
|
||||
import { useLazyQuery } from '@apollo/client';
|
||||
import { LaximoOEMResult } from '@/types/laximo';
|
||||
import { SEARCH_LAXIMO_OEM } from '@/lib/graphql';
|
||||
import BrandSelectionModal from './BrandSelectionModal';
|
||||
|
||||
interface PartDetailCardProps {
|
||||
oem: string;
|
||||
@ -30,7 +29,6 @@ const PartDetailCard: React.FC<PartDetailCardProps> = ({
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
const [localExpanded, setLocalExpanded] = useState(false);
|
||||
const [isBrandModalOpen, setIsBrandModalOpen] = useState(false);
|
||||
|
||||
// Используем локальное состояние если нет внешнего контроля
|
||||
const expanded = onToggleExpand ? isExpanded : localExpanded;
|
||||
@ -53,13 +51,12 @@ const PartDetailCard: React.FC<PartDetailCardProps> = ({
|
||||
|
||||
const handleFindOffers = () => {
|
||||
console.log('🔍 Выбрана деталь для поиска предложений:', name, 'OEM:', oem);
|
||||
// Показываем модал выбора бренда
|
||||
setIsBrandModalOpen(true);
|
||||
// Переходим на страницу выбора бренда
|
||||
const url = `/vehicle-search/${catalogCode}/${vehicleId}/part/${oem}/brands?detailName=${encodeURIComponent(name || '')}`;
|
||||
router.push(url);
|
||||
};
|
||||
|
||||
const handleCloseBrandModal = () => {
|
||||
setIsBrandModalOpen(false);
|
||||
};
|
||||
|
||||
|
||||
const handleOpenFullInfo = () => {
|
||||
// Переход на отдельную страницу с детальной информацией о детали
|
||||
@ -250,13 +247,6 @@ const PartDetailCard: React.FC<PartDetailCardProps> = ({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Модал выбора бренда */}
|
||||
<BrandSelectionModal
|
||||
isOpen={isBrandModalOpen}
|
||||
onClose={handleCloseBrandModal}
|
||||
articleNumber={oem}
|
||||
detailName={name}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
import React, { useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import BrandSelectionModal from '../BrandSelectionModal';
|
||||
|
||||
interface KnotPartsProps {
|
||||
parts?: Array<{
|
||||
@ -15,16 +14,18 @@ interface KnotPartsProps {
|
||||
attributes?: Array<{ key: string; name?: string; value: string }>;
|
||||
}>;
|
||||
selectedCodeOnImage?: string | number;
|
||||
catalogCode?: string;
|
||||
vehicleId?: string;
|
||||
}
|
||||
|
||||
const KnotParts: React.FC<KnotPartsProps> = ({ parts = [], selectedCodeOnImage }) => {
|
||||
const [isBrandModalOpen, setIsBrandModalOpen] = useState(false);
|
||||
const [selectedDetail, setSelectedDetail] = useState<{ oem: string; name: string } | null>(null);
|
||||
const KnotParts: React.FC<KnotPartsProps> = ({ parts = [], selectedCodeOnImage, catalogCode, vehicleId }) => {
|
||||
const router = useRouter();
|
||||
|
||||
const handlePriceClick = (part: any) => {
|
||||
if (part.oem) {
|
||||
setSelectedDetail({ oem: part.oem, name: part.name || '' });
|
||||
setIsBrandModalOpen(true);
|
||||
if (part.oem && catalogCode && vehicleId !== undefined) {
|
||||
// Переходим на страницу выбора бренда
|
||||
const url = `/vehicle-search/${catalogCode}/${vehicleId}/part/${part.oem}/brands?detailName=${encodeURIComponent(part.name || '')}`;
|
||||
router.push(url);
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,12 +73,6 @@ const KnotParts: React.FC<KnotPartsProps> = ({ parts = [], selectedCodeOnImage }
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<BrandSelectionModal
|
||||
isOpen={isBrandModalOpen}
|
||||
onClose={() => setIsBrandModalOpen(false)}
|
||||
articleNumber={selectedDetail?.oem || ''}
|
||||
detailName={selectedDetail?.name || ''}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useLazyQuery, useQuery } from '@apollo/client';
|
||||
import { GET_LAXIMO_FULLTEXT_SEARCH, GET_LAXIMO_CATEGORIES, GET_LAXIMO_UNITS, GET_LAXIMO_QUICK_GROUPS, GET_LAXIMO_QUICK_DETAIL } from '@/lib/graphql/laximo';
|
||||
import VinPartCard from './VinPartCard';
|
||||
|
||||
interface VinLeftbarProps {
|
||||
vehicleInfo?: {
|
||||
|
@ -1,22 +1,27 @@
|
||||
import React, { useState } from "react";
|
||||
import React from "react";
|
||||
import { useRouter } from 'next/router';
|
||||
import BrandSelectionModal from '../BrandSelectionModal';
|
||||
|
||||
interface VinPartCardProps {
|
||||
n?: number;
|
||||
oem: string;
|
||||
name: string;
|
||||
onPriceClick?: () => void;
|
||||
catalogCode?: string;
|
||||
vehicleId?: string;
|
||||
}
|
||||
|
||||
const VinPartCard: React.FC<VinPartCardProps> = ({ n, oem, name, onPriceClick }) => {
|
||||
const VinPartCard: React.FC<VinPartCardProps> = ({ n, oem, name, onPriceClick, catalogCode, vehicleId }) => {
|
||||
const router = useRouter();
|
||||
const [isBrandModalOpen, setIsBrandModalOpen] = useState(false);
|
||||
|
||||
const handlePriceClick = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
if (onPriceClick) onPriceClick();
|
||||
setIsBrandModalOpen(true);
|
||||
|
||||
if (catalogCode && vehicleId !== undefined) {
|
||||
// Переходим на страницу выбора бренда
|
||||
const url = `/vehicle-search/${catalogCode}/${vehicleId}/part/${oem}/brands?detailName=${encodeURIComponent(name || '')}`;
|
||||
router.push(url);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@ -36,12 +41,6 @@ const VinPartCard: React.FC<VinPartCardProps> = ({ n, oem, name, onPriceClick })
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<BrandSelectionModal
|
||||
isOpen={isBrandModalOpen}
|
||||
onClose={() => setIsBrandModalOpen(false)}
|
||||
articleNumber={oem}
|
||||
detailName={name}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { useRouter } from 'next/router';
|
||||
import { GET_LAXIMO_QUICK_DETAIL } from '@/lib/graphql/laximo';
|
||||
import BrandSelectionModal from '../BrandSelectionModal';
|
||||
|
||||
interface VinQuickProps {
|
||||
quickGroup: any;
|
||||
@ -13,6 +13,8 @@ interface VinQuickProps {
|
||||
}
|
||||
|
||||
const VinQuick: React.FC<VinQuickProps> = ({ quickGroup, catalogCode, vehicleId, ssd, onBack, onNodeSelect }) => {
|
||||
const router = useRouter();
|
||||
|
||||
const { data, loading, error } = useQuery(GET_LAXIMO_QUICK_DETAIL, {
|
||||
variables: {
|
||||
catalogCode,
|
||||
@ -24,11 +26,6 @@ const VinQuick: React.FC<VinQuickProps> = ({ quickGroup, catalogCode, vehicleId,
|
||||
});
|
||||
const quickDetail = data?.laximoQuickDetail;
|
||||
|
||||
|
||||
|
||||
const [isBrandModalOpen, setIsBrandModalOpen] = useState(false);
|
||||
const [selectedDetail, setSelectedDetail] = useState<any>(null);
|
||||
|
||||
const handleUnitClick = (unit: any) => {
|
||||
onNodeSelect({
|
||||
...unit,
|
||||
@ -39,13 +36,13 @@ const VinQuick: React.FC<VinQuickProps> = ({ quickGroup, catalogCode, vehicleId,
|
||||
ssd: unit.ssd || ssd // Используем SSD узла, а не родительский
|
||||
});
|
||||
};
|
||||
|
||||
const handleDetailClick = (detail: any) => {
|
||||
setSelectedDetail(detail);
|
||||
setIsBrandModalOpen(true);
|
||||
};
|
||||
const handleCloseBrandModal = () => {
|
||||
setIsBrandModalOpen(false);
|
||||
setSelectedDetail(null);
|
||||
if (detail.oem) {
|
||||
// Переходим на страницу выбора бренда
|
||||
const url = `/vehicle-search/${catalogCode}/${vehicleId}/part/${detail.oem}/brands?detailName=${encodeURIComponent(detail.name || '')}`;
|
||||
router.push(url);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@ -90,14 +87,6 @@ const VinQuick: React.FC<VinQuickProps> = ({ quickGroup, catalogCode, vehicleId,
|
||||
) : (
|
||||
<div className="text-center text-gray-500 py-4">Нет деталей для этой группы</div>
|
||||
)}
|
||||
{isBrandModalOpen && selectedDetail && (
|
||||
<BrandSelectionModal
|
||||
isOpen={isBrandModalOpen}
|
||||
onClose={handleCloseBrandModal}
|
||||
articleNumber={selectedDetail.oem}
|
||||
detailName={selectedDetail.name}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -362,6 +362,8 @@ const VehicleDetailsPage = () => {
|
||||
n={idx + 1}
|
||||
name={detail.name}
|
||||
oem={detail.oem}
|
||||
catalogCode={vehicleInfo.catalog}
|
||||
vehicleId={vehicleInfo.vehicleid}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
@ -419,7 +421,11 @@ const VehicleDetailsPage = () => {
|
||||
) : unitDetailsError ? (
|
||||
<div style={{ color: 'red', padding: 24 }}>Ошибка загрузки деталей: {unitDetailsError.message}</div>
|
||||
) : unitDetails.length > 0 ? (
|
||||
<KnotParts parts={unitDetails} />
|
||||
<KnotParts
|
||||
parts={unitDetails}
|
||||
catalogCode={vehicleInfo.catalog}
|
||||
vehicleId={vehicleInfo.vehicleid}
|
||||
/>
|
||||
) : (
|
||||
<div style={{ padding: 24, textAlign: 'center' }}>Детали не найдены</div>
|
||||
)}
|
||||
|
@ -0,0 +1,259 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import Head from 'next/head';
|
||||
import Footer from '@/components/Footer';
|
||||
import { GET_BRANDS_BY_CODE, GET_LAXIMO_CATALOG_INFO } from '@/lib/graphql';
|
||||
import { LaximoCatalogInfo } from '@/types/laximo';
|
||||
|
||||
const InfoBrandSelection = ({
|
||||
brandName,
|
||||
oemNumber,
|
||||
detailName
|
||||
}: {
|
||||
brandName: string;
|
||||
oemNumber: string;
|
||||
detailName?: string;
|
||||
}) => (
|
||||
<section className="section-info">
|
||||
<div className="w-layout-blockcontainer container info w-container">
|
||||
<div className="w-layout-vflex flex-block-9">
|
||||
<div className="w-layout-hflex flex-block-7">
|
||||
<a href="/" className="link-block w-inline-block text-[#000814] hover:text-[#EC1C24] transition-colors">
|
||||
<div>Главная</div>
|
||||
</a>
|
||||
<div className="text-block-3">→</div>
|
||||
<a href="#" className="link-block-2 w-inline-block text-[#000814] hover:text-[#EC1C24] transition-colors">
|
||||
<div>Каталог</div>
|
||||
</a>
|
||||
<div className="text-block-3">→</div>
|
||||
<div className="font-semibold text-gray-900">{brandName}</div>
|
||||
<div className="text-block-3">→</div>
|
||||
<div className="font-semibold text-gray-900">Деталь {oemNumber}</div>
|
||||
<div className="text-block-3">→</div>
|
||||
<div className="font-semibold text-gray-900">Выбор производителя</div>
|
||||
</div>
|
||||
<div className="w-layout-hflex flex-block-8 mt-4">
|
||||
<div className="w-layout-hflex flex-block-10 items-center gap-4">
|
||||
<h1 className="heading text-2xl font-bold text-gray-900">Выберите производителя</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-lg text-gray-600 mt-2">
|
||||
{detailName && <span>Деталь: {detailName} • </span>}
|
||||
Артикул: {oemNumber}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
const BrandSelectionPage = () => {
|
||||
const router = useRouter();
|
||||
const { brand, vehicleId, oemNumber, detailName } = router.query;
|
||||
|
||||
// Получаем информацию о каталоге
|
||||
const { data: catalogData, loading: catalogLoading } = useQuery<{ laximoCatalogInfo: LaximoCatalogInfo }>(
|
||||
GET_LAXIMO_CATALOG_INFO,
|
||||
{
|
||||
variables: { catalogCode: brand },
|
||||
skip: !brand,
|
||||
errorPolicy: 'all',
|
||||
}
|
||||
);
|
||||
|
||||
// Получаем список брендов по артикулу
|
||||
const { data, loading, error } = useQuery(GET_BRANDS_BY_CODE, {
|
||||
variables: { code: oemNumber },
|
||||
skip: !oemNumber,
|
||||
errorPolicy: 'all'
|
||||
});
|
||||
|
||||
if (!brand || vehicleId === undefined || vehicleId === null || !oemNumber) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Выбор производителя</title>
|
||||
</Head>
|
||||
<main style={{ minHeight: '100vh', backgroundColor: '#f9fafb' }}>
|
||||
<div style={{ textAlign: 'center', padding: '4rem 1rem' }}>
|
||||
<h1 style={{ fontSize: '2rem', fontWeight: 'bold', color: '#1f2937', marginBottom: '1rem' }}>
|
||||
Неверные параметры
|
||||
</h1>
|
||||
<p style={{ color: '#6b7280', marginBottom: '2rem' }}>
|
||||
Неверные параметры для выбора производителя
|
||||
</p>
|
||||
<button
|
||||
onClick={() => router.back()}
|
||||
style={{
|
||||
backgroundColor: '#dc2626',
|
||||
color: 'white',
|
||||
padding: '0.75rem 1.5rem',
|
||||
borderRadius: '0.5rem',
|
||||
border: 'none',
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
>
|
||||
Назад
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const catalogInfo = catalogData?.laximoCatalogInfo;
|
||||
const brandsData = data?.getBrandsByCode;
|
||||
const brands = brandsData?.brands || [];
|
||||
const hasError = brandsData?.error || error;
|
||||
const hasNoBrands = brandsData?.success && brands.length === 0;
|
||||
|
||||
const handleBrandSelect = (selectedBrand: string) => {
|
||||
console.log('🎯 Выбран бренд:', { articleNumber: oemNumber, brand: selectedBrand });
|
||||
router.push(`/search-result?article=${encodeURIComponent(String(oemNumber))}&brand=${encodeURIComponent(selectedBrand)}`);
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
router.back();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Выбор производителя для {oemNumber} - {catalogInfo?.name || 'Каталог запчастей'}</title>
|
||||
<meta name="description" content={`Выберите производителя для детали ${oemNumber} в каталоге ${catalogInfo?.name}`} />
|
||||
</Head>
|
||||
<div className="bg-[#F5F8FB] min-h-screen w-full">
|
||||
<InfoBrandSelection
|
||||
brandName={catalogInfo?.name || String(brand)}
|
||||
oemNumber={String(oemNumber)}
|
||||
detailName={String(detailName || '')}
|
||||
/>
|
||||
<div className="flex flex-col px-32 pt-10 pb-16 max-md:px-5">
|
||||
<div className="flex flex-col items-center w-full">
|
||||
<div className="w-full max-w-[1200px]">
|
||||
|
||||
{/* Кнопка назад */}
|
||||
<div className="mb-6">
|
||||
<button
|
||||
onClick={handleBack}
|
||||
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 transition-colors"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 19l-7-7 7-7" />
|
||||
</svg>
|
||||
Назад к деталям
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{(catalogLoading || loading) && (
|
||||
<div className="bg-white rounded-2xl shadow p-10 flex flex-col items-center justify-center min-h-[300px]">
|
||||
<div className="animate-spin rounded-full h-24 w-24 border-b-2 border-red-600 mb-6"></div>
|
||||
<p className="text-lg text-gray-600">Загружаем производителей...</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasError && !loading && (
|
||||
<div className="bg-red-50 border border-red-200 rounded-2xl shadow p-10 mb-6">
|
||||
<div className="flex items-center">
|
||||
<svg className="w-6 h-6 text-red-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
<div>
|
||||
<h3 className="text-lg font-medium text-red-800">Ошибка загрузки</h3>
|
||||
<p className="text-red-700 mt-1">
|
||||
{brandsData?.error || error?.message || 'Не удалось загрузить список производителей'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasNoBrands && !loading && (
|
||||
<div className="bg-yellow-50 border border-yellow-200 rounded-2xl shadow p-10">
|
||||
<div className="text-center">
|
||||
<div className="text-yellow-500 mb-3">
|
||||
<svg className="w-12 h-12 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 15.5c-.77.833.192 2.5 1.732 2.5z" />
|
||||
</svg>
|
||||
</div>
|
||||
<h4 className="text-lg font-medium text-yellow-800 mb-2">Производители не найдены</h4>
|
||||
<p className="text-yellow-700 mb-4">
|
||||
К сожалению, по данному артикулу производители не найдены
|
||||
</p>
|
||||
<p className="text-sm text-yellow-600 mb-4">
|
||||
Попробуйте изменить параметры поиска или обратитесь к нашим менеджерам
|
||||
</p>
|
||||
<div className="space-y-2 text-sm text-yellow-700">
|
||||
<p>Телефон: <span className="font-medium">+7 (495) 123-45-67</span></p>
|
||||
<p>Email: <span className="font-medium">info@protek.ru</span></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && !hasError && brands.length > 0 && (
|
||||
<div className="bg-white rounded-2xl shadow p-10">
|
||||
<div className="border-b border-gray-200 pb-4 mb-6">
|
||||
<h2 className="text-xl font-semibold text-gray-900">Выберите производителя</h2>
|
||||
<p className="text-sm text-gray-600 mt-1">
|
||||
Найдено производителей: <span className="font-medium">{brands.length}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{brands.map((brandItem: any, index: number) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => handleBrandSelect(brandItem.brand)}
|
||||
className="text-left p-6 rounded-lg border border-gray-200 hover:border-red-500 hover:bg-red-50 transition-all duration-200 group hover:shadow-md"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="font-medium text-gray-900 group-hover:text-red-700 text-lg mb-1">
|
||||
{brandItem.brand}
|
||||
</div>
|
||||
{brandItem.name && brandItem.name !== brandItem.brand && (
|
||||
<div className="text-sm text-gray-600 group-hover:text-red-600 mb-2">
|
||||
{brandItem.name}
|
||||
</div>
|
||||
)}
|
||||
<div className="text-xs text-gray-500 group-hover:text-red-500">
|
||||
Код: {brandItem.code}
|
||||
</div>
|
||||
</div>
|
||||
<svg
|
||||
className="w-6 h-6 text-gray-400 group-hover:text-red-500 transition-colors flex-shrink-0 ml-4"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-8 pt-6 border-t border-gray-200">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-sm text-gray-600">
|
||||
Не нашли нужного производителя?
|
||||
</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
Обратитесь к менеджеру: <span className="font-medium text-gray-700">+7 (495) 123-45-67</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default BrandSelectionPage;
|
@ -56,7 +56,7 @@ export default function Vin() {
|
||||
<div className="w-layout-hflex flex-block-13">
|
||||
<div className="w-layout-vflex flex-block-14-copy-copy">
|
||||
<KnotIn />
|
||||
<KnotParts />
|
||||
<KnotParts catalogCode="" vehicleId="" />
|
||||
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user