script/mvcar/frontend/js/result.js

31 lines
1.3 KiB
JavaScript

// frontend/js/result.js
document.addEventListener('DOMContentLoaded', function() {
console.log('页面加载完成 - 挪车电话结果页面');
const phoneNumberElement = document.getElementById('phoneNumber');
const plateNumberElement = document.getElementById('plateNumber');
const carBrandElement = document.getElementById('carBrand');
const callButton = document.getElementById('callButton');
// 从 sessionStorage 获取车辆信息
const carInfoJson = sessionStorage.getItem('carInfo');
console.log('从 sessionStorage 获取车辆信息');
if (carInfoJson) {
const carInfo = JSON.parse(carInfoJson);
console.log(`车辆信息: ${JSON.stringify(carInfo)}`);
// 显示车辆信息
phoneNumberElement.textContent = carInfo.phone;
plateNumberElement.textContent = carInfo.plate;
carBrandElement.textContent = carInfo.brand;
// 设置拨号链接
callButton.href = 'tel:' + carInfo.phone.replace(/-/g, '');
console.log(`设置拨号链接: ${callButton.href}`);
} else {
console.warn('未找到车辆信息,重定向到搜索页面');
// 如果没有车辆信息,返回搜索页面
window.location.href = 'index.html';
}
});