ServiceList.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. // src/components/ServiceList.tsx
  2. 'use client';
  3. import { useEffect, useState, useMemo } from 'react';
  4. import { useRouter } from '@/lib/i18n/navigation';
  5. import {
  6. Plane,
  7. BookOpen,
  8. ExternalLink,
  9. ChevronDown,
  10. ChevronUp,
  11. Zap,
  12. ShieldCheck,
  13. } from 'lucide-react';
  14. import { useLanguage } from '@/lib/i18n/LanguageContext';
  15. import { Product } from '@/types';
  16. import ServiceDetailModal from '@/components/services/ServiceDetailModal';
  17. import ServicePoster from '@/components/services/ServicePoster';
  18. import ProductTutorialBanner from '@/components/common/ProductTutorialBanner';
  19. import { productService } from '@/lib/services';
  20. import { displayProduct, countryLabel } from '@/lib/i18n/catalog';
  21. import { formattingLocale } from '@/lib/i18n/config';
  22. export default function ServiceList() {
  23. const router = useRouter();
  24. const { t, lang } = useLanguage();
  25. const [allProducts, setAllProducts] = useState<Product[]>([]);
  26. const [loading, setLoading] = useState<boolean>(true);
  27. const [error, setError] = useState<string>('');
  28. // 详情弹窗状态
  29. const [detailProduct, setDetailProduct] = useState<Product | null>(null);
  30. const [isDetailOpen, setIsDetailOpen] = useState(false);
  31. // 教程预览弹窗状态
  32. const [activeTutorialProduct, setActiveTutorialProduct] = useState<Product | null>(null);
  33. // 内嵌教程卡片展开状态 (productId)
  34. const [expandedTutorialId, setExpandedTutorialId] = useState<number | null>(null);
  35. useEffect(() => {
  36. fetchProducts();
  37. }, []);
  38. const fetchProducts = async () => {
  39. setLoading(true);
  40. setError('');
  41. try {
  42. const res = await productService.listEnabled({
  43. size: 1000,
  44. });
  45. const data = res?.data || {};
  46. if (Array.isArray(data)) {
  47. setAllProducts(data);
  48. } else if (Array.isArray(data.items)) {
  49. setAllProducts(data.items);
  50. } else {
  51. setAllProducts([]);
  52. }
  53. } catch (err) {
  54. console.warn('API Error, using fallback state', err);
  55. setAllProducts([]);
  56. } finally {
  57. setLoading(false);
  58. }
  59. };
  60. // 全量成熟产品按推荐分与ID排序展示 (不分页、纵向流)
  61. const sortedProducts = useMemo(() => {
  62. const list = allProducts.map(item => displayProduct(item, t));
  63. list.sort((a, b) => {
  64. const scoreA = typeof a.recommend_score === 'number' ? a.recommend_score : 0;
  65. const scoreB = typeof b.recommend_score === 'number' ? b.recommend_score : 0;
  66. if (scoreB !== scoreA) return scoreB - scoreA;
  67. return b.id - a.id;
  68. });
  69. return list;
  70. }, [allProducts, t]);
  71. const handleOrderClick = (id: number) => {
  72. router.push(`/create-order/${id}`);
  73. };
  74. const handleOpenDetail = (product: Product) => {
  75. setDetailProduct(product);
  76. setIsDetailOpen(true);
  77. };
  78. // 辅助解析描述文本 (仅当后端配置了描述文本时展示)
  79. const renderDescription = (text?: string) => {
  80. if (!text) return null;
  81. const lines = text
  82. .split('\n')
  83. .map((line) => line.trim())
  84. .filter((line) => line.length > 0);
  85. if (lines.length === 0) return null;
  86. return (
  87. <div className="space-y-1 text-neutral-600 text-xs sm:text-sm font-sans leading-relaxed">
  88. {lines.slice(0, 3).map((line, index) => (
  89. <p key={index} className="flex items-start gap-1.5">
  90. <span className="text-black font-bold select-none">•</span>
  91. <span>{line.replace(/^[•\-\*▪]\s*/, '')}</span>
  92. </p>
  93. ))}
  94. </div>
  95. );
  96. };
  97. return (
  98. <div className="space-y-6">
  99. {/* === 1. Neo-Brutalist 工业铭牌大厅标头 === */}
  100. <section className="bg-white border-2 border-black p-6 sm:p-8 md:p-10 shadow-[6px_6px_0px_#000] text-black">
  101. <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">
  102. <div className="flex items-center gap-2">
  103. <span className="w-3 h-3 bg-amber-300 border border-black inline-block shadow-[1px_1px_0px_#000]" />
  104. <span className="tracking-widest uppercase text-black">
  105. {t('services.hero_badge')}
  106. </span>
  107. </div>
  108. <div className="text-neutral-600 font-mono text-[11px] font-bold">
  109. {t('services.sys_node_prefix')}{' '}
  110. <span className="text-black font-black underline decoration-amber-400 decoration-2">
  111. {allProducts.length}
  112. </span>{' '}
  113. {t('services.sys_node_suffix')}
  114. </div>
  115. </div>
  116. <div className="max-w-3xl space-y-3">
  117. <h1 className="text-2xl sm:text-3xl md:text-5xl font-black tracking-tight text-black uppercase leading-tight">
  118. {t('services.hero_title')}
  119. </h1>
  120. <p className="text-xs sm:text-sm md:text-base text-neutral-600 font-mono leading-relaxed">
  121. {t('services.hero_desc')}
  122. </p>
  123. </div>
  124. {/* 核心权益保障胶囊 (Neo-Brutalist 风格) */}
  125. <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 pt-6">
  126. <div className="bg-amber-50 border-2 border-black p-4 shadow-[3px_3px_0px_#000] flex items-start gap-3">
  127. <div className="p-2 bg-amber-300 border-2 border-black shadow-[2px_2px_0px_#000] shrink-0">
  128. <Zap size={18} className="text-black" />
  129. </div>
  130. <div>
  131. <div className="text-xs font-black text-black font-mono uppercase tracking-wide">
  132. {t('services.benefit_patrol_title')}
  133. </div>
  134. <div className="text-[11px] text-neutral-600 mt-1 font-mono leading-relaxed">
  135. {t('services.benefit_patrol_desc')}
  136. </div>
  137. </div>
  138. </div>
  139. <div className="bg-emerald-50 border-2 border-black p-4 shadow-[3px_3px_0px_#000] flex items-start gap-3">
  140. <div className="p-2 bg-emerald-300 border-2 border-black shadow-[2px_2px_0px_#000] shrink-0">
  141. <ShieldCheck size={18} className="text-black" />
  142. </div>
  143. <div>
  144. <div className="text-xs font-black text-black font-mono uppercase tracking-wide">
  145. {t('services.benefit_escrow_title')}
  146. </div>
  147. <div className="text-[11px] text-neutral-600 mt-1 font-mono leading-relaxed">
  148. {t('services.benefit_escrow_desc')}
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. </section>
  154. {/* 错误提示 */}
  155. {error && (
  156. <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}
  157. </div>
  158. )}
  159. {/* 加载骨架屏 */}
  160. {loading && (
  161. <div className="space-y-5">
  162. {Array.from({ length: 3 }).map((_, i) => (
  163. <div
  164. key={i}
  165. 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"
  166. >
  167. <div className="w-full lg:w-[280px] xl:w-[320px] aspect-[16/9] bg-neutral-200 border-2 border-neutral-300 shrink-0" />
  168. <div className="flex-1 space-y-3">
  169. <div className="h-4 bg-neutral-200 w-32" />
  170. <div className="h-6 bg-neutral-200 w-2/3" />
  171. <div className="h-4 bg-neutral-200 w-full" />
  172. <div className="h-4 bg-neutral-200 w-4/5" />
  173. </div>
  174. <div className="lg:w-44 flex flex-col items-end gap-3 shrink-0">
  175. <div className="h-8 bg-neutral-200 w-24" />
  176. <div className="h-10 bg-neutral-200 w-28 border-2 border-neutral-400" />
  177. </div>
  178. </div>
  179. ))}
  180. </div>
  181. )}
  182. {/* 纵向商品卡片列表 (极客现代横向海报卡片 - 无需分页 - 适配全站 Neo-Brutalist 风格) */}
  183. {!loading && !error && sortedProducts.length > 0 && (
  184. <div className="space-y-6">
  185. {sortedProducts.map((item) => {
  186. const formattedPrice = (item.price_amount / 100).toLocaleString(formattingLocale(lang));
  187. const tutorial = item.extra_fields?.tutorial;
  188. const tutorialEnabled = Boolean(tutorial && tutorial.enabled);
  189. const tutorialDisplayType = tutorial?.display_type || 'modal';
  190. const isTutorialExpanded = expandedTutorialId === item.id;
  191. const cardConfig = item.extra_fields?.card_config;
  192. const isOfficial = Boolean(cardConfig?.official_tag || item.provider === 'Official');
  193. const statusTag = cardConfig?.status_tag;
  194. const salesText = cardConfig?.sales_text;
  195. const statusText = cardConfig?.status_text;
  196. const pillText = cardConfig?.pill_text || (tutorialEnabled ? (tutorial?.modal_title || tutorial?.button_text) : null);
  197. const descElement = renderDescription(item.description);
  198. return (
  199. <div
  200. key={item.id}
  201. 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"
  202. >
  203. <div className="flex flex-col lg:flex-row items-stretch lg:items-center justify-between gap-5 sm:gap-6">
  204. {/* 1. 左侧 16:9 视觉海报区 */}
  205. <ServicePoster product={item} />
  206. {/* 2. 中间信息区 */}
  207. <div className="flex-1 min-w-0 flex flex-col justify-between py-0.5 space-y-3">
  208. {/* 分类标签 */}
  209. <div className="flex items-center gap-2 text-xs font-mono font-bold tracking-wider">
  210. <span className="w-2.5 h-2.5 bg-emerald-400 border border-black inline-block shadow-[1px_1px_0px_#000]" />
  211. <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]">
  212. {countryLabel(item.country, lang)} {item.provider ? `// ${item.provider}` : ''}
  213. </span>
  214. </div>
  215. {/* 标题行与标贴 */}
  216. <div className="flex flex-wrap items-center gap-2">
  217. <Plane size={16} className="-rotate-45 text-black inline shrink-0 self-center" />
  218. <h2
  219. onClick={() => handleOpenDetail(item)}
  220. className="text-lg sm:text-xl font-black text-black hover:text-amber-600 cursor-pointer transition font-sans tracking-tight"
  221. >
  222. {item.title}
  223. </h2>
  224. {isOfficial && (
  225. <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">
  226. {t('services.official_tag_default')}
  227. </span>
  228. )}
  229. {statusTag && (
  230. <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">
  231. {statusTag}
  232. </span>
  233. )}
  234. </div>
  235. {/* 描述信息 (仅当后端配置了有效描述时展示) */}
  236. {descElement && (
  237. <div className="max-w-xl">
  238. {descElement}
  239. </div>
  240. )}
  241. {/* 辅助胶囊按键 (支持 modal, link, both, embedded 多种形态) */}
  242. {(pillText || tutorialEnabled) && (
  243. <div className="flex flex-wrap items-center gap-2">
  244. {tutorialEnabled ? (
  245. <>
  246. {/* 模式 A: 纯外部超链接 (link) */}
  247. {tutorialDisplayType === 'link' && (
  248. <button
  249. type="button"
  250. onClick={() => {
  251. if (tutorial?.link_url?.trim()) {
  252. window.open(tutorial.link_url.trim(), '_blank', 'noopener,noreferrer');
  253. } else {
  254. setActiveTutorialProduct(item);
  255. }
  256. }}
  257. 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"
  258. title={t('services.open_guide_tooltip')}
  259. >
  260. <ExternalLink size={12} />
  261. <span>[ {tutorial?.button_text || tutorial?.link_text || pillText || t('tutorial.view_guide_arrow')} ]</span>
  262. </button>
  263. )}
  264. {/* 模式 B: 内嵌折叠展开卡片 (embedded) */}
  265. {tutorialDisplayType === 'embedded' && (
  266. <button
  267. type="button"
  268. onClick={() => {
  269. setExpandedTutorialId(isTutorialExpanded ? null : item.id);
  270. }}
  271. 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 ${
  272. isTutorialExpanded
  273. ? 'bg-amber-300 text-black'
  274. : 'bg-amber-50 hover:bg-amber-100 text-black'
  275. }`}
  276. title={isTutorialExpanded ? t('tutorial.collapse_tooltip') : t('tutorial.expand_tooltip')}
  277. >
  278. {isTutorialExpanded ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
  279. <span>
  280. [ {isTutorialExpanded
  281. ? `${t('tutorial.collapse_guide')} ↑`
  282. : (tutorial?.button_text || tutorial?.modal_title || pillText || `${t('tutorial.expand_guide')} ↓`)} ]
  283. </span>
  284. </button>
  285. )}
  286. {/* 模式 C: 弹窗对话框模式 (modal) */}
  287. {tutorialDisplayType === 'modal' && (
  288. <button
  289. type="button"
  290. onClick={() => setActiveTutorialProduct(item)}
  291. 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"
  292. >
  293. <BookOpen size={12} />
  294. <span>[ {tutorial?.button_text || tutorial?.modal_title || pillText || t('tutorial.view_tutorial_arrow')} ]</span>
  295. </button>
  296. )}
  297. {/* 模式 D: 组合模式 (both - 弹窗 + 外部超链接) */}
  298. {tutorialDisplayType === 'both' && (
  299. <>
  300. <button
  301. type="button"
  302. onClick={() => setActiveTutorialProduct(item)}
  303. 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"
  304. >
  305. <BookOpen size={12} />
  306. <span>[ {tutorial?.button_text || tutorial?.modal_title || pillText || t('tutorial.view_tutorial_arrow')} ]</span>
  307. </button>
  308. {tutorial?.link_url?.trim() && (
  309. <a
  310. href={tutorial.link_url.trim()}
  311. target="_blank"
  312. rel="noopener noreferrer"
  313. 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"
  314. title={t('services.open_docs_tooltip')}
  315. >
  316. <ExternalLink size={12} />
  317. <span>[ {tutorial?.link_text || t('services.official_docs')} ]</span>
  318. </a>
  319. )}
  320. </>
  321. )}
  322. </>
  323. ) : (
  324. pillText && (
  325. <button
  326. type="button"
  327. onClick={() => handleOpenDetail(item)}
  328. 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"
  329. >
  330. <span>[ {pillText} → ]</span>
  331. </button>
  332. )
  333. )}
  334. </div>
  335. )}
  336. {/* 底部属性与服务信息 (仅当后端配置了相关信息时展示) */}
  337. {(salesText || item.city || item.visa_type || statusText) && (
  338. <div className="text-neutral-500 text-xs font-mono flex flex-wrap items-center gap-3 pt-1 border-t border-neutral-200">
  339. {salesText && (
  340. <span className="font-bold text-neutral-800">
  341. {salesText}
  342. </span>
  343. )}
  344. {item.city && (
  345. <span className="text-neutral-500">
  346. {salesText ? '· ' : ''}{t('services.city_prefix')}: {t(item.city)}
  347. </span>
  348. )}
  349. {item.visa_type && (
  350. <span className="text-neutral-500">
  351. · {t('product.visa_type')}: {t(item.visa_type)}
  352. </span>
  353. )}
  354. {statusText && (
  355. <>
  356. <span className="text-neutral-300">|</span>
  357. <span className="text-emerald-700 font-bold flex items-center gap-1">
  358. <span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" />
  359. {statusText}
  360. </span>
  361. </>
  362. )}
  363. </div>
  364. )}
  365. </div>
  366. {/* 3. 右侧价格卡与购买按键区 */}
  367. <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">
  368. {/* 价格展示 */}
  369. <div className="font-mono text-left lg:text-right">
  370. <div className="text-[10px] font-bold uppercase tracking-wider text-neutral-500">{t('services.fee_total')}</div>
  371. <div className="flex items-baseline justify-end gap-1 mt-0.5">
  372. <span className="text-lg font-bold text-black font-mono">
  373. {item.price_currency === 'CNY' ? '¥' : item.price_currency}
  374. </span>
  375. <span className="text-3xl sm:text-4xl font-black text-black font-mono tracking-tight">
  376. {formattedPrice}
  377. </span>
  378. </div>
  379. </div>
  380. {/* 立即购买按键 (Neo-Brutalist 粗野派实体按钮) */}
  381. <button
  382. onClick={() => handleOrderClick(item.id)}
  383. 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"
  384. >
  385. <span>[ {t('services.buy_now')} ]</span>
  386. </button>
  387. {/* 次级细则链接 */}
  388. <button
  389. onClick={() => handleOpenDetail(item)}
  390. 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"
  391. >
  392. <span>{t('services.sublink_terms')}</span>
  393. </button>
  394. </div>
  395. </div>
  396. {/* 4. 内嵌模式展开区 (仅当 display_type === 'embedded' 且展开时显示) */}
  397. {tutorialEnabled && tutorialDisplayType === 'embedded' && isTutorialExpanded && (
  398. <div className="pt-4 border-t-2 border-dashed border-neutral-300">
  399. <ProductTutorialBanner
  400. tutorial={tutorial}
  401. productTitle={item.title}
  402. hideBanner={false}
  403. />
  404. </div>
  405. )}
  406. </div>
  407. );
  408. })}
  409. </div>
  410. )}
  411. {/* 空状态 */}
  412. {!loading && !error && sortedProducts.length === 0 && (
  413. <div className="text-center py-16 bg-white border-2 border-black shadow-[6px_6px_0px_#000] mt-4 font-mono">
  414. <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]">
  415. ?
  416. </div>
  417. <h3 className="text-black font-black text-base uppercase mb-1">
  418. {t('services.no_services_title')}
  419. </h3>
  420. <p className="text-neutral-600 text-xs max-w-sm mx-auto mb-4 font-mono">
  421. {t('services.no_services_desc')}
  422. </p>
  423. <button
  424. onClick={fetchProducts}
  425. 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"
  426. >
  427. [ {t('services.refresh_services')} ]
  428. </button>
  429. </div>
  430. )}
  431. {/* 专属服务细则全景弹窗 */}
  432. <ServiceDetailModal
  433. product={detailProduct}
  434. isOpen={isDetailOpen}
  435. onClose={() => setIsDetailOpen(false)}
  436. onApply={(id) => handleOrderClick(id)}
  437. />
  438. {/* 专属教程查看器 (从商品卡片上点击教程直接弹出) */}
  439. {activeTutorialProduct && activeTutorialProduct.extra_fields?.tutorial && (
  440. <ProductTutorialBanner
  441. tutorial={activeTutorialProduct.extra_fields.tutorial}
  442. productTitle={activeTutorialProduct.title}
  443. defaultOpenModal={true}
  444. hideBanner={true}
  445. onCloseModal={() => setActiveTutorialProduct(null)}
  446. />
  447. )}
  448. </div>
  449. );
  450. }