| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- // src/components/ServiceList.tsx
- 'use client';
- import { useEffect, useState, useMemo } from 'react';
- import { useRouter } from '@/lib/i18n/navigation';
- import {
- Plane,
- BookOpen,
- ExternalLink,
- ChevronDown,
- ChevronUp,
- Zap,
- ShieldCheck,
- } from 'lucide-react';
- import { useLanguage } from '@/lib/i18n/LanguageContext';
- import { Product } from '@/types';
- import ServiceDetailModal from '@/components/services/ServiceDetailModal';
- import ServicePoster from '@/components/services/ServicePoster';
- import ProductTutorialBanner from '@/components/common/ProductTutorialBanner';
- import { productService } from '@/lib/services';
- import { displayProduct, countryLabel } from '@/lib/i18n/catalog';
- import { formattingLocale } from '@/lib/i18n/config';
- export default function ServiceList() {
- const router = useRouter();
- const { t, lang } = useLanguage();
- const [allProducts, setAllProducts] = useState<Product[]>([]);
- const [loading, setLoading] = useState<boolean>(true);
- const [error, setError] = useState<string>('');
- // 详情弹窗状态
- const [detailProduct, setDetailProduct] = useState<Product | null>(null);
- const [isDetailOpen, setIsDetailOpen] = useState(false);
- // 教程预览弹窗状态
- const [activeTutorialProduct, setActiveTutorialProduct] = useState<Product | null>(null);
- // 内嵌教程卡片展开状态 (productId)
- const [expandedTutorialId, setExpandedTutorialId] = useState<number | null>(null);
- useEffect(() => {
- fetchProducts();
- }, []);
- const fetchProducts = async () => {
- setLoading(true);
- setError('');
- try {
- const res = await productService.listEnabled({
- size: 1000,
- });
- const data = res?.data || {};
- if (Array.isArray(data)) {
- setAllProducts(data);
- } else if (Array.isArray(data.items)) {
- setAllProducts(data.items);
- } else {
- setAllProducts([]);
- }
- } catch (err) {
- console.warn('API Error, using fallback state', err);
- setAllProducts([]);
- } finally {
- setLoading(false);
- }
- };
- // 全量成熟产品按推荐分与ID排序展示 (不分页、纵向流)
- const sortedProducts = useMemo(() => {
- const list = allProducts.map(item => displayProduct(item, t));
- list.sort((a, b) => {
- const scoreA = typeof a.recommend_score === 'number' ? a.recommend_score : 0;
- const scoreB = typeof b.recommend_score === 'number' ? b.recommend_score : 0;
- if (scoreB !== scoreA) return scoreB - scoreA;
- return b.id - a.id;
- });
- return list;
- }, [allProducts, t]);
- const handleOrderClick = (id: number) => {
- router.push(`/create-order/${id}`);
- };
- const handleOpenDetail = (product: Product) => {
- setDetailProduct(product);
- setIsDetailOpen(true);
- };
- // 辅助解析描述文本 (仅当后端配置了描述文本时展示)
- const renderDescription = (text?: string) => {
- if (!text) return null;
- const lines = text
- .split('\n')
- .map((line) => line.trim())
- .filter((line) => line.length > 0);
- if (lines.length === 0) return null;
- return (
- <div className="space-y-1 text-neutral-600 text-xs sm:text-sm font-sans leading-relaxed">
- {lines.slice(0, 3).map((line, index) => (
- <p key={index} className="flex items-start gap-1.5">
- <span className="text-black font-bold select-none">•</span>
- <span>{line.replace(/^[•\-\*▪]\s*/, '')}</span>
- </p>
- ))}
- </div>
- );
- };
- return (
- <div className="space-y-6">
-
- {/* === 1. Neo-Brutalist 工业铭牌大厅标头 === */}
- <section className="bg-white border-2 border-black p-6 sm:p-8 md:p-10 shadow-[6px_6px_0px_#000] text-black">
- <div className="flex flex-wrap items-center justify-between gap-2 border-b-2 border-black pb-3 mb-6 font-mono text-xs font-bold select-none">
- <div className="flex items-center gap-2">
- <span className="w-3 h-3 bg-amber-300 border border-black inline-block shadow-[1px_1px_0px_#000]" />
- <span className="tracking-widest uppercase text-black">
- {t('services.hero_badge')}
- </span>
- </div>
- <div className="text-neutral-600 font-mono text-[11px] font-bold">
- {t('services.sys_node_prefix')}{' '}
- <span className="text-black font-black underline decoration-amber-400 decoration-2">
- {allProducts.length}
- </span>{' '}
- {t('services.sys_node_suffix')}
- </div>
- </div>
- <div className="max-w-3xl space-y-3">
- <h1 className="text-2xl sm:text-3xl md:text-5xl font-black tracking-tight text-black uppercase leading-tight">
- {t('services.hero_title')}
- </h1>
- <p className="text-xs sm:text-sm md:text-base text-neutral-600 font-mono leading-relaxed">
- {t('services.hero_desc')}
- </p>
- </div>
- {/* 核心权益保障胶囊 (Neo-Brutalist 风格) */}
- <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 pt-6">
- <div className="bg-amber-50 border-2 border-black p-4 shadow-[3px_3px_0px_#000] flex items-start gap-3">
- <div className="p-2 bg-amber-300 border-2 border-black shadow-[2px_2px_0px_#000] shrink-0">
- <Zap size={18} className="text-black" />
- </div>
- <div>
- <div className="text-xs font-black text-black font-mono uppercase tracking-wide">
- {t('services.benefit_patrol_title')}
- </div>
- <div className="text-[11px] text-neutral-600 mt-1 font-mono leading-relaxed">
- {t('services.benefit_patrol_desc')}
- </div>
- </div>
- </div>
- <div className="bg-emerald-50 border-2 border-black p-4 shadow-[3px_3px_0px_#000] flex items-start gap-3">
- <div className="p-2 bg-emerald-300 border-2 border-black shadow-[2px_2px_0px_#000] shrink-0">
- <ShieldCheck size={18} className="text-black" />
- </div>
- <div>
- <div className="text-xs font-black text-black font-mono uppercase tracking-wide">
- {t('services.benefit_escrow_title')}
- </div>
- <div className="text-[11px] text-neutral-600 mt-1 font-mono leading-relaxed">
- {t('services.benefit_escrow_desc')}
- </div>
- </div>
- </div>
- </div>
- </section>
- {/* 错误提示 */}
- {error && (
- <div className="border-2 border-black bg-rose-100 p-4 text-xs text-rose-950 font-mono font-bold shadow-[4px_4px_0px_#000]">[ {t('common.error')} ]{error}
- </div>
- )}
- {/* 加载骨架屏 */}
- {loading && (
- <div className="space-y-5">
- {Array.from({ length: 3 }).map((_, i) => (
- <div
- key={i}
- className="bg-white border-2 border-black p-5 sm:p-6 shadow-[6px_6px_0px_#000] animate-pulse flex flex-col lg:flex-row items-stretch lg:items-center justify-between gap-6"
- >
- <div className="w-full lg:w-[280px] xl:w-[320px] aspect-[16/9] bg-neutral-200 border-2 border-neutral-300 shrink-0" />
- <div className="flex-1 space-y-3">
- <div className="h-4 bg-neutral-200 w-32" />
- <div className="h-6 bg-neutral-200 w-2/3" />
- <div className="h-4 bg-neutral-200 w-full" />
- <div className="h-4 bg-neutral-200 w-4/5" />
- </div>
- <div className="lg:w-44 flex flex-col items-end gap-3 shrink-0">
- <div className="h-8 bg-neutral-200 w-24" />
- <div className="h-10 bg-neutral-200 w-28 border-2 border-neutral-400" />
- </div>
- </div>
- ))}
- </div>
- )}
- {/* 纵向商品卡片列表 (极客现代横向海报卡片 - 无需分页 - 适配全站 Neo-Brutalist 风格) */}
- {!loading && !error && sortedProducts.length > 0 && (
- <div className="space-y-6">
- {sortedProducts.map((item) => {
- const formattedPrice = (item.price_amount / 100).toLocaleString(formattingLocale(lang));
- const tutorial = item.extra_fields?.tutorial;
- const tutorialEnabled = Boolean(tutorial && tutorial.enabled);
- const tutorialDisplayType = tutorial?.display_type || 'modal';
- const isTutorialExpanded = expandedTutorialId === item.id;
- const cardConfig = item.extra_fields?.card_config;
- const isOfficial = Boolean(cardConfig?.official_tag || item.provider === 'Official');
- const statusTag = cardConfig?.status_tag;
- const salesText = cardConfig?.sales_text;
- const statusText = cardConfig?.status_text;
- const pillText = cardConfig?.pill_text || (tutorialEnabled ? (tutorial?.modal_title || tutorial?.button_text) : null);
- const descElement = renderDescription(item.description);
- return (
- <div
- key={item.id}
- className="group bg-white border-2 border-black shadow-[6px_6px_0px_#000] hover:shadow-[8px_8px_0px_#000] hover:-translate-x-0.5 hover:-translate-y-0.5 transition-all duration-200 p-5 sm:p-6 flex flex-col justify-between gap-5 sm:gap-6"
- >
- <div className="flex flex-col lg:flex-row items-stretch lg:items-center justify-between gap-5 sm:gap-6">
- {/* 1. 左侧 16:9 视觉海报区 */}
- <ServicePoster product={item} />
- {/* 2. 中间信息区 */}
- <div className="flex-1 min-w-0 flex flex-col justify-between py-0.5 space-y-3">
- {/* 分类标签 */}
- <div className="flex items-center gap-2 text-xs font-mono font-bold tracking-wider">
- <span className="w-2.5 h-2.5 bg-emerald-400 border border-black inline-block shadow-[1px_1px_0px_#000]" />
- <span className="uppercase bg-neutral-100 border border-black px-2 py-0.5 text-black font-black text-[11px] shadow-[1px_1px_0px_#000]">
- {countryLabel(item.country, lang)} {item.provider ? `// ${item.provider}` : ''}
- </span>
- </div>
- {/* 标题行与标贴 */}
- <div className="flex flex-wrap items-center gap-2">
- <Plane size={16} className="-rotate-45 text-black inline shrink-0 self-center" />
- <h2
- onClick={() => handleOpenDetail(item)}
- className="text-lg sm:text-xl font-black text-black hover:text-amber-600 cursor-pointer transition font-sans tracking-tight"
- >
- {item.title}
- </h2>
- {isOfficial && (
- <span className="bg-teal-100 text-teal-900 border border-black px-1.5 py-0.5 text-[10px] font-mono font-black shadow-[1px_1px_0px_#000] uppercase">
- {t('services.official_tag_default')}
- </span>
- )}
- {statusTag && (
- <span className="bg-amber-300 text-black border border-black px-1.5 py-0.5 text-[10px] font-mono font-black shadow-[1px_1px_0px_#000] uppercase">
- {statusTag}
- </span>
- )}
- </div>
- {/* 描述信息 (仅当后端配置了有效描述时展示) */}
- {descElement && (
- <div className="max-w-xl">
- {descElement}
- </div>
- )}
- {/* 辅助胶囊按键 (支持 modal, link, both, embedded 多种形态) */}
- {(pillText || tutorialEnabled) && (
- <div className="flex flex-wrap items-center gap-2">
- {tutorialEnabled ? (
- <>
- {/* 模式 A: 纯外部超链接 (link) */}
- {tutorialDisplayType === 'link' && (
- <button
- type="button"
- onClick={() => {
- if (tutorial?.link_url?.trim()) {
- window.open(tutorial.link_url.trim(), '_blank', 'noopener,noreferrer');
- } else {
- setActiveTutorialProduct(item);
- }
- }}
- className="inline-flex items-center gap-1.5 px-3 py-1 bg-amber-50 hover:bg-amber-100 text-black border-2 border-black font-mono text-xs font-bold shadow-[2px_2px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all cursor-pointer"
- title={t('services.open_guide_tooltip')}
- >
- <ExternalLink size={12} />
- <span>[ {tutorial?.button_text || tutorial?.link_text || pillText || t('tutorial.view_guide_arrow')} ]</span>
- </button>
- )}
- {/* 模式 B: 内嵌折叠展开卡片 (embedded) */}
- {tutorialDisplayType === 'embedded' && (
- <button
- type="button"
- onClick={() => {
- setExpandedTutorialId(isTutorialExpanded ? null : item.id);
- }}
- className={`inline-flex items-center gap-1.5 px-3 py-1 border-2 border-black font-mono text-xs font-bold shadow-[2px_2px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all cursor-pointer ${
- isTutorialExpanded
- ? 'bg-amber-300 text-black'
- : 'bg-amber-50 hover:bg-amber-100 text-black'
- }`}
- title={isTutorialExpanded ? t('tutorial.collapse_tooltip') : t('tutorial.expand_tooltip')}
- >
- {isTutorialExpanded ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
- <span>
- [ {isTutorialExpanded
- ? `${t('tutorial.collapse_guide')} ↑`
- : (tutorial?.button_text || tutorial?.modal_title || pillText || `${t('tutorial.expand_guide')} ↓`)} ]
- </span>
- </button>
- )}
- {/* 模式 C: 弹窗对话框模式 (modal) */}
- {tutorialDisplayType === 'modal' && (
- <button
- type="button"
- onClick={() => setActiveTutorialProduct(item)}
- className="inline-flex items-center gap-1.5 px-3 py-1 bg-amber-50 hover:bg-amber-100 text-black border-2 border-black font-mono text-xs font-bold shadow-[2px_2px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all cursor-pointer"
- >
- <BookOpen size={12} />
- <span>[ {tutorial?.button_text || tutorial?.modal_title || pillText || t('tutorial.view_tutorial_arrow')} ]</span>
- </button>
- )}
- {/* 模式 D: 组合模式 (both - 弹窗 + 外部超链接) */}
- {tutorialDisplayType === 'both' && (
- <>
- <button
- type="button"
- onClick={() => setActiveTutorialProduct(item)}
- className="inline-flex items-center gap-1.5 px-3 py-1 bg-amber-50 hover:bg-amber-100 text-black border-2 border-black font-mono text-xs font-bold shadow-[2px_2px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all cursor-pointer"
- >
- <BookOpen size={12} />
- <span>[ {tutorial?.button_text || tutorial?.modal_title || pillText || t('tutorial.view_tutorial_arrow')} ]</span>
- </button>
- {tutorial?.link_url?.trim() && (
- <a
- href={tutorial.link_url.trim()}
- target="_blank"
- rel="noopener noreferrer"
- className="inline-flex items-center gap-1.5 px-3 py-1 bg-white hover:bg-neutral-100 text-black border-2 border-black font-mono text-xs font-bold shadow-[2px_2px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all cursor-pointer"
- title={t('services.open_docs_tooltip')}
- >
- <ExternalLink size={12} />
- <span>[ {tutorial?.link_text || t('services.official_docs')} ]</span>
- </a>
- )}
- </>
- )}
- </>
- ) : (
- pillText && (
- <button
- type="button"
- onClick={() => handleOpenDetail(item)}
- className="inline-flex items-center gap-1.5 px-3 py-1 bg-amber-50 hover:bg-amber-100 text-black border-2 border-black font-mono text-xs font-bold shadow-[2px_2px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all cursor-pointer"
- >
- <span>[ {pillText} → ]</span>
- </button>
- )
- )}
- </div>
- )}
- {/* 底部属性与服务信息 (仅当后端配置了相关信息时展示) */}
- {(salesText || item.city || item.visa_type || statusText) && (
- <div className="text-neutral-500 text-xs font-mono flex flex-wrap items-center gap-3 pt-1 border-t border-neutral-200">
- {salesText && (
- <span className="font-bold text-neutral-800">
- {salesText}
- </span>
- )}
- {item.city && (
- <span className="text-neutral-500">
- {salesText ? '· ' : ''}{t('services.city_prefix')}: {t(item.city)}
- </span>
- )}
- {item.visa_type && (
- <span className="text-neutral-500">
- · {t('product.visa_type')}: {t(item.visa_type)}
- </span>
- )}
- {statusText && (
- <>
- <span className="text-neutral-300">|</span>
- <span className="text-emerald-700 font-bold flex items-center gap-1">
- <span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" />
- {statusText}
- </span>
- </>
- )}
- </div>
- )}
- </div>
- {/* 3. 右侧价格卡与购买按键区 */}
- <div className="lg:w-48 xl:w-52 shrink-0 flex flex-row lg:flex-col items-center lg:items-end justify-between lg:justify-center gap-3 pt-4 lg:pt-0 border-t-2 border-neutral-200 lg:border-t-0 lg:border-l-2 lg:border-neutral-200 lg:pl-6">
- {/* 价格展示 */}
- <div className="font-mono text-left lg:text-right">
- <div className="text-[10px] font-bold uppercase tracking-wider text-neutral-500">{t('services.fee_total')}</div>
- <div className="flex items-baseline justify-end gap-1 mt-0.5">
- <span className="text-lg font-bold text-black font-mono">
- {item.price_currency === 'CNY' ? '¥' : item.price_currency}
- </span>
- <span className="text-3xl sm:text-4xl font-black text-black font-mono tracking-tight">
- {formattedPrice}
- </span>
- </div>
- </div>
- {/* 立即购买按键 (Neo-Brutalist 粗野派实体按钮) */}
- <button
- onClick={() => handleOrderClick(item.id)}
- className="w-full sm:w-auto px-6 py-2.5 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black font-black font-mono text-sm shadow-[3px_3px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition-all uppercase flex items-center justify-center gap-2 cursor-pointer"
- >
- <span>[ {t('services.buy_now')} ]</span>
- </button>
- {/* 次级细则链接 */}
- <button
- onClick={() => handleOpenDetail(item)}
- className="text-xs font-mono font-bold text-neutral-600 hover:text-black underline underline-offset-4 transition inline-flex items-center gap-1 mt-0.5 cursor-pointer"
- >
- <span>{t('services.sublink_terms')}</span>
- </button>
- </div>
- </div>
- {/* 4. 内嵌模式展开区 (仅当 display_type === 'embedded' 且展开时显示) */}
- {tutorialEnabled && tutorialDisplayType === 'embedded' && isTutorialExpanded && (
- <div className="pt-4 border-t-2 border-dashed border-neutral-300">
- <ProductTutorialBanner
- tutorial={tutorial}
- productTitle={item.title}
- hideBanner={false}
- />
- </div>
- )}
- </div>
- );
- })}
- </div>
- )}
- {/* 空状态 */}
- {!loading && !error && sortedProducts.length === 0 && (
- <div className="text-center py-16 bg-white border-2 border-black shadow-[6px_6px_0px_#000] mt-4 font-mono">
- <div className="mx-auto w-12 h-12 bg-amber-300 border-2 border-black flex items-center justify-center mb-3 font-black text-xl text-black shadow-[2px_2px_0px_#000]">
- ?
- </div>
- <h3 className="text-black font-black text-base uppercase mb-1">
- {t('services.no_services_title')}
- </h3>
- <p className="text-neutral-600 text-xs max-w-sm mx-auto mb-4 font-mono">
- {t('services.no_services_desc')}
- </p>
- <button
- onClick={fetchProducts}
- className="px-6 py-2.5 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black font-mono text-xs font-black shadow-[3px_3px_0px_#000] hover:translate-x-0.5 hover:translate-y-0.5 active:shadow-none transition cursor-pointer uppercase"
- >
- [ {t('services.refresh_services')} ]
- </button>
- </div>
- )}
- {/* 专属服务细则全景弹窗 */}
- <ServiceDetailModal
- product={detailProduct}
- isOpen={isDetailOpen}
- onClose={() => setIsDetailOpen(false)}
- onApply={(id) => handleOrderClick(id)}
- />
- {/* 专属教程查看器 (从商品卡片上点击教程直接弹出) */}
- {activeTutorialProduct && activeTutorialProduct.extra_fields?.tutorial && (
- <ProductTutorialBanner
- tutorial={activeTutorialProduct.extra_fields.tutorial}
- productTitle={activeTutorialProduct.title}
- defaultOpenModal={true}
- hideBanner={true}
- onCloseModal={() => setActiveTutorialProduct(null)}
- />
- )}
- </div>
- );
- }
|