diff --git a/Management.html b/Management.html index 3b55509..5326549 100644 --- a/Management.html +++ b/Management.html @@ -375,6 +375,9 @@ let usersData = []; let chartData = []; + // 货源详情相关变量 + let currentSellerId = null; // 当前正在显示的卖家ID + // WebSocket相关变量 let ws = null; let wsReconnectAttempts = 0; @@ -520,6 +523,8 @@ // 对于任何类型的WebSocket消息,都重新加载数据,确保实时更新 if (data.type) { console.log('收到WebSocket消息,刷新数据:', data.type); + + // 重新加载统计数据 if (currentFilter === 'custom') { // 如果是自定义筛选,获取当前日期输入值 const startDate = startDateInput.value; @@ -528,6 +533,12 @@ } else { loadStats(currentFilter); } + + // 如果正在显示货源详情,重新加载货源数据 + if (currentSellerId) { + console.log('正在显示货源详情,重新加载数据'); + showSuppliesBySeller(currentSellerId); + } } else { console.warn('收到未知格式的WebSocket消息'); } @@ -906,6 +917,9 @@ // 显示指定卖家的货源 async function showSuppliesBySeller(sellerId) { + // 保存当前正在显示的卖家ID + currentSellerId = sellerId; + // 获取当前筛选条件和日期范围 let startDate = ''; let endDate = ''; @@ -917,17 +931,14 @@ endDate = endDateInput.value; } - // 构建缓存键,包含自定义日期信息 - const cacheKey = `supplies_${sellerId}_${filter}_${startDate}_${endDate}`; + // 构建API请求URL,包含自定义日期参数 + let url = `/api/admin/supplies?sellerId=${sellerId}&filter=${filter}`; + if (filter === 'custom') { + if (startDate) url += `&startDate=${startDate}`; + if (endDate) url += `&endDate=${endDate}`; + } try { - // 构建API请求URL,包含自定义日期参数 - let url = `/api/admin/supplies?sellerId=${sellerId}&filter=${filter}`; - if (filter === 'custom') { - if (startDate) url += `&startDate=${startDate}`; - if (endDate) url += `&endDate=${endDate}`; - } - const response = await fetch(url); const data = await response.json(); @@ -956,78 +967,40 @@ suppliesSection.style.display = 'block'; // 滚动到货源详情区域 suppliesSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); - - // 保存到缓存 - try { - const cached = localStorage.getItem(CACHE_KEY); - let cache = cached ? JSON.parse(cached) : {}; - cache[cacheKey] = { - data: data.data, - title: title, - timestamp: Date.now() - }; - localStorage.setItem(CACHE_KEY, JSON.stringify(cache)); - console.log('保存货源详情到缓存:', cacheKey); - } catch (error) { - console.error('保存货源详情缓存失败:', error); - } } else { console.error('加载货源数据失败:', data.message); - - // 尝试使用缓存数据 - try { - const cached = localStorage.getItem(CACHE_KEY); - if (cached) { - const cache = JSON.parse(cached); - if (cache[cacheKey] && (Date.now() - cache[cacheKey].timestamp < CACHE_EXPIRY)) { - const cachedData = cache[cacheKey]; - suppliesTitle.textContent = cachedData.title; - renderSupplies(cachedData.data.supplies); - suppliesSection.style.display = 'block'; - suppliesSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); - console.log('使用缓存的货源详情:', cacheKey); - } - } - } catch (error) { - console.error('读取货源详情缓存失败:', error); - } + suppliesGrid.innerHTML = '
加载货源数据失败,请刷新页面重试
'; + suppliesSection.style.display = 'block'; + suppliesSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } catch (error) { console.error('加载货源数据出错:', error); - - // 尝试使用缓存数据 - try { - const cached = localStorage.getItem(CACHE_KEY); - if (cached) { - const cache = JSON.parse(cached); - if (cache[cacheKey] && (Date.now() - cache[cacheKey].timestamp < CACHE_EXPIRY)) { - const cachedData = cache[cacheKey]; - suppliesTitle.textContent = cachedData.title; - renderSupplies(cachedData.data.supplies); - suppliesSection.style.display = 'block'; - suppliesSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); - console.log('使用缓存的货源详情:', cacheKey); - } - } - } catch (error) { - console.error('读取货源详情缓存失败:', error); - } + suppliesGrid.innerHTML = '加载货源数据失败,请刷新页面重试
'; + suppliesSection.style.display = 'block'; + suppliesSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } // 渲染货源卡片 function renderSupplies(supplies) { + console.log('renderSupplies函数被调用,supplies数量:', supplies.length); + console.log('完整supplies数据:', supplies); suppliesGrid.innerHTML = ''; // 过滤掉hidden状态的货源 const filteredSupplies = supplies.filter(supply => supply.status !== 'hidden'); + console.log('过滤后的supplies数量:', filteredSupplies.length); + console.log('过滤后的supplies数据:', filteredSupplies); if (filteredSupplies.length === 0) { suppliesGrid.innerHTML = '暂无货源数据
'; return; } - filteredSupplies.forEach(supply => { + filteredSupplies.forEach((supply, index) => { + console.log(`渲染第${index + 1}个货源,ID:`, supply.productId); + console.log(`该货源的product_log字段:`, supply.product_log); + console.log(`该货源的product_log类型:`, typeof supply.product_log); const card = document.createElement('div'); card.className = 'supply-card'; card.style.cssText = 'border: 1px solid #e8e8e8; border-radius: 8px; padding: 15px; transition: all 0.3s;'; @@ -1200,36 +1173,84 @@