143 lines
5.2 KiB
HTML
143 lines
5.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>库存系统 - 大盒列表</title>
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
|
</head>
|
|
<body>
|
|
<header class="hero">
|
|
<h1>电子元件库存管理 v1.0</h1>
|
|
<a class="btn" href="{{ url_for('scan_page') }}">扫码/搜索</a>
|
|
</header>
|
|
|
|
<main class="container">
|
|
<h2>容器列表</h2>
|
|
|
|
{% for key, meta in box_types.items() %}
|
|
<section class="group-panel panel" id="group-{{ key }}">
|
|
<div class="group-title-row">
|
|
<h3>{{ meta.label }}</h3>
|
|
<span class="group-desc">{{ meta.default_desc }}</span>
|
|
</div>
|
|
|
|
<form class="new-box-form" method="post" action="{{ url_for('create_box') }}">
|
|
<input type="hidden" name="box_type" value="{{ key }}">
|
|
<input type="text" name="name" placeholder="基础名称(自动拼范围)" required>
|
|
<input type="text" name="slot_prefix" placeholder="前缀(如A/B/C)">
|
|
<input type="number" name="start_number" min="0" value="1" placeholder="起始序号">
|
|
<input type="text" name="description" placeholder="备注(可选)">
|
|
<button class="btn btn-light suggest-start-btn" type="button" data-box-type="{{ key }}">建议起始号</button>
|
|
<button class="btn" type="submit">新增盒子</button>
|
|
<span class="hint suggest-preview"></span>
|
|
</form>
|
|
|
|
<section class="box-list">
|
|
{% for item in groups[key] %}
|
|
<article class="box-card">
|
|
<h4>{{ item.box.name }}</h4>
|
|
<p>{{ item.box.description or '暂无描述' }}</p>
|
|
<p>编号前缀: {{ item.box.slot_prefix }} | 范围: {{ item.slot_range }}</p>
|
|
<p>已启用: {{ item.used_count }}/{{ item.box.slot_capacity }}</p>
|
|
|
|
<div class="card-actions">
|
|
<a class="btn" href="{{ url_for('view_box', box_id=item.box.id) }}">进入列表</a>
|
|
<form method="post" action="{{ url_for('delete_box', box_id=item.box.id) }}" onsubmit="return confirm('确认删除盒子及内部全部记录吗?')">
|
|
<button class="btn btn-danger" type="submit">删除</button>
|
|
</form>
|
|
</div>
|
|
|
|
<details class="box-overview">
|
|
<summary>概览(已启用序号和名称)</summary>
|
|
{% if item.overview_rows %}
|
|
<ul>
|
|
{% for row in item.overview_rows %}
|
|
<li>{{ row.slot_code }} - {{ row.name }} ({{ row.part_no }})</li>
|
|
{% endfor %}
|
|
</ul>
|
|
{% else %}
|
|
<p>暂无启用记录</p>
|
|
{% endif %}
|
|
</details>
|
|
|
|
<details class="box-overview">
|
|
<summary>设置(改名/前缀/起始号)</summary>
|
|
<p class="hint">输入基础名称后,系统会自动生成: 基础名称 + 编号范围。</p>
|
|
<form class="new-box-form compact" method="post" action="{{ url_for('update_box', box_id=item.box.id) }}">
|
|
<input type="text" name="name" value="{{ item.base_name }}" required>
|
|
<input type="text" name="slot_prefix" value="{{ item.box.slot_prefix }}" required>
|
|
<input type="number" name="start_number" min="0" value="{{ item.box.start_number }}" required>
|
|
<input type="text" name="description" value="{{ item.box.description or '' }}">
|
|
<button class="btn btn-light suggest-start-btn" type="button" data-box-id="{{ item.box.id }}" data-box-type="{{ item.box.box_type }}">建议起始号</button>
|
|
<button class="btn" type="submit">保存设置</button>
|
|
<span class="hint suggest-preview"></span>
|
|
</form>
|
|
</details>
|
|
</article>
|
|
{% else %}
|
|
<p>当前分类还没有盒子,先新增一个。</p>
|
|
{% endfor %}
|
|
</section>
|
|
</section>
|
|
{% endfor %}
|
|
</main>
|
|
|
|
<script>
|
|
(function () {
|
|
function updateSuggest(form, payload) {
|
|
var startInput = form.querySelector('input[name="start_number"]');
|
|
var prefixInput = form.querySelector('input[name="slot_prefix"]');
|
|
var preview = form.querySelector('.suggest-preview');
|
|
|
|
if (startInput) {
|
|
startInput.value = payload.start_number;
|
|
}
|
|
if (prefixInput && !prefixInput.value.trim()) {
|
|
prefixInput.value = payload.slot_prefix;
|
|
}
|
|
if (preview) {
|
|
preview.textContent = '建议范围: ' + payload.preview_range;
|
|
}
|
|
}
|
|
|
|
document.querySelectorAll('.suggest-start-btn').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
var form = btn.closest('form');
|
|
if (!form) {
|
|
return;
|
|
}
|
|
|
|
var prefixInput = form.querySelector('input[name="slot_prefix"]');
|
|
var boxType = btn.dataset.boxType || 'small_28';
|
|
var boxId = btn.dataset.boxId || '';
|
|
var prefix = prefixInput ? prefixInput.value.trim() : '';
|
|
|
|
var params = new URLSearchParams();
|
|
params.set('box_type', boxType);
|
|
if (prefix) {
|
|
params.set('slot_prefix', prefix);
|
|
}
|
|
if (boxId) {
|
|
params.set('box_id', boxId);
|
|
}
|
|
|
|
fetch('{{ url_for('suggest_start') }}?' + params.toString())
|
|
.then(function (resp) { return resp.json(); })
|
|
.then(function (data) {
|
|
if (!data.ok) {
|
|
alert(data.message || '建议起始号失败');
|
|
return;
|
|
}
|
|
updateSuggest(form, data);
|
|
})
|
|
.catch(function () {
|
|
alert('建议起始号失败,请稍后重试');
|
|
});
|
|
});
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|