359 lines
17 KiB
Plaintext
Executable File
359 lines
17 KiB
Plaintext
Executable File
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>交付物料风险明细</title>
|
||
<link rel="stylesheet" href="../common/nav.css">
|
||
<link rel="stylesheet" href="../common/grid.css">
|
||
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
|
||
<style>
|
||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||
body { font-family: 'Microsoft YaHei','PingFang SC',sans-serif; background: #f3f5fa; color: #2c3e50; padding: 14px 18px; }
|
||
|
||
.head { display: flex; align-items: center; margin-bottom: 12px; gap: 12px; }
|
||
.head h2 { font-size: 20px; }
|
||
.head .back { padding: 6px 14px; background: #fff; border: 1px solid #dcdfe6; border-radius: 6px; cursor: pointer; font-size: 13px; }
|
||
.head .back:hover { border-color: #409eff; color: #409eff; }
|
||
.head .meta { font-size: 13px; color: #909399; margin-left: auto; }
|
||
|
||
.filter { background: #fff; border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
|
||
.filter span { font-size: 13px; color: #606266; }
|
||
.filter input, .filter select { height: 30px; padding: 0 10px; border: 1px solid #dcdfe6; border-radius: 6px; font-size: 13px; outline: none; background: #fff; }
|
||
.filter input { width: 220px; }
|
||
.filter input:focus, .filter select:focus { border-color: #409eff; }
|
||
.filter button { height: 30px; padding: 0 14px; border: 1px solid #409eff; background: #409eff; color: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
|
||
.filter button:hover { background: #66b1ff; border-color: #66b1ff; }
|
||
.filter button.gray { background: #fff; color: #606266; border-color: #dcdfe6; }
|
||
.filter button.gray:hover { border-color: #409eff; color: #409eff; }
|
||
.filter .spacer { flex: 1; }
|
||
.filter .count { font-size: 12px; color: #909399; }
|
||
.filter button.export { background: linear-gradient(135deg,#34a853,#1e8e3e); border-color: #34a853; }
|
||
.filter button.export:hover { opacity: .9; background: #34a853; border-color: #34a853; }
|
||
|
||
.loading, .empty { text-align: center; padding: 60px 0; color: #909399; font-size: 14px; }
|
||
|
||
.pagination { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #fff; border-radius: 0 0 10px 10px; }
|
||
.pagination .info { font-size: 12px; color: #909399; }
|
||
.pagination .ctrl { display: flex; align-items: center; gap: 6px; }
|
||
.pagination button { height: 28px; min-width: 32px; padding: 0 8px; border: 1px solid #dcdfe6; background: #fff; border-radius: 4px; cursor: pointer; font-size: 12px; }
|
||
.pagination button:hover { border-color: #409eff; color: #409eff; }
|
||
.pagination button.active { background: #409eff; color: #fff; border-color: #409eff; }
|
||
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
|
||
.pagination span { font-size: 12px; color: #909399; }
|
||
.pagination select { height: 28px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 6px; font-size: 12px; }
|
||
.pagination input { width: 50px; height: 28px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 6px; text-align: center; font-size: 12px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<div id="sidebar"></div>
|
||
|
||
<div class="head">
|
||
<button class="back" onclick="window.location.href='delivery_dashboard.html'">← 返回看板</button>
|
||
<h2 id="pageTitle">物料明细</h2>
|
||
<span class="meta" id="metaInfo"></span>
|
||
</div>
|
||
|
||
<div class="filter">
|
||
<span>产品类型:</span>
|
||
<select id="filterProductType"><option value="">全部</option></select>
|
||
<span>风险:</span>
|
||
<select id="filterRisk">
|
||
<option value="">全部</option>
|
||
<option value="断线">断线</option>
|
||
<option value="预警">预警</option>
|
||
<option value="安全">安全</option>
|
||
</select>
|
||
<span>供应商:</span>
|
||
<select id="filterSupplier"><option value="">全部</option></select>
|
||
<span>采购员:</span>
|
||
<select id="filterPurchaser"><option value="">全部</option></select>
|
||
<input type="text" id="filterKeyword" placeholder="搜索物料编码/名称/产品编码" />
|
||
<button onclick="loadData(1)">查询</button>
|
||
<button class="gray" onclick="resetFilter()">重置</button>
|
||
<div class="spacer"></div>
|
||
<button class="export" onclick="exportExcel()">导出Excel</button>
|
||
<span class="count" id="countInfo"></span>
|
||
</div>
|
||
|
||
<div class="gx-grid" id="grid">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th style="width:48px">序号</th>
|
||
<th style="width:110px">物料编码</th>
|
||
<th style="width:140px">物料名称</th>
|
||
<th style="width:90px">产品类型</th>
|
||
<th style="width:140px">供应商</th>
|
||
<th style="width:100px">采购员</th>
|
||
<th style="width:100px">预计停线日</th>
|
||
<th style="width:100px">预计到货日</th>
|
||
<th style="width:60px">风险</th>
|
||
<th style="width:60px">日需求</th>
|
||
<th style="width:75px">震泽库存</th>
|
||
<th style="width:75px">晋江库存</th>
|
||
<th style="width:75px">资阳库存</th>
|
||
<th style="width:75px">可用库存</th>
|
||
<th style="width:70px">量产在途</th>
|
||
<th style="width:70px">研发在途</th>
|
||
<th style="width:70px">线边库存</th>
|
||
<th style="width:70px">已收货</th>
|
||
<th style="width:80px">库存</th>
|
||
<th style="width:80px">在途</th>
|
||
<th style="width:90px">到货计划</th>
|
||
<th style="width:140px">备注</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="tbody"></tbody>
|
||
</table>
|
||
<div id="status" class="loading">加载中...</div>
|
||
</div>
|
||
|
||
<div class="pagination">
|
||
<div class="info" id="pageInfo">共 0 条</div>
|
||
<div class="ctrl">
|
||
<span>每页</span>
|
||
<select id="pageSize" onchange="loadData(1)">
|
||
<option value="20">20</option>
|
||
<option value="50" selected>50</option>
|
||
<option value="100">100</option>
|
||
<option value="200">200</option>
|
||
<option value="500">500</option>
|
||
</select>
|
||
<span>条</span>
|
||
<button onclick="goPage(1)">«</button>
|
||
<button onclick="prevPage()">‹ 上一页</button>
|
||
<span>第 <input type="text" id="curPage" value="1" /> / <span id="totalPages">1</span> 页</span>
|
||
<button onclick="nextPage()">下一页 ›</button>
|
||
<button onclick="goPage(-1)">»</button>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
const API_BASE = '../../api/Deliver';
|
||
let currentPage = 1;
|
||
let currentTotal = 0;
|
||
let currentPageSize = 50;
|
||
let initRisk = '';
|
||
let initProductType = '';
|
||
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
initRisk = urlParams.get('risk') || '';
|
||
initProductType = urlParams.get('productType') || '';
|
||
|
||
const titleMap = { '': '全部物料', '断线': '断线风险物料', '预警': '预警关注物料', '安全': '安全供应物料' };
|
||
const titleColorMap = { '': '#303133', '断线': '#f56c6c', '预警': '#e6a23c', '安全': '#67c23a' };
|
||
document.getElementById('pageTitle').textContent = titleMap[initRisk] || '物料明细';
|
||
document.getElementById('pageTitle').style.color = titleColorMap[initRisk] || '#303133';
|
||
document.getElementById('filterRisk').value = initRisk;
|
||
|
||
function num(v) { return Grid.num(v); }
|
||
|
||
function loadFilterOptions() {
|
||
// 产品类型
|
||
fetch(API_BASE + '/GetSchedules?keyword=').then(r => r.json()).then(res => {
|
||
if (res.success) {
|
||
const sel = document.getElementById('filterProductType');
|
||
const set = new Set();
|
||
res.data.forEach(s => { if (s.ProductType) set.add(s.ProductType); });
|
||
[...set].sort().forEach(t => {
|
||
const opt = document.createElement('option');
|
||
opt.value = t; opt.textContent = t;
|
||
sel.appendChild(opt);
|
||
});
|
||
sel.value = initProductType;
|
||
}
|
||
});
|
||
// 供应商/采购员(从当前列表数据汇总,所以首次加载完成后再调用)
|
||
}
|
||
|
||
function loadData(page) {
|
||
if (page) currentPage = page;
|
||
const tbody = document.getElementById('tbody');
|
||
const status = document.getElementById('status');
|
||
tbody.innerHTML = '';
|
||
status.className = 'loading';
|
||
status.style.display = 'block';
|
||
status.textContent = '加载中...';
|
||
|
||
currentPageSize = parseInt(document.getElementById('pageSize').value) || 50;
|
||
const risk = document.getElementById('filterRisk').value;
|
||
const productType = document.getElementById('filterProductType').value;
|
||
const supplier = document.getElementById('filterSupplier').value;
|
||
const purchaser = document.getElementById('filterPurchaser').value;
|
||
const keyword = document.getElementById('filterKeyword').value.trim();
|
||
|
||
const params = new URLSearchParams();
|
||
if (risk) params.append('risk', risk);
|
||
if (productType) params.append('productType', productType);
|
||
if (supplier) params.append('supplier', supplier);
|
||
if (purchaser) params.append('purchaser', purchaser);
|
||
if (keyword) params.append('keyword', keyword);
|
||
params.append('page', currentPage);
|
||
params.append('pageSize', currentPageSize);
|
||
|
||
fetch(API_BASE + '/GetBoardRiskList?' + params).then(r => r.json()).then(res => {
|
||
if (!res.success) {
|
||
status.className = 'empty';
|
||
status.textContent = '加载失败:' + (res.message || '');
|
||
return;
|
||
}
|
||
currentTotal = res.total || 0;
|
||
document.getElementById('curPage').value = currentPage;
|
||
const totalPages = Math.max(1, Math.ceil(currentTotal / currentPageSize));
|
||
document.getElementById('totalPages').textContent = totalPages;
|
||
document.getElementById('pageInfo').textContent = '共 ' + currentTotal + ' 条';
|
||
document.getElementById('countInfo').textContent = '当前显示 ' + ((currentPage-1)*currentPageSize+1) + ' - ' + Math.min(currentPage*currentPageSize, currentTotal) + ' 条';
|
||
if (res.data.length === 0) {
|
||
status.className = 'empty';
|
||
status.textContent = '无数据';
|
||
tbody.innerHTML = '';
|
||
return;
|
||
}
|
||
status.style.display = 'none';
|
||
tbody.innerHTML = res.data.map((m, i) => {
|
||
const seqNo = (currentPage - 1) * currentPageSize + i + 1;
|
||
return `<tr>
|
||
<td>${seqNo}</td>
|
||
<td title="${m.ChildMaterialId}"><strong>${m.ChildMaterialId}</strong></td>
|
||
<td title="${m.MaterialName || ''}">${m.MaterialName || '<span class="muted">-</span>'}</td>
|
||
<td>${m.ProductType || '<span class="muted">-</span>'}</td>
|
||
<td title="${m.Supplier || ''}">${m.Supplier || '<span class="muted">-</span>'}</td>
|
||
<td>${m.Purchaser || '<span class="muted">-</span>'}</td>
|
||
<td>${m.ExpectedStopDate || '<span class="muted">-</span>'}</td>
|
||
<td>${m.ExpectedArrivalDate || '<span class="muted">-</span>'}</td>
|
||
<td>${Grid.riskTag(m.DeliveryRisk)}</td>
|
||
<td>${num(m.DailyRequirement)}</td>
|
||
<td>${num(m.ZhenZeStock)}</td>
|
||
<td>${num(m.JinJiangStock)}</td>
|
||
<td>${num(m.ZiYangStock)}</td>
|
||
<td>${num(m.AvailableStock)}</td>
|
||
<td>${num(m.MassInTransit)}</td>
|
||
<td>${num(m.ResearchInTransit)}</td>
|
||
<td>${num(m.LineSideStock)}</td>
|
||
<td>${num(m.ReceivedQty)}</td>
|
||
<td>${num(m.StockQty)}</td>
|
||
<td>${num(m.InTransitQty)}</td>
|
||
<td>${num(m.ArrivalPlanQty)}</td>
|
||
<td title="${m.Remark || ''}">${m.Remark || '<span class="muted">-</span>'}</td>
|
||
</tr>`;
|
||
}).join('');
|
||
|
||
// 加载完后更新供应商/采购员下拉(用本次数据)
|
||
refreshDropdowns(res.data);
|
||
});
|
||
}
|
||
|
||
function refreshDropdowns(data) {
|
||
const supplierSet = new Set();
|
||
const purchaserSet = new Set();
|
||
data.forEach(m => { if (m.Supplier) supplierSet.add(m.Supplier); if (m.Purchaser) purchaserSet.add(m.Purchaser); });
|
||
const currentSupplier = document.getElementById('filterSupplier').value;
|
||
const currentPurchaser = document.getElementById('filterPurchaser').value;
|
||
const supplierSel = document.getElementById('filterSupplier');
|
||
const purchaserSel = document.getElementById('filterPurchaser');
|
||
// 保留当前选中
|
||
supplierSel.innerHTML = '<option value="">全部</option>';
|
||
purchaserSel.innerHTML = '<option value="">全部</option>';
|
||
[...supplierSet].sort().forEach(v => {
|
||
const opt = document.createElement('option'); opt.value = v; opt.textContent = v; supplierSel.appendChild(opt);
|
||
});
|
||
[...purchaserSet].sort().forEach(v => {
|
||
const opt = document.createElement('option'); opt.value = v; opt.textContent = v; purchaserSel.appendChild(opt);
|
||
});
|
||
supplierSel.value = currentSupplier;
|
||
purchaserSel.value = currentPurchaser;
|
||
}
|
||
|
||
function prevPage() { if (currentPage > 1) loadData(currentPage - 1); }
|
||
function nextPage() {
|
||
const totalPages = Math.max(1, Math.ceil(currentTotal / currentPageSize));
|
||
if (currentPage < totalPages) loadData(currentPage + 1);
|
||
}
|
||
function goPage(p) {
|
||
const totalPages = Math.max(1, Math.ceil(currentTotal / currentPageSize));
|
||
if (p === -1) loadData(totalPages);
|
||
else if (p === 1) loadData(1);
|
||
else {
|
||
const v = parseInt(document.getElementById('curPage').value);
|
||
if (!isNaN(v) && v >= 1 && v <= totalPages) loadData(v);
|
||
}
|
||
}
|
||
|
||
function resetFilter() {
|
||
document.getElementById('filterRisk').value = initRisk;
|
||
document.getElementById('filterProductType').value = initProductType;
|
||
document.getElementById('filterSupplier').value = '';
|
||
document.getElementById('filterPurchaser').value = '';
|
||
document.getElementById('filterKeyword').value = '';
|
||
document.getElementById('pageSize').value = '50';
|
||
loadData(1);
|
||
}
|
||
|
||
// ===== 导出Excel =====
|
||
const exportHeaders = ['序号','物料编码','物料名称','产品类型','供应商','采购员','预计停线日','预计到货日','风险','日需求','震泽库存','晋江库存','资阳库存','可用库存','量产在途','研发在途','线边库存','已收货','库存','在途','到货计划','备注'];
|
||
const exportKeys = ['','ChildMaterialId','MaterialName','ProductType','Supplier','Purchaser','ExpectedStopDate','ExpectedArrivalDate','DeliveryRisk','DailyRequirement','ZhenZeStock','JinJiangStock','ZiYangStock','AvailableStock','MassInTransit','ResearchInTransit','LineSideStock','ReceivedQty','StockQty','InTransitQty','ArrivalPlanQty','Remark'];
|
||
|
||
function exportExcel() {
|
||
const risk = document.getElementById('filterRisk').value;
|
||
const productType = document.getElementById('filterProductType').value;
|
||
const supplier = document.getElementById('filterSupplier').value;
|
||
const purchaser = document.getElementById('filterPurchaser').value;
|
||
const keyword = document.getElementById('filterKeyword').value.trim();
|
||
const params = new URLSearchParams();
|
||
if (risk) params.append('risk', risk);
|
||
if (productType) params.append('productType', productType);
|
||
if (supplier) params.append('supplier', supplier);
|
||
if (purchaser) params.append('purchaser', purchaser);
|
||
if (keyword) params.append('keyword', keyword);
|
||
params.append('page', 1);
|
||
params.append('pageSize', 100000);
|
||
|
||
const btn = document.querySelector('.filter button.export');
|
||
const oldText = btn.textContent;
|
||
btn.textContent = '导出中...';
|
||
btn.disabled = true;
|
||
fetch(API_BASE + '/GetBoardRiskList?' + params).then(r => r.json()).then(res => {
|
||
btn.textContent = oldText;
|
||
btn.disabled = false;
|
||
if (!res.success) { alert('导出失败:' + (res.message || '未知错误')); return; }
|
||
const rows = res.data || [];
|
||
if (!rows.length) { alert('当前条件下没有可导出的数据'); return; }
|
||
|
||
const data = [exportHeaders];
|
||
rows.forEach((m, i) => {
|
||
const row = [i + 1];
|
||
for (let k = 1; k < exportKeys.length; k++) row.push(m[exportKeys[k]] == null ? '' : m[exportKeys[k]]);
|
||
data.push(row);
|
||
});
|
||
const wscols = exportHeaders.map((h, i) => {
|
||
let max = i === 0 ? Math.max(h.length, String(rows.length).length) : h.length;
|
||
rows.forEach(r => { const v = String(r[exportKeys[i]] || ''); if (v.length > max) max = v.length; });
|
||
return { wch: Math.min(max + 2, 40) };
|
||
});
|
||
const ws = XLSX.utils.aoa_to_sheet(data);
|
||
ws['!cols'] = wscols;
|
||
const wb = XLSX.utils.book_new();
|
||
XLSX.utils.book_append_sheet(wb, ws, '交付物料风险明细');
|
||
const riskName = ({'': '全部', '断线': '断线', '预警': '预警', '安全': '安全'})[risk] || '';
|
||
XLSX.writeFile(wb, '交付物料风险明细' + riskName + '_' + new Date().toISOString().slice(0, 10) + '.xlsx');
|
||
}).catch(() => {
|
||
btn.textContent = oldText;
|
||
btn.disabled = false;
|
||
alert('导出失败:网络错误');
|
||
});
|
||
}
|
||
|
||
document.getElementById('curPage').addEventListener('keydown', e => { if (e.key === 'Enter') goPage(0); });
|
||
document.getElementById('filterKeyword').addEventListener('keydown', e => { if (e.key === 'Enter') loadData(1); });
|
||
|
||
loadFilterOptions();
|
||
loadData(1);
|
||
setTimeout(() => Grid.bind('grid'), 200);
|
||
</script>
|
||
<!-- 公共组件 -->
|
||
<script src="../common/grid.js"></script>
|
||
<script src="../common/nav.js"></script>
|
||
</body>
|
||
</html>
|