pravkiend 29.06 #4
@ -31,6 +31,8 @@ const FulltextSearchSection: React.FC<FulltextSearchSectionProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('SEARCH PARAMS', { catalogCode, vehicleId, searchQuery: searchQuery.trim(), ssd });
|
||||
|
||||
executeSearch({
|
||||
variables: {
|
||||
catalogCode,
|
||||
@ -199,6 +201,4 @@ const FulltextSearchSection: React.FC<FulltextSearchSectionProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
export default FulltextSearchSection;
|
@ -1,6 +1,7 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useLazyQuery, useQuery } from '@apollo/client';
|
||||
import { SEARCH_LAXIMO_FULLTEXT, GET_LAXIMO_CATEGORIES, GET_LAXIMO_UNITS } from '@/lib/graphql/laximo';
|
||||
import VinPartCard from './VinPartCard';
|
||||
|
||||
interface VinLeftbarProps {
|
||||
catalogCode?: string;
|
||||
@ -46,7 +47,12 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ catalogCode, vehicleId, ssd, on
|
||||
};
|
||||
|
||||
const handleSearch = () => {
|
||||
if (!searchQuery.trim() || !catalogCode || !vehicleId || !ssd) return;
|
||||
if (!searchQuery.trim()) return;
|
||||
if (!ssd || ssd.trim() === '') {
|
||||
console.error('SSD обязателен для поиска по названию');
|
||||
return;
|
||||
}
|
||||
console.log('SEARCH PARAMS', { catalogCode, vehicleId, searchQuery: searchQuery.trim(), ssd });
|
||||
executeSearch({
|
||||
variables: {
|
||||
catalogCode,
|
||||
@ -75,12 +81,19 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ catalogCode, vehicleId, ssd, on
|
||||
}
|
||||
}, [searchResults, searchQuery, onSearchResults]);
|
||||
|
||||
// --- Новый блок: вычисляем доступность поиска ---
|
||||
const isSearchAvailable = !!catalogCode && !!vehicleId && !!ssd && ssd.trim() !== '';
|
||||
const showWarning = !isSearchAvailable;
|
||||
const showError = !!error && isSearchAvailable && searchQuery.trim();
|
||||
const showNotFound = isSearchAvailable && searchQuery.trim() && !loading && data && searchResults && searchResults.details && searchResults.details.length === 0;
|
||||
const showTips = isSearchAvailable && !searchQuery.trim() && !loading;
|
||||
|
||||
return (
|
||||
<div className="w-layout-vflex vinleftbar">
|
||||
<div className="div-block-2">
|
||||
<div className="form-block w-form">
|
||||
<form id="vin-form-search" name="vin-form-search" data-name="vin-form-search" action="#" method="post" className="form">
|
||||
<a href="#" className="link-block-3 w-inline-block" onClick={e => { e.preventDefault(); handleSearch(); }}>
|
||||
<a href="#" className="link-block-3 w-inline-block" onClick={e => { e.preventDefault(); if (!ssd || ssd.trim() === '') { return; } handleSearch(); }}>
|
||||
<div className="code-embed-6 w-embed">
|
||||
{/* SVG */}
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
@ -101,10 +114,11 @@ const VinLeftbar: React.FC<VinLeftbarProps> = ({ catalogCode, vehicleId, ssd, on
|
||||
value={searchQuery}
|
||||
onChange={e => setSearchQuery(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
disabled={!catalogCode || !vehicleId || !ssd}
|
||||
disabled={loading}
|
||||
/>
|
||||
</form>
|
||||
{error && <div style={{ color: 'red', fontSize: 12 }}>Ошибка поиска: {error.message}</div>}
|
||||
{/* Варианты отображения: предупреждение, ошибка, подсказки, результаты */}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-layout-vflex flex-block-113">
|
||||
|
@ -161,12 +161,12 @@ const VehicleDetailsPage = () => {
|
||||
<Head>
|
||||
<title>Загрузка автомобиля...</title>
|
||||
</Head>
|
||||
<main className="min-h-screen bg-gray-50 flex items-center justify-center">
|
||||
<div style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#f9fafb' }}>
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-32 w-32 border-b-2 border-red-600 mx-auto"></div>
|
||||
<p className="mt-4 text-lg text-gray-600">Загружаем информацию об автомобиле...</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@ -194,16 +194,49 @@ const VehicleDetailsPage = () => {
|
||||
);
|
||||
}
|
||||
|
||||
// Если информация об автомобиле недоступна, создаем заглушку
|
||||
const vehicleInfo = vehicleData?.laximoVehicleInfo || {
|
||||
vehicleid: vehicleId as string,
|
||||
// Если vehicleId невалидный (например, '0'), показываем предупреждение и не рендерим поиск
|
||||
if (!vehicleId || vehicleId === '0') {
|
||||
return (
|
||||
<main className="min-h-screen bg-yellow-50 flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<h1 className="text-2xl font-bold text-yellow-900 mb-4">Автомобиль не выбран</h1>
|
||||
<p className="text-yellow-700 mb-8">Для поиска по деталям необходимо выбрать конкретный автомобиль через VIN или мастер подбора.</p>
|
||||
<button
|
||||
onClick={() => router.back()}
|
||||
className="bg-yellow-600 text-white px-6 py-3 rounded-lg hover:bg-yellow-700 transition-colors"
|
||||
>
|
||||
Назад к поиску
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
// Гарантируем, что vehicleId — строка
|
||||
const vehicleIdStr = Array.isArray(vehicleId) ? (vehicleId[0] || '') : (vehicleId || '');
|
||||
const fallbackVehicleId = (vehicleIdStr !== '0' ? vehicleIdStr : '');
|
||||
|
||||
let vehicleInfo = vehicleData?.laximoVehicleInfo || {
|
||||
vehicleid: fallbackVehicleId,
|
||||
name: `Автомобиль ${catalogData.laximoCatalogInfo.name}`,
|
||||
ssd: finalSsd,
|
||||
brand: catalogData.laximoCatalogInfo.brand,
|
||||
catalog: catalogData.laximoCatalogInfo.code,
|
||||
attributes: []
|
||||
attributes: [] as never[]
|
||||
};
|
||||
|
||||
// Если вдруг с сервера пришёл vehicleid: '0', подменяем на корректный
|
||||
if (vehicleInfo.vehicleid === '0' && fallbackVehicleId) {
|
||||
vehicleInfo = { ...vehicleInfo, vehicleid: fallbackVehicleId };
|
||||
}
|
||||
|
||||
// Логируем, что реально передаём в VinLeftbar
|
||||
console.log('Передаём в VinLeftbar:', {
|
||||
catalog: vehicleInfo.catalog,
|
||||
vehicleid: vehicleInfo.vehicleid,
|
||||
ssd: vehicleInfo.ssd
|
||||
});
|
||||
|
||||
// Если нет данных автомобиля и есть ошибка, показываем предупреждение
|
||||
const hasError = vehicleError && !vehicleData?.laximoVehicleInfo;
|
||||
const catalogInfo = catalogData.laximoCatalogInfo;
|
||||
|
@ -387,13 +387,12 @@ input.input-receiver:focus {
|
||||
}
|
||||
|
||||
.knotin {
|
||||
height: 100%;
|
||||
max-width: 100%;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
}
|
||||
.knotin img {
|
||||
height: 100%;
|
||||
width: auto;
|
||||
max-width: 100%;
|
||||
object-fit: contain; /* или cover */
|
||||
}
|
||||
|
||||
@ -420,3 +419,13 @@ input#VinSearchInput {
|
||||
display: block;
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
.text-block-55 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-height: 2.8em;
|
||||
line-height: 1.4em;
|
||||
}
|
Reference in New Issue
Block a user