import React, { useState, useEffect } from 'react'; import { Card, Table, Button, Space, Tag, Input, Select, Row, Col, Modal, message, Tooltip, Badge, Alert, Descriptions, Divider, Dropdown, Menu, Image, Typography, Tabs, Form, InputNumber, Switch, } from 'antd'; import { SyncOutlined, EditOutlined, EyeOutlined, GlobalOutlined, AmazonOutlined, ShoppingOutlined, ShopOutlined, CheckCircleOutlined, CloseCircleOutlined, ExclamationCircleOutlined, LinkOutlined, ArrowUpOutlined, ArrowDownOutlined, } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; const { Text, Title } = Typography; const { Option } = Select; const { Search } = Input; const { TabPane } = Tabs; // ==================== 多商户店铺配置 ==================== // 当前用户拥有的店铺(根据登录用户的权限动态加载) interface UserShop { id: string; platform: string; shopId: string; shopName: string; region: string; status: 'ACTIVE' | 'INACTIVE'; apiSupported: boolean; // 是否支持API管理 } // 模拟当前用户拥有的店铺 const CURRENT_USER_SHOPS: UserShop[] = [ { id: '1', platform: 'AMAZON', shopId: 'AMZ-US-001', shopName: 'Amazon US Store', region: 'US', status: 'ACTIVE', apiSupported: true }, { id: '2', platform: 'AMAZON', shopId: 'AMZ-EU-001', shopName: 'Amazon EU Store', region: 'EU', status: 'ACTIVE', apiSupported: true }, { id: '3', platform: 'EBAY', shopId: 'EB-US-001', shopName: 'eBay US Store', region: 'US', status: 'ACTIVE', apiSupported: true }, { id: '4', platform: 'SHOPIFY', shopId: 'SF-001', shopName: 'My Shopify Store', region: 'US', status: 'ACTIVE', apiSupported: true }, { id: '5', platform: 'SHOPEE', shopId: 'SP-SG-001', shopName: 'Shopee Singapore', region: 'SG', status: 'ACTIVE', apiSupported: false }, // 不支持API { id: '6', platform: 'TIKTOK', shopId: 'TK-US-001', shopName: 'TikTok US Shop', region: 'US', status: 'ACTIVE', apiSupported: false }, // 不支持API ]; // 平台配置 const PLATFORM_CONFIG: Record = { AMAZON: { name: 'Amazon', color: '#FF9900', icon: }, EBAY: { name: 'eBay', color: '#E53238', icon: }, SHOPIFY: { name: 'Shopify', color: '#96BF48', icon: }, SHOPEE: { name: 'Shopee', color: '#EE4D2D', icon: }, TIKTOK: { name: 'TikTok Shop', color: '#000000', icon: }, LAZADA: { name: 'Lazada', color: '#0F156D', icon: }, }; // ==================== 跨平台商品接口 ==================== interface CrossPlatformProduct { id: string; localProductId: string; sku: string; name: string; image: string; category: string; description: string; platforms: { [shopId: string]: { status: 'LIVE' | 'OFFLINE' | 'PENDING' | 'ERROR' | 'SYNCING' | 'NOT_LISTED'; platformProductId: string; platformSku: string; price: number; stock: number; sales: number; listingUrl: string; lastSync: string; shopInfo: UserShop; }; }; basePrice: number; baseStock: number; totalSales: number; createdAt: string; updatedAt: string; } // ==================== 模拟数据 ==================== const MOCK_CROSS_PLATFORM_PRODUCTS: CrossPlatformProduct[] = [ { id: 'CP001', localProductId: 'P001', sku: 'TP-TEMP-001', name: '工业温度传感器 Pro', image: 'https://via.placeholder.com/200x200?text=Product', category: '工业自动化', description: '高精度工业温度传感器,适用于各种工业环境,测量范围-40°C至125°C', basePrice: 89.99, baseStock: 256, totalSales: 1250, createdAt: '2025-12-15 10:00:00', updatedAt: '2026-03-18 10:30:00', platforms: { 'AMZ-US-001': { status: 'LIVE', platformProductId: 'AMZ-123456', platformSku: 'TP-TEMP-001-AMZ', price: 99.99, stock: 100, sales: 850, listingUrl: 'https://amazon.com/dp/123456', lastSync: '2026-03-18 10:00:00', shopInfo: CURRENT_USER_SHOPS[0], }, 'AMZ-EU-001': { status: 'LIVE', platformProductId: 'AMZ-EU-789', platformSku: 'TP-TEMP-001-AMZ-EU', price: 89.99, stock: 80, sales: 200, listingUrl: 'https://amazon.de/dp/789', lastSync: '2026-03-18 09:00:00', shopInfo: CURRENT_USER_SHOPS[1], }, 'EB-US-001': { status: 'LIVE', platformProductId: 'EB-789012', platformSku: 'TP-TEMP-001-EB', price: 95.99, stock: 76, sales: 200, listingUrl: 'https://ebay.com/itm/789012', lastSync: '2026-03-18 09:30:00', shopInfo: CURRENT_USER_SHOPS[2], }, 'SP-SG-001': { status: 'LIVE', platformProductId: 'SP-345678', platformSku: 'TP-TEMP-001-SP', price: 89.99, stock: 76, sales: 80, listingUrl: 'https://shopee.sg/product/345678', lastSync: '2026-03-18 09:00:00', shopInfo: CURRENT_USER_SHOPS[4], }, }, }, { id: 'CP002', localProductId: 'P002', sku: 'TP-PRES-002', name: '压力传感器 Digital', image: 'https://via.placeholder.com/200x200?text=Product', category: '工业自动化', description: '数字式压力传感器,精度0.1%,支持多种输出信号', basePrice: 129.99, baseStock: 128, totalSales: 680, createdAt: '2026-03-10 14:30:00', updatedAt: '2026-03-18 09:15:00', platforms: { 'AMZ-US-001': { status: 'LIVE', platformProductId: 'AMZ-234567', platformSku: 'TP-PRES-002-AMZ', price: 139.99, stock: 50, sales: 500, listingUrl: 'https://amazon.com/dp/234567', lastSync: '2026-03-18 10:00:00', shopInfo: CURRENT_USER_SHOPS[0], }, 'SF-001': { status: 'LIVE', platformProductId: 'SF-890123', platformSku: 'TP-PRES-002-SF', price: 129.99, stock: 78, sales: 180, listingUrl: 'https://mystore.myshopify.com/products/890123', lastSync: '2026-03-18 08:30:00', shopInfo: CURRENT_USER_SHOPS[3], }, }, }, { id: 'CP003', localProductId: 'P003', sku: 'TP-FLOW-003', name: '流量计 Ultra', image: 'https://via.placeholder.com/200x200?text=Product', category: '仪器仪表', description: '超声波流量计,非接触式测量,精度高', basePrice: 299.99, baseStock: 64, totalSales: 320, createdAt: '2026-03-01 09:00:00', updatedAt: '2026-03-17 16:45:00', platforms: { 'AMZ-US-001': { status: 'OFFLINE', platformProductId: 'AMZ-345678', platformSku: 'TP-FLOW-003-AMZ', price: 319.99, stock: 0, sales: 300, listingUrl: 'https://amazon.com/dp/345678', lastSync: '2026-03-17 16:00:00', shopInfo: CURRENT_USER_SHOPS[0], }, 'EB-US-001': { status: 'ERROR', platformProductId: 'EB-901234', platformSku: 'TP-FLOW-003-EB', price: 299.99, stock: 64, sales: 20, listingUrl: 'https://ebay.com/itm/901234', lastSync: '2026-03-17 15:30:00', shopInfo: CURRENT_USER_SHOPS[2], }, }, }, ]; const STATUS_CONFIG: Record = { LIVE: { color: 'success', text: '在线', icon: }, OFFLINE: { color: 'default', text: '已下架', icon: }, PENDING: { color: 'warning', text: '审核中', icon: }, ERROR: { color: 'error', text: '异常', icon: }, SYNCING: { color: 'processing', text: '同步中', icon: }, NOT_LISTED: { color: 'default', text: '未上架', icon: }, }; const CrossPlatformManage: React.FC = () => { const [loading, setLoading] = useState(false); const [products, setProducts] = useState([]); const [filteredProducts, setFilteredProducts] = useState([]); const [selectedShop, setSelectedShop] = useState('ALL'); const [searchText, setSearchText] = useState(''); const [selectedRows, setSelectedRows] = useState([]); const [syncLoading, setSyncLoading] = useState>({}); // 详情弹窗 const [detailModalVisible, setDetailModalVisible] = useState(false); const [selectedProduct, setSelectedProduct] = useState(null); // 同步弹窗 const [syncModalVisible, setSyncModalVisible] = useState(false); const [syncForm] = Form.useForm(); const [syncingProduct, setSyncingProduct] = useState(null); const [selectedSyncShops, setSelectedSyncShops] = useState([]); useEffect(() => { fetchProducts(); }, []); useEffect(() => { filterProducts(); }, [products, selectedShop, searchText]); const fetchProducts = async () => { setLoading(true); try { await new Promise(resolve => setTimeout(resolve, 500)); setProducts(MOCK_CROSS_PLATFORM_PRODUCTS); } catch (error) { message.error('加载跨平台商品失败'); } finally { setLoading(false); } }; const filterProducts = () => { let result = [...products]; // 按店铺筛选 if (selectedShop !== 'ALL') { result = result.filter(p => p.platforms[selectedShop] && p.platforms[selectedShop].status !== 'NOT_LISTED' ); } // 按关键词搜索 if (searchText) { result = result.filter(p => p.name.toLowerCase().includes(searchText.toLowerCase()) || p.sku.toLowerCase().includes(searchText.toLowerCase()) ); } setFilteredProducts(result); }; // 获取用户拥有的店铺列表(按平台分组) const getUserShopsByPlatform = () => { const grouped: Record = {}; CURRENT_USER_SHOPS.forEach(shop => { if (!grouped[shop.platform]) { grouped[shop.platform] = []; } grouped[shop.platform].push(shop); }); return grouped; }; // 查看商品详情 const handleViewDetail = (product: CrossPlatformProduct) => { setSelectedProduct(product); setDetailModalVisible(true); }; // 打开同步弹窗 const handleOpenSyncModal = (product: CrossPlatformProduct) => { setSyncingProduct(product); // 默认选中已上架的店铺 const listedShops = Object.entries(product.platforms) .filter(([_, info]) => info.status !== 'NOT_LISTED') .filter(([shopId, info]) => info.shopInfo.apiSupported) // 只选中支持API的店铺 .map(([shopId]) => shopId); setSelectedSyncShops(listedShops); syncForm.setFieldsValue({ shops: listedShops, syncStock: true, syncPrice: false, }); setSyncModalVisible(true); }; // 执行同步 const handleSync = async () => { if (selectedSyncShops.length === 0) { message.warning('请至少选择一个目标店铺'); return; } const values = syncForm.getFieldsValue(); message.loading(`正在同步到 ${selectedSyncShops.length} 个店铺...`, 2); await new Promise(resolve => setTimeout(resolve, 2000)); message.success(`同步完成!库存: ${values.syncStock ? '是' : '否'}, 价格: ${values.syncPrice ? '是' : '否'}`); setSyncModalVisible(false); fetchProducts(); }; // 批量同步库存 const handleBatchSyncStock = async () => { if (selectedRows.length === 0) { message.warning('请先选择商品'); return; } Modal.confirm({ title: '批量同步库存', content: `将对 ${selectedRows.length} 个商品同步库存到所有支持API的店铺`, onOk: async () => { message.loading('正在批量同步库存...', 2); await new Promise(resolve => setTimeout(resolve, 2000)); message.success('批量同步完成'); fetchProducts(); }, }); }; // 获取店铺统计 const getShopStats = () => { const stats: Record = { ALL: products.length }; CURRENT_USER_SHOPS.forEach(shop => { stats[shop.shopId] = products.filter(p => p.platforms[shop.shopId] && p.platforms[shop.shopId].status !== 'NOT_LISTED' ).length; }); return stats; }; const shopStats = getShopStats(); const userShopsByPlatform = getUserShopsByPlatform(); // 表格列定义 const columns: ColumnsType = [ { title: '商品信息', key: 'productInfo', width: 300, render: (_, record) => (
{record.name}
SKU: {record.sku}
{record.category}
), }, { title: '本地信息', key: 'localInfo', width: 150, render: (_, record) => (
价格: ${record.basePrice.toFixed(2)}
库存: {record.baseStock}
总销量: {record.totalSales}
), }, // 为每个用户店铺生成一列 ...CURRENT_USER_SHOPS.map(shop => ({ title: (
{PLATFORM_CONFIG[shop.platform]?.icon}
{shop.region}
), key: `shop-${shop.shopId}`, width: 100, align: 'center' as const, render: (_: any, record: CrossPlatformProduct) => { const platformInfo = record.platforms[shop.shopId]; if (!platformInfo || platformInfo.status === 'NOT_LISTED') { return 未上架; } const statusConfig = STATUS_CONFIG[platformInfo.status]; const canManage = shop.apiSupported; return ( handleViewDetail(record)}> 查看详情 {canManage && platformInfo.status === 'LIVE' && ( handleOpenSyncModal(record)}> 同步库存/价格 )} {canManage && platformInfo.status === 'LIVE' && ( message.info('打开价格调整')}> 调整价格 )} {canManage && platformInfo.status === 'LIVE' && ( message.info('执行下架')}> 下架 )} {canManage && platformInfo.status === 'OFFLINE' && ( message.info('执行上架')}> 上架 )} {!canManage && ( 不支持API管理 )} {platformInfo.listingUrl && ( 打开商品页 )} } > {statusConfig.text} {!canManage && *} ); }, })), { title: '操作', key: 'action', width: 180, fixed: 'right', render: (_, record) => ( ), }, ]; return (

• 集中管理您所有店铺的在线商品

• 标记 * 的店铺暂不支持API管理,需要手动操作

• 同步操作需要指定目标店铺,只同步到支持API的店铺

• 当前拥有 {CURRENT_USER_SHOPS.length} 个店铺

} type="info" showIcon style={{ marginBottom: 16 }} /> 跨平台商品列表 {selectedRows.length > 0 && ( } /> )} `共 ${total} 个商品` }} rowSelection={{ selectedRowKeys: selectedRows.map(r => r.id), onChange: (_, rows) => setSelectedRows(rows), }} /> {/* 商品详情弹窗 */} setDetailModalVisible(false)} width={900} footer={[ , ]} > {selectedProduct && ( {selectedProduct.name} {selectedProduct.sku} {selectedProduct.category} ${selectedProduct.basePrice.toFixed(2)} {selectedProduct.baseStock} {selectedProduct.totalSales} {selectedProduct.createdAt} {selectedProduct.updatedAt}
商品描述:

{selectedProduct.description}

( {PLATFORM_CONFIG[info.shopInfo.platform]?.icon} {info.shopInfo.shopName} {info.shopInfo.region} {!info.shopInfo.apiSupported && No API} ), }, { title: '状态', render: ([_, info]: [string, any]) => ( {STATUS_CONFIG[info.status].text} ), }, { title: '平台SKU', render: ([_, info]: [string, any]) => info.platformSku, }, { title: '售价', render: ([_, info]: [string, any]) => `$${info.price.toFixed(2)}`, }, { title: '库存', render: ([_, info]: [string, any]) => info.stock, }, { title: '销量', render: ([_, info]: [string, any]) => info.sales, }, { title: '最后同步', render: ([_, info]: [string, any]) => info.lastSync, }, { title: '操作', render: ([shopId, info]: [string, any]) => ( {info.shopInfo.apiSupported && ( )} {info.listingUrl && ( 查看 )} ), }, ]} /> )} {/* 同步弹窗 */} setSyncModalVisible(false)} onOk={handleSync} width={600} > {syncingProduct && (
)}
); }; // 添加 OptGroup 导入 const { OptGroup } = Select; export default CrossPlatformManage;