This commit is contained in:
邓智航
2026-01-18 16:51:28 +08:00
parent 0b71afea29
commit 5364edfc46
3 changed files with 1867 additions and 271 deletions

View File

@@ -294,39 +294,42 @@
<td width="60%" valign="top" class="layout-cell main-content">
<h2>库存列表 - 区域 A1</h2>
<form action="submit_filter">
<form id="searchForm" onsubmit="event.preventDefault(); handleSearch();">
<table border="0" width="100%" class="filter-table">
<tr>
<td>关键词: <input type="text" name="kw" size="30" placeholder="输入 ID 或名称"></td>
<td>关键词: <input type="text" id="searchInput" name="kw" size="30" placeholder="输入 ID 或名称"></td>
<td>
类型:
<select name="type">
<select id="typeSelect" name="type">
<option value="all">-- 所有 --</option>
<option value="res">电阻</option>
<option value="cap">电容</option>
<option value="ind">电感</option>
<option value="chip">芯片</option>
<option value="conn">连接器</option>
<option value="res">电阻 (Resistor)</option>
<option value="cap">电容 (Capacitor)</option>
<option value="ind">电感 (Inductor)</option>
<option value="chip">芯片 (Chip)</option>
<option value="conn">连接器 (Connector)</option>
<option value="other">其他 (Other)</option>
</select>
</td>
<td>
状态:
<label><input type="checkbox" name="st1" checked> 正常</label>
<label><input type="checkbox" name="st2"> 警告</label>
<label><input type="checkbox" name="st3"> 损坏</label>
<label><input type="checkbox" name="st_normal" value="NORMAL" checked> 正常</label>
<label><input type="checkbox" name="st_low" value="LOW" checked> 警告</label>
<label><input type="checkbox" name="st_crit" value="CRITICAL" checked> 严重</label>
</td>
</tr>
<tr>
<td colspan="3" style="padding-top:10px;">
高级选项:
<label><input type="radio" name="sort" value="date"> 按日期</label>
排序:
<label><input type="radio" name="sort" value="date" checked>更新日期</label>
<label><input type="radio" name="sort" value="id"> 按ID</label>
<label><input type="radio" name="sort" value="wt"></label>
<label><input type="radio" name="sort" value="pr"> 按优先级</label>
<label><input type="radio" name="sort" value="qty">库存</label>
<br><br>
<input type="submit" value="开始检索">
<input type="reset" value="重置条件">
<input type="button" value="导出Excel (不可用)" disabled style="background:#eee; color:#aaa; cursor:not-allowed;">
<button type="submit" class="page-btn active" style="padding:6px 20px;">
<span id="search-spinner" class="spinner" style="display:none; width:12px; height:12px; border-width:2px; vertical-align:middle; margin-right:5px;"></span>
开始检索
</button>
<button type="button" class="page-btn" onclick="resetSearch()">重置条件</button>
<button type="button" class="page-btn" disabled style="opacity:0.6; cursor:not-allowed;">导出Excel</button>
</td>
</tr>
</table>
@@ -735,6 +738,82 @@
// --- 导航与通用模态框 ---
// --- 搜索逻辑 ---
function handleSearch() {
const spinner = document.getElementById('search-spinner');
spinner.style.display = 'inline-block';
// 获取筛选条件
const kw = document.getElementById('searchInput').value.toLowerCase().trim();
const typeFilter = document.getElementById('typeSelect').value;
const checkedStatuses = [];
if(document.querySelector('input[name="st_normal"]').checked) checkedStatuses.push('NORMAL');
if(document.querySelector('input[name="st_low"]').checked) checkedStatuses.push('LOW');
if(document.querySelector('input[name="st_crit"]').checked) checkedStatuses.push('CRITICAL');
// 获取排序
const sortVal = document.querySelector('input[name="sort"]:checked').value;
// 模拟网络延迟
setTimeout(() => {
state.filteredData = state.data.filter(item => {
// 1. 关键词匹配 (ID, Name, Supplier, Batch)
const matchKw = !kw ||
item.id.toLowerCase().includes(kw) ||
item.name.toLowerCase().includes(kw) ||
item.supplier.toLowerCase().includes(kw) ||
item.batch.toLowerCase().includes(kw);
// 2. 类型匹配 (简单的字符串包含判断)
let matchType = true;
if (typeFilter !== 'all') {
if (typeFilter === 'res') matchType = item.name.includes('Resistor');
else if (typeFilter === 'cap') matchType = item.name.includes('Capacitor');
else if (typeFilter === 'ind') matchType = item.name.includes('Inductor');
else if (typeFilter === 'chip') matchType = item.name.includes('MCU') || item.name.includes('Regulator') || item.name.includes('Transistor') || item.name.includes('Diode');
else if (typeFilter === 'conn') matchType = item.name.includes('Connector') || item.name.includes('Header');
else if (typeFilter === 'other') matchType = !item.name.includes('Resist') && !item.name.includes('Capacit') && !item.name.includes('Induct') && !item.name.includes('Connect');
}
// 3. 状态匹配 (注意: 之前生成的 Mock Status 包含 DAMAGED/PENDING但Checkbox只有三种需兼容)
// 这里只筛选三种主要显示状态,如果用户没选也没事
let matchStatus = false;
if (checkedStatuses.length === 0) matchStatus = true; // 如果全不选,默认全显示?或者全不显示?通常全不选意味着什么都不看,或者看全部...
// 为了用户体验,全不选就当全选吧 (或者严谨点就是空)
// 这里逻辑只要item.status在checkedStatuses里就显示
// 特殊处理: CRITICAL 包含了 Mock 里的 CRITICAL 和 DAMAGED (假设)
if (checkedStatuses.includes(item.status)) matchStatus = true;
// 修正逻辑如果勾选了CRITICAL我们把DAMAGED也算进去?
if (checkedStatuses.includes('CRITICAL') && item.status === 'DAMAGED') matchStatus = true;
return matchKw && matchType && matchStatus;
});
// 排序
if (sortVal === 'id') {
state.filteredData.sort((a,b) => a.id.localeCompare(b.id));
} else if (sortVal === 'qty') {
state.filteredData.sort((a,b) => b.qty - a.qty); // Fixed: property name is qty
} else if (sortVal === 'date') {
state.filteredData.sort((a,b) => new Date(b.date) - new Date(a.date));
}
state.currentPage = 1;
renderTable();
spinner.style.display = 'none';
showToast(`检索完成,找到 ${state.filteredData.length} 条记录`, 'success');
}, 400);
}
function resetSearch() {
document.getElementById('searchInput').value = '';
document.getElementById('typeSelect').value = 'all';
document.querySelectorAll('input[type="checkbox"]').forEach(c => c.checked = true);
document.querySelector('input[value="date"]').checked = true;
handleSearch();
}
function openModal(id) {
const modal = document.getElementById(id);
if (modal) {