修复套餐选择后默认服务时长未带出的问题:1)使用dataset属性获取套餐数据;2)优化selectDuration函数的表单查找逻辑;3)添加调试日志以便排查问题
This commit is contained in:
+65
-21
@@ -798,17 +798,28 @@ try {
|
||||
|
||||
// 更新套餐信息
|
||||
function updatePackageInfo(submissionId) {
|
||||
console.log('updatePackageInfo called with submissionId:', submissionId);
|
||||
|
||||
const packageSelect = document.getElementById('selected_package_' + submissionId);
|
||||
if (!packageSelect) {
|
||||
console.error('Package select not found for submissionId:', submissionId);
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedOption = packageSelect.options[packageSelect.selectedIndex];
|
||||
const packageInfoDiv = document.getElementById('packageInfo_' + submissionId);
|
||||
const durationInput = document.getElementById('duration_' + submissionId);
|
||||
const totalPriceInput = document.getElementById('total_price_' + submissionId);
|
||||
|
||||
console.log('Selected option:', selectedOption, 'value:', selectedOption ? selectedOption.value : 'null');
|
||||
|
||||
if (selectedOption && selectedOption.value) {
|
||||
const packageId = parseInt(selectedOption.value);
|
||||
const duration = parseInt(selectedOption.getAttribute('data-duration'));
|
||||
const price = parseFloat(selectedOption.getAttribute('data-price'));
|
||||
const services = JSON.parse(selectedOption.getAttribute('data-services'));
|
||||
// 直接从selectedOption的data-duration属性获取时长
|
||||
const duration = parseInt(selectedOption.dataset.duration);
|
||||
const price = parseFloat(selectedOption.dataset.price);
|
||||
const services = JSON.parse(selectedOption.dataset.services);
|
||||
|
||||
console.log('Package data using dataset:', {duration, price});
|
||||
|
||||
// 更新套餐信息显示
|
||||
document.getElementById('packageName_' + submissionId).textContent = selectedOption.textContent;
|
||||
@@ -824,9 +835,17 @@ try {
|
||||
servicesContainer.innerHTML = '';
|
||||
}
|
||||
|
||||
// 更新时长和价格
|
||||
durationInput.value = duration;
|
||||
totalPriceInput.value = price.toFixed(2);
|
||||
// 直接更新时长输入框
|
||||
if (durationInput) {
|
||||
durationInput.value = duration;
|
||||
console.log('Directly updated duration input to:', duration);
|
||||
} else {
|
||||
console.error('Duration input not found for submissionId:', submissionId);
|
||||
}
|
||||
|
||||
if (totalPriceInput) {
|
||||
totalPriceInput.value = price.toFixed(2);
|
||||
}
|
||||
|
||||
// 更新快捷选择按钮状态
|
||||
selectDuration(submissionId, duration);
|
||||
@@ -839,31 +858,56 @@ try {
|
||||
|
||||
// 快捷选择服务时长
|
||||
function selectDuration(submissionId, minutes) {
|
||||
console.log('selectDuration called with submissionId:', submissionId, 'minutes:', minutes);
|
||||
|
||||
// 直接通过ID获取时长输入框
|
||||
const durationInput = document.getElementById('duration_' + submissionId);
|
||||
const customDurationInput = document.getElementById('customDuration_' + submissionId);
|
||||
|
||||
// 更新时长输入框
|
||||
durationInput.value = minutes;
|
||||
if (durationInput) {
|
||||
durationInput.value = minutes;
|
||||
console.log('selectDuration updated duration input to:', minutes);
|
||||
} else {
|
||||
console.error('Duration input not found in selectDuration for submissionId:', submissionId);
|
||||
}
|
||||
|
||||
// 更新自定义时长输入框
|
||||
if (customDurationInput) {
|
||||
customDurationInput.value = minutes;
|
||||
}
|
||||
|
||||
// 获取当前表单的所有时长按钮
|
||||
const form = document.getElementById('selected_package_' + submissionId).closest('form');
|
||||
const durationButtons = form.querySelectorAll('.duration-btn');
|
||||
|
||||
// 更新按钮选中状态
|
||||
durationButtons.forEach(btn => {
|
||||
// 使用data-duration属性来检查按钮对应的时长
|
||||
const btnDuration = parseInt(btn.getAttribute('data-duration'));
|
||||
if (btnDuration === minutes) {
|
||||
btn.classList.add('selected');
|
||||
} else {
|
||||
btn.classList.remove('selected');
|
||||
// 直接通过ID获取packageInfo元素,然后找到其父表单
|
||||
const packageInfo = document.getElementById('packageInfo_' + submissionId);
|
||||
let form;
|
||||
if (packageInfo) {
|
||||
form = packageInfo.closest('form');
|
||||
} else {
|
||||
// 如果找不到packageInfo,尝试通过packageSelect找到表单
|
||||
const packageSelect = document.getElementById('selected_package_' + submissionId);
|
||||
if (packageSelect) {
|
||||
form = packageSelect.closest('form');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('Found form:', form);
|
||||
|
||||
if (form) {
|
||||
// 获取表单内的所有时长按钮
|
||||
const durationButtons = form.querySelectorAll('.duration-btn');
|
||||
console.log('Found duration buttons:', durationButtons.length);
|
||||
|
||||
// 更新按钮选中状态
|
||||
durationButtons.forEach(btn => {
|
||||
const btnDuration = parseInt(btn.dataset.duration);
|
||||
if (btnDuration === minutes) {
|
||||
btn.classList.add('selected');
|
||||
console.log('Added selected class to button with duration:', btnDuration);
|
||||
} else {
|
||||
btn.classList.remove('selected');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 应用自定义时长
|
||||
|
||||
Reference in New Issue
Block a user