feat(预约系统): 添加套餐专属预约信息功能并优化复制逻辑
- 在SQL查询中添加package_reminder字段 - 重构复制按钮使用data属性存储预约信息 - 实现套餐专属预约信息的单独保存功能 - 优化复制功能以包含套餐专属提醒信息 - 添加套餐专属预约信息的实时编辑功能
This commit is contained in:
+74
-10
@@ -27,9 +27,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$base_duration = (int)$_POST['base_duration'];
|
||||
$price = (float)$_POST['price'];
|
||||
$services = implode(',', array_filter(array_map('trim', $_POST['services'] ?? [])));
|
||||
$package_reminder = trim($_POST['package_reminder']);
|
||||
$is_active = isset($_POST['is_active']) ? 1 : 0;
|
||||
|
||||
// 获取当前套餐的专属预约信息,避免更新时丢失
|
||||
$stmt = $pdo->prepare("SELECT package_reminder FROM packages WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$current_package = $stmt->fetch();
|
||||
$package_reminder = $current_package['package_reminder'] ?? '';
|
||||
|
||||
// 更新套餐信息,保留现有的package_reminder
|
||||
$stmt = $pdo->prepare("UPDATE packages SET package_name = ?, description = ?, base_duration = ?, price = ?, services = ?, package_reminder = ?, is_active = ? WHERE id = ?");
|
||||
$stmt->execute([$package_name, $description, $base_duration, $price, $services, $package_reminder, $is_active, $id]);
|
||||
$message = "套餐更新成功!";
|
||||
@@ -39,6 +45,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$stmt = $pdo->prepare("DELETE FROM packages WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$message = "套餐删除成功!";
|
||||
} elseif ($action === 'update_reminder') {
|
||||
// 处理套餐专属预约信息的单独更新
|
||||
$id = (int)$_POST['id'];
|
||||
$package_reminder = trim($_POST['package_reminder']);
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE packages SET package_reminder = ? WHERE id = ?");
|
||||
$stmt->execute([$package_reminder, $id]);
|
||||
|
||||
// 返回JSON响应
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['success' => true, 'message' => '套餐专属预约信息更新成功!']);
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$message = "操作失败:" . $e->getMessage();
|
||||
@@ -207,12 +225,14 @@ $packages = $stmt->fetchAll();
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($package['package_reminder'])): ?>
|
||||
<div class="package-reminder" style="margin-top: 12px; padding: 12px; background: #f8f9fa; border-radius: 4px; border-left: 4px solid #1890ff;">
|
||||
<div class="detail-label" style="font-weight: 600; margin-bottom: 8px; color: #333;">套餐专属预约信息</div>
|
||||
<div class="reminder-content" style="font-size: 14px; color: #666; line-height: 1.5;"><?= nl2br(htmlspecialchars($package['package_reminder'])) ?></div>
|
||||
<div class="package-reminder" style="margin-top: 12px; padding: 12px; background: #f8f9fa; border-radius: 4px; border-left: 4px solid #1890ff;">
|
||||
<div class="detail-label" style="font-weight: 600; margin-bottom: 8px; color: #333;">套餐专属预约信息</div>
|
||||
<textarea class="reminder-editor" data-package-id="<?= $package['id'] ?>" oninput="autoResizeTextarea(this)" style="width: 100%; padding: 10px; background: white; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; line-height: 1.5; min-height: 100px; resize: none; overflow: hidden;" placeholder="输入此套餐的专属预约信息,将在预约确认时显示"><?= htmlspecialchars($package['package_reminder'] ?? '') ?></textarea>
|
||||
<div class="reminder-actions" style="margin-top: 8px; text-align: right;">
|
||||
<button class="btn-primary btn-sm" onclick="saveReminder(this)">保存</button>
|
||||
<button class="btn-outline btn-sm" onclick="cancelEdit(this)">取消</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="package-actions">
|
||||
<button class="btn-primary btn-sm" onclick="editPackage(<?= $package['id'] ?>)"><span>✏️ 编辑</span></button>
|
||||
@@ -278,10 +298,7 @@ $packages = $stmt->fetchAll();
|
||||
<button type="button" class="btn-outline btn-sm" onclick="addService()" style="padding: 6px 12px; background: white; color: #1890ff; border: 1px solid #1890ff; border-radius: 4px; font-size: 12px; cursor: pointer;"><span>+ 添加服务项目</span></button>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-bottom: 16px;">
|
||||
<label for="package_reminder" style="display: block; font-weight: 600; margin-bottom: 6px; color: #333;">套餐专属预约信息</label>
|
||||
<textarea id="package_reminder" name="package_reminder" rows="4" placeholder="输入此套餐的专属预约信息,将在预约确认时显示" class="form-control" style="width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; resize: vertical;"><?= htmlspecialchars($package['package_reminder'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<!-- 套餐专属预约信息编辑已移至套餐列表直接编辑 -->
|
||||
|
||||
<div class="form-group" style="margin-bottom: 16px;">
|
||||
<label class="checkbox-label" style="display: flex; align-items: center; cursor: pointer;">
|
||||
@@ -362,5 +379,52 @@ $packages = $stmt->fetchAll();
|
||||
document.body.classList.add('mobile-device');
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
// 自适应文本框高度
|
||||
function autoResizeTextarea(textarea) {
|
||||
// 重置高度以获取正确的滚动高度
|
||||
textarea.style.height = 'auto';
|
||||
// 设置新高度(加上一些内边距的补偿)
|
||||
textarea.style.height = Math.min(textarea.scrollHeight + 10, 500) + 'px';
|
||||
}
|
||||
|
||||
// 页面加载时初始化所有文本框高度
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
const textareas = document.querySelectorAll('.reminder-editor');
|
||||
textareas.forEach(autoResizeTextarea);
|
||||
});
|
||||
|
||||
// 保存套餐专属预约信息
|
||||
function saveReminder(button) {
|
||||
const textarea = button.closest('.package-reminder').querySelector('.reminder-editor');
|
||||
const packageId = textarea.dataset.packageId;
|
||||
const reminderText = textarea.value.trim();
|
||||
|
||||
// 创建保存请求
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', 'packages.php', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
alert('保存成功!');
|
||||
// 可以选择刷新页面或更新UI
|
||||
} else {
|
||||
alert('保存失败,请重试!');
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(`action=update_reminder&id=${packageId}&package_reminder=${encodeURIComponent(reminderText)}`);
|
||||
}
|
||||
|
||||
// 取消编辑
|
||||
function cancelEdit(button) {
|
||||
const textarea = button.closest('.package-reminder').querySelector('.reminder-editor');
|
||||
const packageId = textarea.dataset.packageId;
|
||||
|
||||
// 可以选择恢复原始值或不做处理
|
||||
textarea.blur();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user