收货页面

欢迎,

收货管理

在这里管理您的收货信息

收货页面

加载中...

`); printWindow.document.close(); printWindow.print(); } // 确认全部已收货 function confirmAllReceived() { const currentUser = JSON.parse(localStorage.getItem('currentUser')); if (!currentUser || !currentUser.username) { alert('请先登录'); return; } if (confirm('确定已将所有订单的商品都收货了吗?确认后将无法撤销。')) { const orderDataKey = `orderData_${currentUser.username}`; const storedOrderData = localStorage.getItem(orderDataKey); if (storedOrderData) { const orderData = JSON.parse(storedOrderData); const currentOrders = orderData.currentOrders || []; const pendingOrders = currentOrders.filter(order => { const status = order.delivery_person ? 'delivering' : (order.status || 'pending'); return status === 'pending' || status === 'processing' || status === 'confirmed'; }); if (pendingOrders.length === 0) { alert('没有可确认收货的订单'); return; } let completedCount = 0; pendingOrders.forEach(order => { fetch('/api/finish', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ orderId: order.id, username: currentUser.username }) }) .then(response => response.json()) .then(data => { if (data.success) { completedCount++; if (completedCount === pendingOrders.length) { fetch('/api/generate-verification-code', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: currentUser.username }) }).catch(e => console.error('生成核对码失败:', e)); alert(`已确认 ${completedCount} 个订单的收货`); displayMainReceipt(); } } }) .catch(error => { console.error('确认收货失败:', error); }); }); } } } // 打印主收据 function printMainReceipt() { const printContent = document.getElementById('mainReceiptPrintArea').innerHTML; // 创建打印页面 const printWindow = window.open('', '_blank'); printWindow.document.write(` 主收据 - 闲吃吃 ${printContent} `); printWindow.document.close(); printWindow.print(); } // 导出主收据 function exportMainReceipt() { const receiptContent = document.getElementById('mainReceiptPrintArea'); const currentUser = JSON.parse(localStorage.getItem('currentUser')); // 创建收据文本内容 let textContent = '闲吃吃 - 主收据汇总\n'; textContent += '=' .repeat(50) + '\n\n'; textContent += `用户: ${currentUser.username}\n`; textContent += `生成时间: ${new Date().toLocaleString('zh-CN')}\n\n`; // 获取订单信息 const orderElements = receiptContent.querySelectorAll('.flex.items-center.justify-between'); let totalAmount = 0; let orderCount = 0; textContent += '订单明细:\n'; textContent += '-'.repeat(30) + '\n'; orderElements.forEach((element, index) => { const productName = element.querySelector('.font-medium.text-gray-800')?.textContent || ''; const price = element.querySelector('.font-semibold.text-gray-800')?.textContent || ''; const orderId = element.querySelector('.text-xs.text-gray-500')?.textContent || ''; const storeInfo = element.querySelector('.text-sm.text-gray-600')?.textContent || ''; if (productName && price) { textContent += `${index + 1}. ${productName}\n`; textContent += ` ${storeInfo}\n`; textContent += ` ${orderId}\n`; textContent += ` 金额: ${price}\n\n`; // 提取数字并累加 const priceValue = parseFloat(price.replace('HK$', '')); if (!isNaN(priceValue)) { totalAmount += priceValue; orderCount++; } } }); textContent += '-'.repeat(30) + '\n'; textContent += `总订单数: ${orderCount}\n`; textContent += `总金额: HK$${totalAmount.toFixed(2)}\n`; textContent += '=' .repeat(50) + '\n'; textContent += '感谢您选择闲吃吃\n'; textContent += '此主收据由系统自动生成\n'; // 创建并下载文件 const blob = new Blob([textContent], { type: 'text/plain;charset=utf-8' }); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `闲吃吃主收据_${currentUser.username}_${new Date().toISOString().split('T')[0]}.txt`; document.body.appendChild(a); a.click(); document.body.removeChild(a); window.URL.revokeObjectURL(url); } // 应用当前模式的按钮显示逻辑 function applyModeButtonVisibility() { if (currentMode === 'iphone') { // iPhone模式隐藏所有操作按钮,显示iPhone模式的操作按钮 document.querySelectorAll('.computer-mode-buttons').forEach(el => el.classList.add('hidden')); document.querySelectorAll('.iphone-mode-action-btn').forEach(el => el.classList.remove('hidden')); // 如果之前有显示的菜单,恢复显示状态 if (window.visibleOrderActionsId) { const savedMenu = document.getElementById(`orderActions_${window.visibleOrderActionsId}`); if (savedMenu) { savedMenu.classList.remove('hidden'); } } } else { // 电脑模式显示所有操作按钮,隐藏iPhone模式的操作按钮 document.querySelectorAll('.computer-mode-buttons').forEach(el => el.classList.remove('hidden')); document.querySelectorAll('.iphone-mode-action-btn').forEach(el => el.classList.add('hidden')); document.querySelectorAll('.order-actions-menu').forEach(el => el.classList.add('hidden')); } // 检查是否在新手引导模式(电脑模式和iPhone模式都应用) applyGuideModeEffects(); } // 应用新手引导模式效果 function applyGuideModeEffects() { const hasPurchasedGuideProduct = localStorage.getItem('hasPurchasedGuideProduct'); if (hasPurchasedGuideProduct === 'true') { if (currentMode === 'iphone') { // iPhone模式:第一个订单的iPhone模式操作按钮变大闪烁 const iphoneActionBtn = document.querySelector('.first-order-item .iphone-mode-action-btn'); if (iphoneActionBtn) { iphoneActionBtn.classList.add('large-button', 'flash-animation'); } // 清除查看详情按钮的效果 document.querySelectorAll('.order-actions-menu button').forEach(btn => { btn.classList.remove('large-button', 'flash-animation'); }); } else { // 电脑模式:第一个订单的查看详情按钮变大闪烁 const firstDetailBtn = document.getElementById('firstOrderDetailBtn'); if (firstDetailBtn) { firstDetailBtn.classList.add('large-button', 'flash-animation'); } } } else { // 不在新手引导模式,恢复原样 removeGuideModeEffects(); } } // 移除新手引导模式效果 function removeGuideModeEffects() { // 移除所有操作按钮的效果 document.querySelectorAll('.iphone-mode-action-btn').forEach(btn => { btn.classList.remove('large-button', 'flash-animation'); }); // 移除所有查看详情按钮的效果 document.querySelectorAll('.order-actions-menu button').forEach(btn => { btn.classList.remove('large-button', 'flash-animation'); }); // 移除电脑模式下第一个订单查看详情按钮的效果 const firstDetailBtn = document.getElementById('firstOrderDetailBtn'); if (firstDetailBtn) { firstDetailBtn.classList.remove('large-button', 'flash-animation'); } } // 切换到电脑模式 function switchToComputerMode() { currentMode = 'computer'; document.getElementById('computerModeBtn').className = 'mode-switch-btn px-3 py-1.5 text-sm font-medium rounded-md bg-blue-600 text-white'; document.getElementById('iphoneModeBtn').className = 'mode-switch-btn px-3 py-1.5 text-sm font-medium rounded-md text-gray-600 hover:text-gray-800'; const htmlElement = document.documentElement; htmlElement.classList.remove('iphone-mode'); applyModeButtonVisibility(); localStorage.setItem('deviceMode', 'computer'); } // 切换到iPhone模式 function switchToIphoneMode() { currentMode = 'iphone'; document.getElementById('iphoneModeBtn').className = 'mode-switch-btn px-3 py-1.5 text-sm font-medium rounded-md bg-blue-600 text-white'; document.getElementById('computerModeBtn').className = 'mode-switch-btn px-3 py-1.5 text-sm font-medium rounded-md text-gray-600 hover:text-gray-800'; const htmlElement = document.documentElement; htmlElement.classList.add('iphone-mode'); applyModeButtonVisibility(); localStorage.setItem('deviceMode', 'iphone'); } // 显示订单操作菜单 function showOrderActions(orderId) { const hasPurchasedGuideProduct = localStorage.getItem('hasPurchasedGuideProduct'); // 获取当前订单的操作菜单 const menu = document.getElementById(`orderActions_${orderId}`); const isMenuVisible = menu && !menu.classList.contains('hidden'); // 如果菜单已经显示,则隐藏它 if (isMenuVisible) { menu.classList.add('hidden'); // 清除保存的显示状态 window.visibleOrderActionsId = null; // 不在新手引导模式,恢复操作按钮效果 if (hasPurchasedGuideProduct !== 'true') { const actionBtn = document.getElementById(`actionBtn_${orderId}`); if (actionBtn) { actionBtn.classList.remove('large-button', 'flash-animation'); } } return; } // 菜单原本是隐藏的,显示它 // 隐藏其他菜单 document.querySelectorAll('.order-actions-menu').forEach(el => el.classList.add('hidden')); // 显示当前菜单 if (menu) { menu.classList.remove('hidden'); } // 保存当前显示的菜单ID,用于订单刷新后恢复状态 window.visibleOrderActionsId = orderId; // 不在新手引导模式,恢复操作按钮效果 if (hasPurchasedGuideProduct !== 'true') { const actionBtn = document.getElementById(`actionBtn_${orderId}`); if (actionBtn) { actionBtn.classList.remove('large-button', 'flash-animation'); } } // 新手引导模式:让查看详情按钮变大闪烁 if (hasPurchasedGuideProduct === 'true' && currentMode === 'iphone') { const detailBtn = document.getElementById(`detailBtn_${orderId}`); if (detailBtn) { detailBtn.classList.add('large-button', 'flash-animation'); } } } // 隐藏订单操作菜单 function hideOrderActions(orderId) { const menu = document.getElementById(`orderActions_${orderId}`); if (menu) { menu.classList.add('hidden'); } } // 回到主页按钮事件 document.getElementById('backToHomeBtn').addEventListener('click', function() { window.location.href = 'index.html'; }); // 页面加载完成后的初始化 document.addEventListener('DOMContentLoaded', function() { console.log('收货页面已加载'); // 初始化贪吃蛇游戏 initSnakeGame(); makeDraggable(); setupSnakeControls(); // 立即显示游戏窗口 showSnakeGame(); loadUserInfo(); hideSnakeGame(); localStorage.setItem('snakeScore', score); // 检查是否购买了新手引导商品,如果是则显示"请下滑"提示 const hasPurchasedGuideProduct = localStorage.getItem('hasPurchasedGuideProduct'); if (hasPurchasedGuideProduct === 'true') { document.getElementById('centerMessage').classList.remove('hidden'); // 3秒后自动隐藏提示,并清除信号(下次不再显示) setTimeout(function() { document.getElementById('centerMessage').classList.add('hidden'); // 清除信号,下次进入页面不再显示提示 localStorage.removeItem('hasPurchasedGuideProduct'); // 清除新手引导效果(按钮恢复原样) removeGuideModeEffects(); }, 3000); } // 加载保存的显示模式(从 deviceMode 读取) const savedMode = localStorage.getItem('deviceMode'); console.log('当前设备模式:', savedMode); if (savedMode === 'iphone') { switchToIphoneMode(); } else if (savedMode === 'computer' || savedMode === 'laptop') { // 同时支持 'computer' 和 'laptop' 两种电脑模式值 switchToComputerMode(); } else { } // 先刷新本地存储数据,然后加载订单 refreshOrderDataInStorage().then(() => { loadOrders(); }); // 初始化未读消息徽章 updateUnreadBadge(); // 设置每3秒自动刷新订单(但不在主收据页面时) setInterval(function() { console.log('自动刷新订单数据'); // 只有在非主收据模式下才刷新,并且不在查看订单详情时 if (currentFilterMode !== 'mainReceipt' && document.getElementById('orderDetailModal').classList.contains('hidden')) { refreshOrderDataInStorage().then(() => { filterAndDisplayOrders(); }); } }, 3000); // 设置每5秒自动更新未读消息数量 setInterval(function() { updateUnreadBadge(); }, 5000); });