page.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. 'use client';
  2. import { useState, useEffect, useMemo } from 'react';
  3. import api from '@/lib/api';
  4. import {
  5. Plus,
  6. RefreshCw,
  7. Search,
  8. FileJson,
  9. Package,
  10. CheckCircle2,
  11. XCircle,
  12. Layers,
  13. Filter,
  14. X,
  15. RotateCcw,
  16. Sparkles
  17. } from 'lucide-react';
  18. import { toast } from 'react-hot-toast';
  19. import ProductList from '@/components/admin/products/ProductList';
  20. import ProductModal from '@/components/admin/products/ProductModal';
  21. import RoutingManager from '@/components/admin/products/RoutingManager';
  22. import SchemaManager from '@/components/admin/products/SchemaManager';
  23. import ProductDetailDrawer from '@/components/admin/products/ProductDetailDrawer';
  24. import Pagination from '@/components/common/Pagination';
  25. import { Product, SchemaItem } from '@/types';
  26. export default function AdminProductsPage() {
  27. const [allProducts, setAllProducts] = useState<Product[]>([]);
  28. const [schemas, setSchemas] = useState<SchemaItem[]>([]);
  29. const [loading, setLoading] = useState(true);
  30. const [statusTab, setStatusTab] = useState<'all' | 'active' | 'inactive'>('all');
  31. const [keyword, setKeyword] = useState('');
  32. const [selectedVisaType, setSelectedVisaType] = useState<string>('all');
  33. const [selectedCountry, setSelectedCountry] = useState<string>('all');
  34. const [selectedProvider, setSelectedProvider] = useState<string>('all');
  35. const [selectedSchemaFilter, setSelectedSchemaFilter] = useState<'all' | 'bound' | 'unbound'>('all');
  36. const [page, setPage] = useState(1);
  37. const [pageSize] = useState(10);
  38. const [isProductModalOpen, setProductModalOpen] = useState(false);
  39. const [isRoutingModalOpen, setRoutingModalOpen] = useState(false);
  40. const [isSchemaModalOpen, setSchemaModalOpen] = useState(false);
  41. const [isDrawerOpen, setIsDrawerOpen] = useState(false);
  42. const [selectedProduct, setSelectedProduct] = useState<Product | null>(null);
  43. useEffect(() => {
  44. fetchInitialData();
  45. }, []);
  46. const fetchInitialData = async () => {
  47. setLoading(true);
  48. try {
  49. const [prodRes, schemaRes] = await Promise.allSettled([
  50. api.get('/api/vas/product/list', { params: { size: 1000 } }),
  51. api.get('/api/vas/schema/list'),
  52. ]);
  53. if (prodRes.status === 'fulfilled') {
  54. const data = prodRes.value.data?.data || {};
  55. if (Array.isArray(data)) {
  56. setAllProducts(data);
  57. } else if (Array.isArray(data.items)) {
  58. setAllProducts(data.items);
  59. } else {
  60. setAllProducts([]);
  61. }
  62. } else {
  63. setAllProducts([]);
  64. }
  65. if (schemaRes.status === 'fulfilled') {
  66. const schemaData = schemaRes.value.data?.data;
  67. setSchemas(Array.isArray(schemaData) ? schemaData : []);
  68. }
  69. } catch {
  70. toast.error('加载商品列表失败');
  71. } finally {
  72. setLoading(false);
  73. }
  74. };
  75. const fetchProductsOnly = async () => {
  76. setLoading(true);
  77. try {
  78. const res = await api.get('/api/vas/product/list', { params: { size: 1000 } });
  79. const data = res.data?.data || {};
  80. if (Array.isArray(data)) {
  81. setAllProducts(data);
  82. } else if (Array.isArray(data.items)) {
  83. setAllProducts(data.items);
  84. } else {
  85. setAllProducts([]);
  86. }
  87. } catch {
  88. toast.error('刷新商品列表失败');
  89. } finally {
  90. setLoading(false);
  91. }
  92. };
  93. const availableCountries = useMemo(() => {
  94. const set = new Set<string>();
  95. allProducts.forEach((p) => {
  96. if (p.country && p.country.trim()) set.add(p.country.trim());
  97. });
  98. return Array.from(set).sort();
  99. }, [allProducts]);
  100. const availableProviders = useMemo(() => {
  101. const set = new Set<string>();
  102. allProducts.forEach((p) => {
  103. if (p.provider && p.provider.trim()) set.add(p.provider.trim());
  104. });
  105. return Array.from(set).sort();
  106. }, [allProducts]);
  107. const stats = useMemo(() => {
  108. const total = allProducts.length;
  109. const active = allProducts.filter((p) => Boolean(p.enabled)).length;
  110. const inactive = total - active;
  111. const withSchema = allProducts.filter((p) => p.schema_id && p.schema_id > 0).length;
  112. const schemaCoverage = total > 0 ? Math.round((withSchema / total) * 100) : 0;
  113. return { total, active, inactive, withSchema, schemaCoverage };
  114. }, [allProducts]);
  115. const filteredProducts = useMemo(() => {
  116. let list = [...allProducts];
  117. if (statusTab === 'active') {
  118. list = list.filter((p) => Boolean(p.enabled));
  119. } else if (statusTab === 'inactive') {
  120. list = list.filter((p) => !Boolean(p.enabled));
  121. }
  122. if (keyword.trim()) {
  123. const lowerKey = keyword.trim().toLowerCase();
  124. list = list.filter((p) => {
  125. const idMatch = String(p.id).includes(lowerKey);
  126. const titleMatch = (p.title || '').toLowerCase().includes(lowerKey);
  127. const countryMatch = (p.country || '').toLowerCase().includes(lowerKey);
  128. const cityMatch = (p.city || '').toLowerCase().includes(lowerKey);
  129. const providerMatch = (p.provider || '').toLowerCase().includes(lowerKey);
  130. return idMatch || titleMatch || countryMatch || cityMatch || providerMatch;
  131. });
  132. }
  133. if (selectedVisaType !== 'all') {
  134. list = list.filter((p) => (p.visa_type || 'Tourist').toLowerCase() === selectedVisaType.toLowerCase());
  135. }
  136. if (selectedCountry !== 'all') {
  137. list = list.filter((p) => p.country === selectedCountry);
  138. }
  139. if (selectedProvider !== 'all') {
  140. list = list.filter((p) => p.provider === selectedProvider);
  141. }
  142. if (selectedSchemaFilter === 'bound') {
  143. list = list.filter((p) => p.schema_id && p.schema_id > 0);
  144. } else if (selectedSchemaFilter === 'unbound') {
  145. list = list.filter((p) => !p.schema_id || p.schema_id === 0);
  146. }
  147. list.sort((a, b) => {
  148. const scoreA = typeof a.recommend_score === 'number' ? a.recommend_score : 0;
  149. const scoreB = typeof b.recommend_score === 'number' ? b.recommend_score : 0;
  150. if (scoreB !== scoreA) return scoreB - scoreA;
  151. return b.id - a.id;
  152. });
  153. return list;
  154. }, [
  155. allProducts,
  156. statusTab,
  157. keyword,
  158. selectedVisaType,
  159. selectedCountry,
  160. selectedProvider,
  161. selectedSchemaFilter,
  162. ]);
  163. const paginatedProducts = useMemo(() => {
  164. const start = (page - 1) * pageSize;
  165. return filteredProducts.slice(start, start + pageSize);
  166. }, [filteredProducts, page, pageSize]);
  167. const handleResetFilters = () => {
  168. setStatusTab('all');
  169. setKeyword('');
  170. setSelectedVisaType('all');
  171. setSelectedCountry('all');
  172. setSelectedProvider('all');
  173. setSelectedSchemaFilter('all');
  174. setPage(1);
  175. };
  176. const hasActiveFilters =
  177. statusTab !== 'all' ||
  178. keyword.trim() !== '' ||
  179. selectedVisaType !== 'all' ||
  180. selectedCountry !== 'all' ||
  181. selectedProvider !== 'all' ||
  182. selectedSchemaFilter !== 'all';
  183. const handleSaveProduct = async (data: any) => {
  184. try {
  185. if (data.id) {
  186. await api.post('/api/vas/product/update', data, { params: { id: data.id } });
  187. toast.success(`商品 #${data.id} 更新成功`);
  188. } else {
  189. await api.post('/api/vas/product/create', data);
  190. toast.success('新商品发布成功');
  191. }
  192. fetchProductsOnly();
  193. if (selectedProduct && selectedProduct.id === data.id) {
  194. setSelectedProduct({ ...selectedProduct, ...data });
  195. }
  196. } catch (error: any) {
  197. toast.error('操作失败: ' + (error.response?.data?.detail || error.message));
  198. throw error;
  199. }
  200. };
  201. const handleToggleStatus = async (product: Product) => {
  202. const newStatus = product.enabled ? 0 : 1;
  203. const actionText = newStatus ? '上架' : '下架';
  204. try {
  205. await api.post(
  206. '/api/vas/product/update',
  207. {
  208. ...product,
  209. enabled: newStatus,
  210. },
  211. { params: { id: product.id } }
  212. );
  213. toast.success(`商品 #${product.id} 已${actionText}`);
  214. setAllProducts((prev) =>
  215. prev.map((item) => (item.id === product.id ? { ...item, enabled: newStatus } : item))
  216. );
  217. if (selectedProduct && selectedProduct.id === product.id) {
  218. setSelectedProduct({ ...selectedProduct, enabled: newStatus });
  219. }
  220. } catch (e: any) {
  221. toast.error(`${actionText}操作失败: ` + (e.response?.data?.detail || e.message));
  222. throw e;
  223. }
  224. };
  225. const handleViewDetail = (product: Product) => {
  226. setSelectedProduct(product);
  227. setIsDrawerOpen(true);
  228. };
  229. const handleOpenCreate = () => {
  230. setSelectedProduct(null);
  231. setProductModalOpen(true);
  232. };
  233. const handleOpenEdit = (product: Product) => {
  234. setSelectedProduct(product);
  235. setProductModalOpen(true);
  236. };
  237. const handleOpenRouting = (product: Product) => {
  238. setSelectedProduct(product);
  239. setRoutingModalOpen(true);
  240. };
  241. const handleOpenSchemaManager = () => {
  242. setSchemaModalOpen(true);
  243. };
  244. return (
  245. <div className="space-y-6 font-mono">
  246. {/* 1. 顶部标头与主操作按钮 */}
  247. <div className="bg-neutral-100 border-2 border-black p-6 shadow-[6px_6px_0px_#000] flex flex-col md:flex-row md:items-center justify-between gap-4">
  248. <div>
  249. <div className="text-[10px] font-bold text-neutral-500 uppercase tracking-widest">[ VAS-CATALOG // 签证服务商品库 ]</div>
  250. <h1 className="text-xl sm:text-2xl font-black text-black uppercase mt-1">
  251. 商品配置中心与 SCHEMA 表单
  252. </h1>
  253. <p className="text-xs text-neutral-600 font-sans mt-0.5">
  254. 统一管理可售签证及增值服务、动态表单 Schema 绑定与后台自动化分发路由策略。
  255. </p>
  256. </div>
  257. {/* 顶部右侧主要操作 */}
  258. <div className="flex flex-wrap items-center gap-2">
  259. <button
  260. onClick={fetchProductsOnly}
  261. disabled={loading}
  262. className="p-2 bg-neutral-50 hover:bg-neutral-200 border-2 border-black text-black transition shadow-[2px_2px_0px_#000]"
  263. title="刷新数据"
  264. >
  265. <RefreshCw size={14} className={loading ? 'animate-spin' : ''} />
  266. </button>
  267. <button
  268. onClick={handleOpenSchemaManager}
  269. className="flex items-center gap-1.5 px-3.5 py-1.5 bg-white hover:bg-neutral-100 text-black border-2 border-black font-bold text-xs shadow-[2px_2px_0px_#000] transition active:translate-x-0.5 active:translate-y-0.5 uppercase"
  270. >
  271. <FileJson size={14} />
  272. <span>[ 表单 SCHEMA 库 ]</span>
  273. </button>
  274. <button
  275. onClick={handleOpenCreate}
  276. className="flex items-center gap-1.5 px-4 py-1.5 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black font-black text-xs shadow-[2px_2px_0px_#000] transition active:translate-x-0.5 active:translate-y-0.5 uppercase whitespace-nowrap"
  277. >
  278. <Plus size={15} />
  279. <span>[ 发布新商品 ]</span>
  280. </button>
  281. </div>
  282. </div>
  283. {/* 2. 统计指标概览卡片 (4 列布局) */}
  284. <div className="grid grid-cols-2 lg:grid-cols-4 gap-3.5">
  285. {/* 卡片 1 */}
  286. <div
  287. onClick={() => {
  288. setStatusTab('all');
  289. setPage(1);
  290. }}
  291. className={`p-4 border-2 border-black cursor-pointer bg-white transition active:translate-x-0.5 active:translate-y-0.5 ${
  292. statusTab === 'all'
  293. ? 'bg-amber-100 shadow-[4px_4px_0px_#000]'
  294. : 'shadow-[2px_2px_0px_#000] hover:bg-neutral-50'
  295. }`}
  296. >
  297. <div className="flex items-center justify-between text-neutral-500 mb-2 border-b-2 border-black pb-1.5">
  298. <span className="text-[10px] font-black uppercase text-black">[ 全部服务商品 ]</span>
  299. <Package size={14} className="text-black" />
  300. </div>
  301. <div className="text-2xl font-black text-black">{stats.total} 个</div>
  302. <div className="text-[10px] text-neutral-500 font-sans mt-0.5">全量已配置服务</div>
  303. </div>
  304. {/* 卡片 2 */}
  305. <div
  306. onClick={() => {
  307. setStatusTab('active');
  308. setPage(1);
  309. }}
  310. className={`p-4 border-2 border-black cursor-pointer bg-white transition active:translate-x-0.5 active:translate-y-0.5 ${
  311. statusTab === 'active'
  312. ? 'bg-amber-300 shadow-[4px_4px_0px_#000]'
  313. : 'shadow-[2px_2px_0px_#000] hover:bg-neutral-50'
  314. }`}
  315. >
  316. <div className="flex items-center justify-between text-neutral-500 mb-2 border-b-2 border-black pb-1.5">
  317. <span className="text-[10px] font-black uppercase text-black">[ 上架在售 ]</span>
  318. <CheckCircle2 size={14} className="text-black" />
  319. </div>
  320. <div className="text-2xl font-black text-black">{stats.active} 个</div>
  321. <div className="text-[10px] text-neutral-500 font-sans mt-0.5">
  322. 占比 {stats.total > 0 ? Math.round((stats.active / stats.total) * 100) : 0}% 处于可售状态
  323. </div>
  324. </div>
  325. {/* 卡片 3 */}
  326. <div
  327. onClick={() => {
  328. setStatusTab('inactive');
  329. setPage(1);
  330. }}
  331. className={`p-4 border-2 border-black cursor-pointer bg-white transition active:translate-x-0.5 active:translate-y-0.5 ${
  332. statusTab === 'inactive'
  333. ? 'bg-neutral-200 shadow-[4px_4px_0px_#000]'
  334. : 'shadow-[2px_2px_0px_#000] hover:bg-neutral-50'
  335. }`}
  336. >
  337. <div className="flex items-center justify-between text-neutral-500 mb-2 border-b-2 border-black pb-1.5">
  338. <span className="text-[10px] font-black uppercase text-black">[ 已下架停售 ]</span>
  339. <XCircle size={14} className="text-black" />
  340. </div>
  341. <div className="text-2xl font-black text-black">{stats.inactive} 个</div>
  342. <div className="text-[10px] text-neutral-500 font-sans mt-0.5">暂停前台对外申请</div>
  343. </div>
  344. {/* 卡片 4 */}
  345. <div
  346. onClick={() => {
  347. setSelectedSchemaFilter(selectedSchemaFilter === 'bound' ? 'all' : 'bound');
  348. setPage(1);
  349. }}
  350. className={`p-4 border-2 border-black cursor-pointer bg-white transition active:translate-x-0.5 active:translate-y-0.5 ${
  351. selectedSchemaFilter === 'bound'
  352. ? 'bg-amber-200 shadow-[4px_4px_0px_#000]'
  353. : 'shadow-[2px_2px_0px_#000] hover:bg-neutral-50'
  354. }`}
  355. >
  356. <div className="flex items-center justify-between text-neutral-500 mb-2 border-b-2 border-black pb-1.5">
  357. <span className="text-[10px] font-black uppercase text-black">[ SCHEMA 覆盖率 ]</span>
  358. <FileJson size={14} className="text-black" />
  359. </div>
  360. <div className="text-2xl font-black text-black">
  361. {stats.withSchema} <span className="text-xs text-neutral-500 font-normal">/ {stats.total}</span>
  362. </div>
  363. <div className="text-[10px] text-neutral-500 font-sans mt-0.5">覆盖率 {stats.schemaCoverage}%</div>
  364. </div>
  365. </div>
  366. {/* 3. 筛选与操作工具栏 */}
  367. <div className="bg-white border-2 border-black p-4 shadow-[4px_4px_0px_#000] space-y-3.5">
  368. {/* 状态 Tabs 与快速搜索 */}
  369. <div className="flex flex-col lg:flex-row lg:items-center justify-between gap-3">
  370. {/* Tabs 切换 */}
  371. <div className="flex gap-1 overflow-x-auto">
  372. <button
  373. onClick={() => {
  374. setStatusTab('all');
  375. setPage(1);
  376. }}
  377. className={`px-3 py-1.5 border-2 text-xs font-bold uppercase transition ${
  378. statusTab === 'all'
  379. ? 'bg-amber-300 border-black text-black shadow-[2px_2px_0px_#000]'
  380. : 'bg-neutral-50 border-black text-neutral-700 hover:bg-neutral-100'
  381. }`}
  382. >
  383. [ 全部 ({stats.total}) ]
  384. </button>
  385. <button
  386. onClick={() => {
  387. setStatusTab('active');
  388. setPage(1);
  389. }}
  390. className={`px-3 py-1.5 border-2 text-xs font-bold uppercase transition ${
  391. statusTab === 'active'
  392. ? 'bg-amber-300 border-black text-black shadow-[2px_2px_0px_#000]'
  393. : 'bg-neutral-50 border-black text-neutral-700 hover:bg-neutral-100'
  394. }`}
  395. >
  396. [ 上架在售 ({stats.active}) ]
  397. </button>
  398. <button
  399. onClick={() => {
  400. setStatusTab('inactive');
  401. setPage(1);
  402. }}
  403. className={`px-3 py-1.5 border-2 text-xs font-bold uppercase transition ${
  404. statusTab === 'inactive'
  405. ? 'bg-amber-300 border-black text-black shadow-[2px_2px_0px_#000]'
  406. : 'bg-neutral-50 border-black text-neutral-700 hover:bg-neutral-100'
  407. }`}
  408. >
  409. [ 已下架 ({stats.inactive}) ]
  410. </button>
  411. </div>
  412. {/* 搜索框 */}
  413. <div className="relative w-full lg:w-80">
  414. <input
  415. type="text"
  416. placeholder="搜索商品 / 国家 / 城市 / Provider..."
  417. className="w-full pl-9 pr-8 py-1.5 border-2 border-black bg-neutral-50 text-xs font-mono focus:bg-white outline-none shadow-[2px_2px_0px_#000] text-black"
  418. value={keyword}
  419. onChange={(e) => {
  420. setKeyword(e.target.value);
  421. setPage(1);
  422. }}
  423. />
  424. <Search size={14} className="absolute left-3 top-2 text-black pointer-events-none" />
  425. {keyword && (
  426. <button
  427. onClick={() => {
  428. setKeyword('');
  429. setPage(1);
  430. }}
  431. className="absolute right-2.5 top-1.5 text-black hover:text-rose-600 font-bold"
  432. >
  433. ✕
  434. </button>
  435. )}
  436. </div>
  437. </div>
  438. {/* 次级下拉组合筛选 */}
  439. <div className="flex flex-wrap items-center gap-2 pt-2 border-t-2 border-dashed border-neutral-300 text-xs">
  440. <div className="flex items-center gap-1 text-black font-bold uppercase mr-1">
  441. <Filter size={12} />
  442. <span>[ 维度过滤 ]:</span>
  443. </div>
  444. {/* 国家下拉 */}
  445. <select
  446. className="border-2 border-black px-2 py-1 bg-neutral-50 text-black text-xs font-bold outline-none shadow-[1px_1px_0px_#000]"
  447. value={selectedCountry}
  448. onChange={(e) => {
  449. setSelectedCountry(e.target.value);
  450. setPage(1);
  451. }}
  452. >
  453. <option value="all">[ 全部国家/地区 ]</option>
  454. {availableCountries.map((c) => (
  455. <option key={c} value={c}>
  456. {c}
  457. </option>
  458. ))}
  459. </select>
  460. {/* 签证类型下拉 */}
  461. <select
  462. className="border-2 border-black px-2 py-1 bg-neutral-50 text-black text-xs font-bold outline-none shadow-[1px_1px_0px_#000]"
  463. value={selectedVisaType}
  464. onChange={(e) => {
  465. setSelectedVisaType(e.target.value);
  466. setPage(1);
  467. }}
  468. >
  469. <option value="all">[ 全部签证类型 ]</option>
  470. <option value="Tourist">旅游签证 (Tourist)</option>
  471. <option value="Business">商务签证 (Business)</option>
  472. <option value="Family">探亲访友 (Family)</option>
  473. <option value="Student">留学签证 (Student)</option>
  474. <option value="Work">工作签证 (Work)</option>
  475. <option value="Transit">过境签证 (Transit)</option>
  476. <option value="e-Visa">电子签证 (e-Visa)</option>
  477. </select>
  478. {/* Provider 下拉 */}
  479. <select
  480. className="border-2 border-black px-2 py-1 bg-neutral-50 text-black text-xs font-bold outline-none shadow-[1px_1px_0px_#000]"
  481. value={selectedProvider}
  482. onChange={(e) => {
  483. setSelectedProvider(e.target.value);
  484. setPage(1);
  485. }}
  486. >
  487. <option value="all">[ 全部 Provider ]</option>
  488. {availableProviders.map((p) => (
  489. <option key={p} value={p}>
  490. {p}
  491. </option>
  492. ))}
  493. </select>
  494. {/* Schema 绑定下拉 */}
  495. <select
  496. className="border-2 border-black px-2 py-1 bg-neutral-50 text-black text-xs font-bold outline-none shadow-[1px_1px_0px_#000]"
  497. value={selectedSchemaFilter}
  498. onChange={(e: any) => {
  499. setSelectedSchemaFilter(e.target.value);
  500. setPage(1);
  501. }}
  502. >
  503. <option value="all">[ Schema 绑定状态 ]</option>
  504. <option value="bound">已绑定 Schema</option>
  505. <option value="unbound">未绑定 Schema</option>
  506. </select>
  507. {/* 重置筛选按钮 */}
  508. {hasActiveFilters && (
  509. <button
  510. onClick={handleResetFilters}
  511. className="px-2 py-1 bg-rose-100 hover:bg-rose-200 border border-black text-rose-800 text-[11px] font-bold shadow-[1px_1px_0px_#000] uppercase"
  512. >
  513. [ 清空筛选 ]
  514. </button>
  515. )}
  516. <div className="ml-auto text-[11px] text-neutral-500 font-bold uppercase">
  517. MATCHED: <span className="text-black">{filteredProducts.length}</span> ITEMS
  518. </div>
  519. </div>
  520. </div>
  521. {/* 4. 商品列表组件 */}
  522. <ProductList
  523. products={paginatedProducts}
  524. schemas={schemas}
  525. loading={loading}
  526. onViewDetail={handleViewDetail}
  527. onEdit={handleOpenEdit}
  528. onManageRouting={handleOpenRouting}
  529. onToggleStatus={handleToggleStatus}
  530. />
  531. {/* 5. 分页组件 */}
  532. {filteredProducts.length > 0 && (
  533. <div className="mt-4 flex justify-center md:justify-end">
  534. <Pagination
  535. currentPage={page}
  536. total={filteredProducts.length}
  537. pageSize={pageSize}
  538. onPageChange={(newPage) => setPage(newPage)}
  539. />
  540. </div>
  541. )}
  542. {/* 6. 商品全景详情抽屉 */}
  543. <ProductDetailDrawer
  544. isOpen={isDrawerOpen}
  545. onClose={() => setIsDrawerOpen(false)}
  546. product={selectedProduct}
  547. schemas={schemas}
  548. onEdit={(p) => {
  549. setIsDrawerOpen(false);
  550. handleOpenEdit(p);
  551. }}
  552. onManageRouting={(p) => {
  553. handleOpenRouting(p);
  554. }}
  555. onManageSchemas={() => {
  556. handleOpenSchemaManager();
  557. }}
  558. onToggleStatus={handleToggleStatus}
  559. />
  560. {/* 7. 新增/编辑商品弹窗 */}
  561. <ProductModal
  562. isOpen={isProductModalOpen}
  563. onClose={() => setProductModalOpen(false)}
  564. product={selectedProduct}
  565. onSubmit={handleSaveProduct}
  566. onManageSchemas={handleOpenSchemaManager}
  567. />
  568. {/* 8. 路由策略管理弹窗 */}
  569. {selectedProduct && (
  570. <RoutingManager
  571. isOpen={isRoutingModalOpen}
  572. productId={selectedProduct.id}
  573. productTitle={selectedProduct.title}
  574. onClose={() => {
  575. setRoutingModalOpen(false);
  576. fetchProductsOnly();
  577. }}
  578. />
  579. )}
  580. {/* 9. 表单 Schema 库管理器 */}
  581. <SchemaManager
  582. isOpen={isSchemaModalOpen}
  583. onClose={() => {
  584. setSchemaModalOpen(false);
  585. api.get('/api/vas/schema/list').then((res) => {
  586. setSchemas(Array.isArray(res.data?.data) ? res.data.data : []);
  587. });
  588. }}
  589. />
  590. </div>
  591. );
  592. }