2025-03-20 13:21:31 +08:00

176 lines
6.5 KiB
HTML

{% extends "base.html" %}
{% block title %}台桌管理{% endblock %}
{% block content %}
<body>
<div class="container mt-4">
<h1>桌台列表</h1>
<a href="{{ url_for('tables.add_table') }}" class="btn btn-primary mb-3">添加桌台</a>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>桌号</th>
<th>容量</th>
<th>收款策略</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for table in tables %}
<tr>
<td>{{ table.table_id }}</td>
<td>{{ table.game_table_number }}</td>
<td>{{ table.capacity }}</td>
<td>{{ table.strategy_name }}</td>
<td>
<a href="{{ url_for('tables.edit_table', table_id=table.table_id) }}"
class="btn btn-warning btn-sm">编辑</a>
<button class="btn btn-sm btn-info"
onclick="showQRCode({{ table.table_id }}, '{{ table.game_table_number }}')">
生成二维码
</button>
<form action="{{ url_for('tables.delete_table', table_id=table.table_id) }}" method="post"
class="d-inline">
<button type="submit" class="btn btn-danger btn-sm"
onclick="return confirm('确认删除该桌台吗?')">删除
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="modal fade" id="qrcodeModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">桌台二维码 - 桌号<span id="tableNumber"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body text-center">
<img id="qrcodeImage" class="img-fluid mb-3" style="max-width: 300px;">
<div>
<button class="btn btn-primary" onclick="downloadQRCode()">下载二维码</button>
</div>
</div>
</div>
</div>
</div>
<!-- 选择策略模态框 -->
<div class="modal fade" id="selectStrategyModal" tabindex="-1" aria-labelledby="selectStrategyModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="selectStrategyModalLabel">选择收款策略</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form onsubmit="selectStrategy(event)">
<input type="hidden" id="selectedTableId">
<div class="modal-body">
<div class="form-group">
<label for="strategySelect">收款策略</label>
<select class="form-control" id="strategySelect" required>
<!-- 动态填充策略选项 -->
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
<button type="submit" class="btn btn-primary">保存</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function showQRCode(tableId, tableNumber) {
fetch(`/tables/qrcode/${tableId}`)
.then(res => res.json())
.then(data => {
if (data.image) {
document.getElementById('qrcodeImage').src = data.image;
document.getElementById('tableNumber').textContent = tableNumber;
new bootstrap.Modal(document.getElementById('qrcodeModal')).show();
}
});
}
function downloadQRCode() {
const link = document.createElement('a');
link.download = `桌台二维码-${document.getElementById('tableNumber').textContent}.png`;
link.href = document.getElementById('qrcodeImage').src;
link.click();
}
async function openSelectStrategyModal(tableId) {
try {
const token = "{{ session['token'] }}";
const response = await fetch('/admin/strategies/list', {
headers: {
'Authorization': `Bearer ${token}`
}
});
const strategies = await response.json();
const strategySelect = document.getElementById('strategySelect');
strategySelect.innerHTML = '';
strategies.forEach(strategy => {
const option = document.createElement('option');
option.value = strategy.strategy_id;
option.textContent = strategy.strategy_name;
strategySelect.appendChild(option);
});
document.getElementById('selectedTableId').value = tableId;
const myModal = new bootstrap.Modal(document.getElementById('selectStrategyModal'));
myModal.show();
} catch (error) {
console.error('获取策略列表失败:', error);
}
}
async function selectStrategy(event) {
event.preventDefault();
const tableId = document.getElementById('selectedTableId').value;
const strategyId = document.getElementById('strategySelect').value;
const token = "{{ session['token'] }}";
try {
const response = await fetch(`/admin/tables/${tableId}/strategy`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
strategy_id: strategyId
})
});
if (response.ok) {
const myModal = bootstrap.Modal.getInstance(document.getElementById('selectStrategyModal'));
myModal.hide();
location.reload();
} else {
const error = await response.json();
alert(`更新失败: ${error.detail}`);
}
} catch (error) {
console.error('更新策略失败:', error);
}
}
</script>
</body>
{% endblock %}