Удалены модальные окна выбора бренда из компонентов PartDetailCard, KnotParts, VinPartCard и VinQuick. Вместо этого добавлена логика для перехода на страницу выбора бренда при клике на деталь. Обновлены компоненты для передачи параметров catalogCode и vehicleId. Исправлены типы и улучшена читаемость кода.
This commit is contained in:
@ -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;
|
Reference in New Issue
Block a user