2025-03-20 04:41:04 +08:00

134 lines
5.4 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>
<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="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>
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 %}