65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
// 地址管理页面JavaScript功能
|
|
|
|
function setDefaultAddress(addressId) {
|
|
if (confirm('确定要设置为默认地址吗?')) {
|
|
fetch(`/address/set_default/${addressId}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
showAlert(data.message, 'success');
|
|
setTimeout(() => location.reload(), 1000);
|
|
} else {
|
|
showAlert(data.message, 'error');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
showAlert('操作失败,请重试', 'error');
|
|
});
|
|
}
|
|
}
|
|
|
|
function deleteAddress(addressId) {
|
|
if (confirm('确定要删除这个地址吗?删除后无法恢复。')) {
|
|
fetch(`/address/delete/${addressId}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
showAlert(data.message, 'success');
|
|
setTimeout(() => location.reload(), 1000);
|
|
} else {
|
|
showAlert(data.message, 'error');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
showAlert('删除失败,请重试', 'error');
|
|
});
|
|
}
|
|
}
|
|
|
|
// 页面加载完成后的处理
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// 为地址卡片添加点击效果
|
|
const addressCards = document.querySelectorAll('.address-card');
|
|
addressCards.forEach(card => {
|
|
card.addEventListener('mouseenter', function() {
|
|
this.style.transform = 'translateY(-2px)';
|
|
this.style.boxShadow = '0 4px 15px rgba(0,0,0,0.1)';
|
|
});
|
|
|
|
card.addEventListener('mouseleave', function() {
|
|
this.style.transform = 'translateY(0)';
|
|
this.style.boxShadow = '';
|
|
});
|
|
});
|
|
});
|