From 047438968bc8a272479fb161e4d2a405bd1ce92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B1=95=E9=B9=8F?= Date: Wed, 19 Nov 2025 01:57:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=A2=84=E7=BA=A6=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0VIP=E5=AE=A2=E6=88=B7=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加VIP客户搜索功能,支持姓名和手机号模糊搜索 增加手机号自动检测VIP功能并提供切换按钮 优化VIP客户选择界面样式和交互流程 --- index.php | 313 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 282 insertions(+), 31 deletions(-) diff --git a/index.php b/index.php index 298309d..6426f96 100644 --- a/index.php +++ b/index.php @@ -182,6 +182,112 @@ $packages_json = json_encode(array_map(function($package) { 洗车预约系统 + +
@@ -271,10 +377,17 @@ $packages_json = json_encode(array_map(function($package) {
@@ -286,7 +399,9 @@ $packages_json = json_encode(array_map(function($package) {
- + +
@@ -404,52 +519,188 @@ $packages_json = json_encode(array_map(function($package) { slotDuration: 30 // 30分钟一个时段 }; - // 初始化 + // 页面加载完成时初始化 document.addEventListener('DOMContentLoaded', function() { - const today = new Date(); - today.setDate(today.getDate()); - const todayStr = today.toISOString().split('T')[0]; - document.getElementById('appointment_date').value = todayStr; - selectedDate = todayStr; + // 初始化时间选择 + generateTimeSlots(); - // 默认选择今天的日期并显示时间段 - selectDate(todayStr); + // 处理当前时间 + const now = new Date(); + const todayStr = now.getFullYear() + '-' + + String(now.getMonth() + 1).padStart(2, '0') + '-' + + String(now.getDate()).padStart(2, '0'); + document.getElementById('service_date').value = todayStr; - // 加载VIP客户列表 + // 检查数据库连接 + checkDatabaseConnection(); + + // 加载VIP客户(必须在页面加载时完成) loadVIPCustomers(); - - // 移动端优化 - if (/Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) { - document.body.classList.add('mobile-device'); - // 自动聚焦到姓名输入框 - setTimeout(() => { - document.getElementById('customer_name').focus(); - }, 500); - } }); + let allVIPCustomers = []; // 全局变量存储所有VIP客户数据 + // 加载VIP客户列表 function loadVIPCustomers() { - // 这里将从数据库获取VIP客户列表 - // 在实际应用中,您可能需要通过AJAX获取 fetch('get_vip_customers.php') .then(response => response.json()) .then(data => { - const vipSelect = document.getElementById('vip_id'); - vipSelect.innerHTML = ''; - data.forEach(vip => { - const option = document.createElement('option'); - option.value = vip.id; - option.textContent = `${vip.customer_name} (${vip.phone})`; - vipSelect.appendChild(option); - }); + allVIPCustomers = data; // 存储所有VIP客户数据 + updateVIPSelect(data); // 更新下拉列表 }) .catch(error => { console.log('加载VIP客户列表失败:', error); - // 如果加载失败,显示空列表 + allVIPCustomers = []; }); } + // 更新VIP客户下拉列表 + function updateVIPSelect(customers) { + const vipSelect = document.getElementById('vip_id'); + vipSelect.innerHTML = ''; + customers.forEach(vip => { + const option = document.createElement('option'); + option.value = vip.id; + option.textContent = `${vip.customer_name} (${vip.phone})`; + vipSelect.appendChild(option); + }); + } + + // VIP客户搜索功能 + function searchVIPCustomers() { + const searchTerm = document.getElementById('vip_search').value.trim(); + const searchResultsDiv = document.getElementById('vip_search_results'); + + if (searchTerm === '') { + clearSearchResults(); + updateVIPSelect(allVIPCustomers); + return; + } + + // 模糊搜索:支持姓名和手机号搜索 + const filteredCustomers = allVIPCustomers.filter(vip => + vip.customer_name.includes(searchTerm) || + vip.phone.includes(searchTerm) + ); + + // 显示搜索结果 + displaySearchResults(filteredCustomers, searchTerm); + + // 隐藏下拉列表 + document.getElementById('vip_id').style.display = 'none'; + } + + // 显示搜索结果 + function displaySearchResults(customers, searchTerm) { + const searchResultsDiv = document.getElementById('vip_search_results'); + + if (customers.length === 0) { + searchResultsDiv.innerHTML = '
没有找到匹配的客户
'; + } else { + searchResultsDiv.innerHTML = customers.map(vip => ` +
+
${highlightSearchTerm(vip.customer_name, searchTerm)}
+
${highlightSearchTerm(vip.phone, searchTerm)}
+
${vip.car_model || '未知车型'} - ${vip.car_number || '未知车牌'}
+
+ `).join(''); + } + + searchResultsDiv.style.display = 'block'; + } + + // 高亮搜索关键词 + function highlightSearchTerm(text, searchTerm) { + if (!searchTerm) return text; + const regex = new RegExp(`(${searchTerm})`, 'gi'); + return text.replace(regex, '$1'); + } + + // 清除搜索结果 + function clearSearchResults() { + document.getElementById('vip_search_results').style.display = 'none'; + document.getElementById('vip_id').style.display = 'block'; + + // 清除搜索输入 + const searchInput = document.getElementById('vip_search'); + if (searchInput && searchInput.value !== '') { + searchInput.value = ''; + updateVIPSelect(allVIPCustomers); + } + } + + // 选择VIP客户 + function selectVIPCustomer(customerId) { + // 设置下拉选择值 + document.getElementById('vip_id').value = customerId; + + // 清除搜索状态 + clearSearchResults(); + + // 加载VIP客户信息 + loadVIPInfo(); + } + + // 检查手机号是否为VIP客户 + function checkPhoneForVIP() { + const phoneInput = document.getElementById('phone'); + const tipDiv = document.getElementById('phone_vip_tip'); + const phone = phoneInput.value.trim(); + + // 清除提示 + tipDiv.style.display = 'none'; + tipDiv.className = 'phone-vip-tip'; + + // 如果手机号为空或过短,不进行检查 + if (phone.length < 3) { + return; + } + + // 在VIP客户中搜索匹配的手机号 + const matchedVIP = allVIPCustomers.find(vip => vip.phone.includes(phone)); + + if (matchedVIP) { + // 显示VIP客户提示 + tipDiv.innerHTML = ` + 👑 检测到VIP客户!
+ 该手机号属于 VIP客户:${matchedVIP.customer_name}
+ + `; + tipDiv.className = 'phone-vip-tip vip-detected'; + tipDiv.style.display = 'block'; + } else if (phone.length >= 8) { + // 显示建议提示(当手机号长度足够时) + tipDiv.innerHTML = ` + 💡 提示:未找到该手机号的VIP客户
+ 如果此客户是VIP客户,请检查手机号是否正确 + `; + tipDiv.className = 'phone-vip-tip suggestion'; + tipDiv.style.display = 'block'; + } + } + + // 切换到VIP模式 + function switchToVIPMode(vipId = null) { + // 切换到VIP客户模式 + document.getElementById('customer_type').value = 'vip'; + handleCustomerTypeChange(); + + // 如果提供了VIP ID,选择该VIP客户 + if (vipId) { + // 先等待VIP客户列表加载完成 + setTimeout(() => { + document.getElementById('vip_id').value = vipId; + loadVIPInfo(); + }, 500); + } + + // 隐藏提示 + document.getElementById('phone_vip_tip').style.display = 'none'; + } + // 处理客户类型变更 function handleCustomerTypeChange() { const customerType = document.getElementById('customer_type').value;