baseline: 小军 WMS 二开代码原始快照(含 SynOABusiness.cs Debugger.Break)

This commit is contained in:
Gaussian committed 2026-11-06 18:38:38 +08:00
commit c2b0e7be0d
6522 files changed
+3530643

No files matched your search

@@ -0,0 +1,322 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>产品BOM主数据维护</title>
<!-- 公共侧边栏组件 -->
<link rel="stylesheet" href="../common/nav.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
.top-bar{background:linear-gradient(135deg,#1a73e8,#1557b0);color:#fff;padding:0 24px;display:flex;align-items:center;height:56px;box-shadow:0 2px 8px rgba(0,0,0,.15);position:sticky;top:0;z-index:100}
.top-bar .logo{font-size:18px;font-weight:600;letter-spacing:1px;margin-right:32px}
.top-bar .nav-tabs{display:flex;gap:4px;height:100%}
.top-bar .nav-tabs a{color:rgba(255,255,255,.75);text-decoration:none;padding:0 16px;display:flex;align-items:center;font-size:13px;border-radius:4px 4px 0 0;transition:all .2s}
.top-bar .nav-tabs a:hover{color:#fff;background:rgba(255,255,255,.1)}
.top-bar .nav-tabs a.active{color:#fff;background:rgba(255,255,255,.2)}
.top-bar .user-info{margin-left:auto;font-size:13px;opacity:.85}
.main-container{max-width:1500px;margin:0 auto;padding:16px 20px}
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:12px}
.toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
.toolbar input,.toolbar select{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.toolbar input:focus,.toolbar select:focus{border-color:#1a73e8}
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff}
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
.btn-primary:hover{opacity:.92}
.btn-green{background:#22c55e}
.btn-green:hover{opacity:.92}
.btn-orange{background:#f59e0b}
.btn-orange:hover{opacity:.92}
.btn-red{background:#ef4444}
.btn-red:hover{opacity:.92}
.btn-outline{background:#fff;color:#666;border:2px solid #e0e0e0}
.btn-outline:hover{border-color:#1a73e8;color:#1a73e8}
table{width:100%;border-collapse:collapse;font-size:13px}
thead th{background:#f8f9fa;color:#555;font-weight:600;padding:9px 12px;text-align:left;border:1px solid #999;border-bottom:2px solid #999;white-space:nowrap}
tbody td{padding:9px 12px;border:1px solid #ddd;color:#333}
tbody tr:hover{background:#f0f6ff}
.badge{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:500}
.badge-success{background:#dcfce7;color:#166534}
.badge-muted{background:#f1f5f9;color:#64748b}
.modal-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:999;justify-content:center;align-items:center;padding:24px}
body.with-sidebar:not(.sidebar-collapsed) .modal-overlay{padding-left:240px}
body.with-sidebar.sidebar-collapsed .modal-overlay{padding-left:60px}
.modal-overlay.show{display:flex}
.modal{background:#fff;border-radius:10px;width:560px;max-width:95vw;max-height:90vh;overflow-y:auto;box-shadow:0 20px 60px rgba(0,0,0,.2);padding:24px}
.modal h3{font-size:17px;color:#333;margin-bottom:16px}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.form-group{display:flex;flex-direction:column}
.form-group.full{grid-column:1/-1}
.form-group label{font-size:12px;color:#555;font-weight:600;margin-bottom:4px}
.form-group input,.form-group select{height:34px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.form-group input:focus,.form-group select:focus{border-color:#1a73e8}
.form-group input.readonly{background:#f8f9fa;color:#999}
.modal-actions{display:flex;gap:8px;justify-content:flex-end;margin-top:18px}
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
.detail-table{max-height:60vh;overflow-y:auto}
.expand-btn{cursor:pointer;color:#1a73e8;font-weight:600}
/* 列表分页 */
.pagination{display:flex;justify-content:space-between;align-items:center;padding:10px 4px;border-top:1px solid #f0f0f0;font-size:12px;color:#666}
.pagination .btns{display:flex;gap:2px;flex-wrap:wrap}
.pagination .btns button,.pagination .size-btn{min-width:30px;height:26px;border:1px solid #e0e0e0;border-radius:4px;background:#fff;color:#555;cursor:pointer;font-size:12px;padding:0 8px}
.pagination .btns button:hover,.pagination .size-btn:hover{border-color:#1a73e8;color:#1a73e8}
.pagination .btns button.active,.pagination .size-btn.active{background:#1a73e8;color:#fff;border-color:#1a73e8}
.pagination .size-group{display:inline-flex;gap:2px;margin-left:8px}
</style>
</head>
<body>
<div id="sidebar"></div>
<div class="main-content">
<div class="panel">
<h3>产品BOM主数据维护</h3>
<div class="toolbar">
<input type="text" id="txtKeyword" placeholder="搜索 产品编码 / 产品名称" style="width:220px">
<select id="selStatus">
<option value="-1">状态:全部</option>
<option value="1">启用</option>
<option value="0">禁用</option>
</select>
<button class="btn btn-primary" onclick="searchList()">查询</button>
<button class="btn btn-outline" onclick="resetSearch()">重置</button>
<div style="flex:1"></div>
<button class="btn btn-green" onclick="openAddModal()">+ 新增产品</button>
</div>
<table>
<thead>
<tr>
<th>产品编码</th><th>BOM版本</th><th>产品名称</th>
<th>状态</th><th>BOM明细数</th><th>操作</th>
</tr>
</thead>
<tbody id="tbodyList"></tbody>
</table>
<div class="pagination" id="pagination" style="display:none">
<div><span>共 <em id="totalCnt">0</em> 条</span><span class="size-group" id="sizeBtns"></span></div>
<div class="btns" id="pageBtns"></div>
</div>
</div>
</div>
<div class="modal-overlay" id="editModal">
<div class="modal">
<h3 id="modalTitle">新增产品</h3>
<div class="form-grid">
<div class="form-group">
<label>产品编码 <span style="color:#ef4444">*</span></label>
<input type="text" id="fProductCode" placeholder="如 KHT10">
</div>
<div class="form-group">
<label>BOM版本 <span style="color:#ef4444">*</span></label>
<input type="text" id="fBOMVersion" placeholder="如 V1.0">
</div>
<div class="form-group full">
<label>产品名称</label>
<input type="text" id="fProductName" placeholder="产品名称">
</div>
<div class="form-group">
<label>状态</label>
<select id="fStatus">
<option value="1">启用</option>
<option value="0">禁用</option>
</select>
</div>
</div>
<div class="modal-actions">
<button class="btn btn-outline" onclick="closeModal('editModal')">取消</button>
<button class="btn btn-primary" onclick="saveBom()">保存</button>
</div>
</div>
</div>
<div class="modal-overlay" id="detailModal">
<div class="modal" style="width:90vw">
<h3 id="detailTitle">BOM明细</h3>
<div class="toolbar">
<button class="btn btn-orange" onclick="expandBom()">从金蝶同步展开BOM</button>
<span id="detailCount" style="font-size:13px;color:#666"></span>
</div>
<div class="detail-table">
<table>
<thead>
<tr>
<th>层级</th><th>父物料编码</th><th>子物料编码</th><th>子物料名称</th>
<th>规格型号</th><th>单位</th><th>用量</th>
</tr>
</thead>
<tbody id="tbodyDetail"></tbody>
</table>
</div>
<div class="modal-actions">
<button class="btn btn-outline" onclick="closeModal('detailModal')">关闭</button>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
var curId=0;
var curProductCode='';
var curPage=1, pageSize=20, totalCnt=0;
var pageSizeOptions=[20,50,100,200];
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
function api(url,method,data,cb){
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
if(data)opts.body=JSON.stringify(data);
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
cb&&cb(res);
}).catch(function(e){toast('请求失败:'+e.message,'error')});
}
function getApiUrl(){
return '../../api/deliver/';
}
function baseUrl(){
return window.location.protocol+'//'+window.location.host;
}
function searchList(){curPage=1;loadList()}
function loadList(){
var kw=document.getElementById('txtKeyword').value.trim();
var st=document.getElementById('selStatus').value;
api(getApiUrl()+'GetBomMasterList?keyword='+encodeURIComponent(kw)+'&status='+st+'&page='+curPage+'&pageSize='+pageSize,'GET',null,function(res){
var rows=res.data||[];
totalCnt=res.total||0;
var html='';
if(rows.length===0){html='<tr class="empty"><td colspan="6" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>'}
rows.forEach(function(r){
var stBadge=r.Status=='1'?'<span class="badge badge-success">启用</span>':'<span class="badge badge-muted">禁用</span>';
html+='<tr>'+
'<td>'+r.ProductCode+'</td>'+
'<td>'+r.BOMVersion+'</td>'+
'<td>'+r.ProductName+'</td>'+
'<td>'+stBadge+'</td>'+
'<td><span class="expand-btn" onclick="openDetail(\''+r.ProductCode+'\',\''+r.BOMVersion+'\')">查看BOM</span></td>'+
'<td style="white-space:nowrap">'+
'<button class="btn btn-primary" style="height:26px;padding:0 10px;font-size:11px" onclick="openEdit('+r.Id+')">编辑</button> '+
'<button class="btn btn-red" style="height:26px;padding:0 10px;font-size:11px" onclick="delBom('+r.Id+')">删除</button>'+
'</td></tr>';
});
document.getElementById('tbodyList').innerHTML=html;
renderPagination();
});
}
function resetSearch(){document.getElementById('txtKeyword').value='';document.getElementById('selStatus').value='-1';curPage=1;loadList()}
// ===== 列表分页 =====
function renderPagination(){
var tp=Math.ceil(totalCnt/pageSize)||1;
var pc=document.getElementById('pagination');
if(totalCnt<=pageSize){pc.style.display='none';return}
pc.style.display='flex';
document.getElementById('totalCnt').textContent=totalCnt;
document.getElementById('sizeBtns').innerHTML=pageSizeOptions.map(function(s){return '<button class="size-btn'+(s===pageSize?' active':'')+'" onclick="setPageSize('+s+')">'+s+'条</button>'}).join('');
var pb=document.getElementById('pageBtns');
if(tp<=1){pb.innerHTML='';return}
var h='<button '+(curPage<=1?'disabled':'')+' onclick="goPage(1)">首页</button><button '+(curPage<=1?'disabled':'')+' onclick="goPage('+(curPage-1)+')">‹</button>';
for(var i=Math.max(1,curPage-2);i<=Math.min(tp,curPage+2);i++)h+='<button class="'+(i===curPage?'active':'')+'" onclick="goPage('+i+')">'+i+'</button>';
h+='<button '+(curPage>=tp?'disabled':'')+' onclick="goPage('+(curPage+1)+')">›</button><button '+(curPage>=tp?'disabled':'')+' onclick="goPage('+tp+')">末页</button>';
pb.innerHTML=h;
}
function goPage(p){
if(p<1||p>Math.ceil(totalCnt/pageSize))return;
curPage=p;
loadList();
}
function setPageSize(s){
pageSize=s;curPage=1;loadList();
}
function openAddModal(){
curId=0;
document.getElementById('modalTitle').textContent='新增产品';
document.getElementById('fProductCode').value='';
document.getElementById('fBOMVersion').value='';
document.getElementById('fProductName').value='';
document.getElementById('fStatus').value='1';
document.getElementById('editModal').classList.add('show');
}
function openEdit(id){
api(getApiUrl()+'GetBomMasterList?keyword=&status=-1&page=1&pageSize=100000','GET',null,function(res){
var list=res.data||[];
var r=list.find(function(x){return x.Id==id});
if(!r){toast('未找到记录','error');return}
curId=id;
document.getElementById('modalTitle').textContent='编辑产品';
document.getElementById('fProductCode').value=r.ProductCode;
document.getElementById('fBOMVersion').value=r.BOMVersion;
document.getElementById('fProductName').value=r.ProductName;
document.getElementById('fStatus').value=r.Status||'1';
document.getElementById('editModal').classList.add('show');
});
}
function saveBom(){
var data={
Id:curId,
ProductCode:document.getElementById('fProductCode').value.trim(),
BOMVersion:document.getElementById('fBOMVersion').value.trim(),
ProductName:document.getElementById('fProductName').value.trim(),
Status:document.getElementById('fStatus').value
};
if(!data.ProductCode){toast('请填写产品编码','error');return}
if(!data.BOMVersion){toast('请填写BOM版本','error');return}
api(getApiUrl()+'SaveBomMaster','POST',data,function(res){
if(res.success){toast('保存成功','success');closeModal('editModal');loadList()}
});
}
function delBom(id){
if(!confirm('确认删除该产品?其BOM明细将一并删除'))return;
api(getApiUrl()+'DeleteBomMaster','POST',{Id:id},function(res){
if(res.success){toast('删除成功','success');loadList()}
});
}
function openDetail(productCode,bomVersion){
curProductCode=productCode;
document.getElementById('detailTitle').textContent='BOM明细 - '+productCode+' ('+bomVersion+')';
document.getElementById('detailModal').classList.add('show');
loadDetail();
}
function loadDetail(){
api(getApiUrl()+'GetBomDetail?productCode='+encodeURIComponent(curProductCode),'GET',null,function(res){
var rows=res.data||[];
document.getElementById('detailCount').textContent='共 '+rows.length+' 条';
var html='';
if(rows.length===0)html='<tr><td colspan="7" style="text-align:center;padding:36px;color:#bbb">暂无明细,请点击"从金蝶同步展开BOM"</td></tr>';
rows.forEach(function(r){
html+='<tr><td>L'+r.Level+'</td><td>'+r.ParentMaterialId+'</td><td>'+r.ChildMaterialId+'</td><td>'+r.MaterialName+'</td><td>'+r.Spec+'</td><td>'+r.Unit+'</td><td>'+r.UsageQty+'</td></tr>';
});
document.getElementById('tbodyDetail').innerHTML=html;
});
}
function expandBom(){
var p=prompt('请输入要展开的产品编码(如 KHT10):',curProductCode);
if(!p)return;
curProductCode=p.trim();
api(getApiUrl()+'ExpandBom','POST',{ProductCode:curProductCode,BOMVersion:''},function(res){
if(res.success){toast(res.message,'success');document.getElementById('detailTitle').textContent='BOM明细 - '+curProductCode;loadDetail()}
});
}
function closeModal(id){document.getElementById(id).classList.remove('show')}
loadList();
</script>
<!-- 公共导航栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>
@@ -0,0 +1,297 @@
<!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="../common/nav.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
.top-bar{background:linear-gradient(135deg,#1a73e8,#1557b0);color:#fff;padding:0 24px;display:flex;align-items:center;height:56px;box-shadow:0 2px 8px rgba(0,0,0,.15);position:sticky;top:0;z-index:100}
.top-bar .logo{font-size:18px;font-weight:600;letter-spacing:1px;margin-right:32px}
.top-bar .nav-tabs{display:flex;gap:4px;height:100%}
.top-bar .nav-tabs a{color:rgba(255,255,255,.75);text-decoration:none;padding:0 16px;display:flex;align-items:center;font-size:13px;border-radius:4px 4px 0 0;transition:all .2s}
.top-bar .nav-tabs a:hover{color:#fff;background:rgba(255,255,255,.1)}
.top-bar .nav-tabs a.active{color:#fff;background:rgba(255,255,255,.2)}
.top-bar .user-info{margin-left:auto;font-size:13px;opacity:.85}
.main-container{max-width:1500px;margin:0 auto;padding:16px 20px}
/* 统计卡片 */
.stat-cards{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-bottom:16px}
.stat-card{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:18px;text-align:center;border-top:3px solid #3b82f6}
.stat-card .stat-value{font-size:32px;font-weight:700;margin-bottom:4px}
.stat-card .stat-label{font-size:13px;color:#64748b}
.stat-card.stat-danger{border-top-color:#ef4444}.stat-card.stat-danger .stat-value{color:#ef4444}
.stat-card.stat-warning{border-top-color:#f59e0b}.stat-card.stat-warning .stat-value{color:#f59e0b}
.stat-card.stat-safe{border-top-color:#22c55e}.stat-card.stat-safe .stat-value{color:#22c55e}
.stat-card.stat-total{border-top-color:#3b82f6}.stat-card.stat-total .stat-value{color:#3b82f6}
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:12px}
.toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
.toolbar select,.toolbar input{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.toolbar select:focus,.toolbar input:focus{border-color:#1a73e8}
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff}
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
.btn-primary:hover{opacity:.92}
.btn-outline{background:#fff;color:#666;border:2px solid #e0e0e0}
.btn-outline:hover{border-color:#1a73e8;color:#1a73e8}
/* 分组列表 */
.group-row{display:flex;align-items:center;gap:10px;padding:10px 14px;border:1px solid #e2e8f0;border-radius:6px;margin-bottom:8px;cursor:pointer;background:#fff;transition:all .15s}
.group-row:hover{background:#f0f6ff}
.group-row .expand{font-size:12px;color:#1a73e8;width:16px}
.group-row .group-name{font-weight:600;color:#333;min-width:150px}
.group-row .group-sub{color:#64748b;font-size:13px;flex:1}
.badge{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:500}
.badge-danger{background:#fee2e2;color:#991b1b}
.badge-warning{background:#fef3c7;color:#92400e}
.badge-success{background:#dcfce7;color:#166534}
.badge-info{background:#dbeafe;color:#1e40af}
table{width:100%;border-collapse:collapse;font-size:13px}
thead th{background:#f8f9fa;color:#555;font-weight:600;padding:9px 12px;text-align:left;border:1px solid #999;border-bottom:2px solid #999;white-space:nowrap}
tbody td{padding:9px 12px;border:1px solid #ddd;color:#333}
tbody tr:hover{background:#f0f6ff}
.pagination{display:flex;justify-content:flex-end;align-items:center;gap:8px;margin-top:12px;font-size:13px;color:#666}
.pagination button{min-width:30px;height:30px;border:1px solid #e0e0e0;border-radius:4px;background:#fff;cursor:pointer}
.pagination button.active{background:#1a73e8;color:#fff;border-color:#1a73e8}
/* 甘特图 */
.gantt-container{overflow-x:auto;margin-top:8px}
.gantt-grid{display:grid;grid-template-columns:160px repeat(var(--gantt-cols),minmax(36px,1fr));gap:1px;font-size:11px;min-width:100%}
.gantt-header{background:#f1f5f9;padding:6px 4px;text-align:center;font-weight:600;color:#64748b;border-bottom:2px solid #e2e8f0}
.gantt-header.weekend{background:#e2e8f0;color:#94a3b8}
.gantt-name{background:#f8fafc;padding:6px 8px;font-weight:500;border-bottom:1px solid #e2e8f0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.gantt-cell{padding:4px 2px;text-align:center;border-bottom:1px solid #e2e8f0;min-height:28px}
.gantt-cell.req{background:#dbeafe;color:#1e40af;font-weight:600}
.gantt-cell.arrival{background:#dcfce7;color:#166534}
.gantt-cell.stop{background:#fee2e2;color:#991b1b}
.gantt-cell.empty{background:#fff}
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
.detail-wrap{display:none;margin-bottom:8px}
</style>
</head>
<body>
<div id="sidebar"></div>
<div class="main-content">
<div class="stat-cards">
<div class="stat-card stat-total"><div class="stat-value" id="statTotal">0</div><div class="stat-label">物料总数</div></div>
<div class="stat-card stat-danger"><div class="stat-value" id="statDanger">0</div><div class="stat-label">断线风险</div></div>
<div class="stat-card stat-warning"><div class="stat-value" id="statWarn">0</div><div class="stat-label">预警关注</div></div>
<div class="stat-card stat-safe"><div class="stat-value" id="statSafe">0</div><div class="stat-label">安全供应</div></div>
</div>
<div class="panel">
<h3>物料交付分组(按产品)</h3>
<div class="toolbar">
<select id="selProductType" style="min-width:140px"><option value="">产品类型:全部</option></select>
<select id="selRisk">
<option value="">风险:全部</option>
<option value="断线">断线</option>
<option value="预警">预警</option>
<option value="安全">安全</option>
</select>
<input type="text" id="txtKeyword" placeholder="物料编码/名称" style="min-width:160px">
<div style="flex:1"></div>
<button class="btn btn-outline" onclick="loadBoard()">刷新</button>
</div>
<div id="groupList"></div>
</div>
<div class="panel">
<h3>物料交付明细</h3>
<table>
<thead>
<tr>
<th>物料编码</th><th>物料名称</th><th>层级</th><th>产品类型</th><th>日需求</th><th>总需求</th>
<th>可用库存</th><th>在途</th><th>已到货</th><th>预计停线日</th><th>预计到货日</th><th>风险</th>
</tr>
</thead>
<tbody id="tbodyDetail"></tbody>
</table>
<div class="pagination" id="detailPagination"></div>
</div>
<div class="panel">
<h3>交付甘特图(需求/到货)</h3>
<div class="gantt-container">
<div class="gantt-grid" id="ganttGrid"></div>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
var options=null;
var currentProductType='';
var currentRisk='';
var ganttData=[];
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
function api(url,method,data,cb){
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
if(data)opts.body=JSON.stringify(data);
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
cb&&cb(res);
}).catch(function(e){toast('请求失败:'+e.message,'error')});
}
function getApiUrl(){return '../../api/deliver/'}
function loadOptions(cb){
// 产品类型下拉:从分组接口取
api(getApiUrl()+'GetBoardGroups','GET',null,function(res){
var h='<option value="">产品类型:全部</option>';
(res.data||[]).forEach(function(g){h+='<option value="'+g.ProductType+'">'+g.ProductType+'</option>'});
document.getElementById('selProductType').innerHTML=h;
cb&&cb();
});
}
function loadBoard(){
currentProductType=document.getElementById('selProductType').value;
currentRisk=document.getElementById('selRisk').value;
loadStats();
loadGroups();
loadDetail();
loadGantt();
}
function loadStats(){
api(getApiUrl()+'GetBoardStats?productType='+encodeURIComponent(currentProductType)+'&risk='+encodeURIComponent(currentRisk),'GET',null,function(res){
var d=res.data||{};
document.getElementById('statTotal').textContent=d.total||0;
document.getElementById('statDanger').textContent=d.danger||0;
document.getElementById('statWarn').textContent=d.warn||0;
document.getElementById('statSafe').textContent=d.safe||0;
});
}
function loadGroups(){
api(getApiUrl()+'GetBoardGroups','GET',null,function(res){
var rows=res.data||[];
var html='';
if(rows.length===0)html='<div style="text-align:center;padding:30px;color:#bbb">暂无数据</div>';
rows.forEach(function(g){
var stClass=g.Status=='需处理'?'badge-danger':(g.Status=='关注'?'badge-warning':'badge-success');
html+='<div class="group-row" onclick="toggleGroup(\''+g.ProductType+'\',this)">'+
'<span class="expand">▶</span>'+
'<span class="group-name">'+g.ProductType+'</span>'+
'<span style="color:#64748b;font-size:13px">'+g.MaterialCount+'个物料</span>'+
'<span class="badge badge-danger">断线'+g.DangerCount+'</span>'+
'<span class="badge badge-warning">预警'+g.WarnCount+'</span>'+
'<span class="badge '+stClass+'">'+g.Status+'</span>'+
'</div>';
});
document.getElementById('groupList').innerHTML=html;
});
}
function toggleGroup(productType,el){
currentProductType=productType;
document.getElementById('selProductType').value=productType;
var expand=el.querySelector('.expand');
if(expand.textContent==='▶'){expand.textContent='▼'}else{expand.textContent='▶'}
loadDetail();
loadGantt();
}
function loadDetail(page){
page=page||1;
var kw=document.getElementById('txtKeyword').value.trim();
api(getApiUrl()+'GetBoardDetail?productType='+encodeURIComponent(currentProductType)+'&risk='+encodeURIComponent(currentRisk)+'&keyword='+encodeURIComponent(kw)+'&page='+page+'&pageSize=50','GET',null,function(res){
var rows=res.data||[];
var html='';
if(rows.length===0)html='<tr><td colspan="12" style="text-align:center;padding:36px;color:#bbb">暂无明细数据</td></tr>';
rows.forEach(function(r){
var cls=r.DeliveryRisk=='断线'?'badge-danger':(r.DeliveryRisk=='预警'?'badge-warning':'badge-success');
html+='<tr>'+
'<td>'+r.ChildMaterialId+'</td>'+
'<td>'+r.MaterialName+'</td>'+
'<td>L'+r.BOMLevel+'</td>'+
'<td>'+(r.ProductTypes||'')+'</td>'+
'<td>'+r.DailyReq+'</td>'+
'<td>'+r.TotalRequirement+'</td>'+
'<td>'+r.AvailableStock+'</td>'+
'<td>'+r.InTransitQty+'</td>'+
'<td>'+r.ArrivedQty+'</td>'+
'<td>'+r.ExpectedStopDate+'</td>'+
'<td>'+r.ExpectedArrivalDate+'</td>'+
'<td><span class="badge '+cls+'">'+r.DeliveryRisk+'</span></td>'+
'</tr>';
});
document.getElementById('tbodyDetail').innerHTML=html;
renderPagination(res.total,res.page);
});
}
function renderPagination(total,page){
var pages=Math.ceil(total/50);
if(pages<=1){document.getElementById('detailPagination').innerHTML='';return}
var html='';
for(var i=1;i<=pages;i++)html+='<button class="'+(i==page?'active':'')+'" onclick="loadDetail('+i+')">'+i+'</button>';
document.getElementById('detailPagination').innerHTML=html;
}
function loadGantt(){
api(getApiUrl()+'GetGanttData?productType='+encodeURIComponent(currentProductType)+'&risk=断线,预警','GET',null,function(res){
ganttData=res.data||[];
var start=res.startDate;
var end=res.endDate;
if(!start||!end){document.getElementById('ganttGrid').innerHTML='<div style="padding:20px;color:#bbb">暂无排程数据</div>';return}
renderGantt(start,end,ganttData);
});
}
function renderGantt(start,end,data){
var dates=[];
var cur=new Date(start),last=new Date(end);
while(cur<=last){dates.push(formatDate(cur));cur.setDate(cur.getDate()+1)}
document.getElementById('ganttGrid').style.setProperty('--gantt-cols',dates.length);
// 按物料分组
var groups={};
data.forEach(function(d){
var key=d.ChildMaterialId;
if(!groups[key])groups[key]={material:d.ChildMaterialId,name:d.MaterialName,risk:d.DeliveryRisk,stop:d.ExpectedStopDate,reqs:{},arrivals:[]};
if(d.PlanDate)groups[key].reqs[d.PlanDate]=(groups[key].reqs[d.PlanDate]||0)+(parseFloat(d.DailyRequirement)||0);
if(d.ArrivalExpectedDate||d.ActualArrivalDate)groups[key].arrivals.push(d);
});
// 表头
var html='<div class="gantt-header" style="grid-column:1">物料</div>';
dates.forEach(function(d){
var dt=new Date(d);var wk=['日','一','二','三','四','五','六'][dt.getDay()];
var isWk=(dt.getDay()==0||dt.getDay()==6);
html+='<div class="gantt-header'+(isWk?' weekend':'')+'">'+(d.slice(5))+'<br>周'+wk+'</div>';
});
// 物料行
Object.keys(groups).forEach(function(key){
var g=groups[key];
html+='<div class="gantt-name" title="'+g.name+'">'+g.material+' <span style="color:#94a3b8">L'+(key.split('|')[0]||'')+'</span></div>';
dates.forEach(function(d){
var cls='empty';
var txt='';
if(g.stop==d){cls='stop';txt='停'}
if(g.reqs[d]){cls=cls=='stop'?'stop':'req';txt=(txt||'')+(g.reqs[d]||'')}
// 到货
g.arrivals.forEach(function(a){
var ad=a.ArrivalExpectedDate;
if(ad==d){cls='arrival';txt=(txt||'')+'>'+a.ArrivalQty}
});
html+='<div class="gantt-cell '+cls+'">'+txt+'</div>';
});
});
document.getElementById('ganttGrid').innerHTML=html;
}
function formatDate(d){var y=d.getFullYear(),m=('0'+(d.getMonth()+1)).slice(-2),dd=('0'+d.getDate()).slice(-2);return y+'-'+m+'-'+dd}
loadOptions(function(){loadBoard()});
</script>
<!-- 公共导航栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>
@@ -0,0 +1,437 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>采购物料交付计划看板</title>
<link rel="stylesheet" href="../common/nav.css">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: 'Microsoft YaHei','PingFang SC',sans-serif; background: #f3f5fa; color: #2c3e50; padding: 14px 18px; }
/* 顶部 4 卡片 */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.card { background: #fff; border-radius: 8px; padding: 16px 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); cursor: pointer; transition: transform .15s, box-shadow .15s; border-left: 4px solid #c0c4cc; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.1); }
.card .label { font-size: 13px; color: #909399; margin-bottom: 6px; }
.card .num { font-size: 30px; font-weight: 700; line-height: 1.2; }
.card .sub { font-size: 12px; color: #b0b3ba; margin-top: 4px; }
.card.total { border-left-color: #409eff; } .card.total .num { color: #409eff; }
.card.broken { border-left-color: #f56c6c; } .card.broken .num { color: #f56c6c; }
.card.warn { border-left-color: #e6a23c; } .card.warn .num { color: #e6a23c; }
.card.safe { border-left-color: #67c23a; } .card.safe .num { color: #67c23a; }
.card.active { box-shadow: 0 0 0 2px #409eff, 0 6px 16px rgba(0,0,0,0.1); }
/* 工具栏 */
.toolbar { background: #fff; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.toolbar select, .toolbar button { height: 30px; padding: 0 12px; border: 1px solid #dcdfe6; border-radius: 6px; background: #fff; font-size: 13px; cursor: pointer; }
.toolbar select:hover, .toolbar button:hover { border-color: #409eff; color: #409eff; }
.toolbar .spacer { flex: 1; }
.toolbar .meta { font-size: 12px; color: #909399; }
/* 甘特图容器 */
.gantt-wrap { background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); padding: 16px 18px 14px; }
.gantt-title { font-size: 16px; font-weight: 600; color: #303133; margin-bottom: 6px; }
.gantt-sub { font-size: 12px; color: #909399; margin-bottom: 12px; }
.gantt-legend { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; font-size: 12px; color: #606266; }
.gantt-legend .item { display: flex; align-items: center; gap: 5px; }
.gantt-legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.gantt-legend .dot.req { background: #409eff; }
.gantt-legend .dot.arr { background: #67c23a; }
.gantt-legend .dot.broken { background: #f56c6c; }
.gantt-legend .dot.weekend { background: #f4f4f5; border: 1px solid #dcdfe6; }
.gantt-scroll { overflow-x: auto; overflow-y: visible; position: relative; padding-bottom: 6px; }
.gantt-scroll::-webkit-scrollbar { height: 10px; }
.gantt-scroll::-webkit-scrollbar-thumb { background: #c0c4cc; border-radius: 5px; }
.gantt-scroll::-webkit-scrollbar-track { background: #f0f2f5; border-radius: 5px; }
.gantt { position: relative; min-width: 100%; border-collapse: collapse; }
.gantt-row { display: flex; border-bottom: 1px solid #f0f2f5; min-height: 50px; max-height: 50px; overflow: hidden; align-items: stretch; }
.gantt-row.head { background: #f7f9fc; border-bottom: 1px solid #ebeef5; min-height: 36px; max-height: 36px; align-items: stretch; overflow: hidden; }
.gantt-row:hover:not(.head) { background: #fafbfc; }
/* 固定左列 */
.gantt-fixed { position: sticky; left: 0; z-index: 4; background: #fff; display: flex; flex-shrink: 0; box-shadow: 2px 0 4px rgba(0,0,0,0.04); }
.gantt-row.head .gantt-fixed { background: #f7f9fc; z-index: 6; }
.gantt-cell { padding: 8px 10px; font-size: 12px; color: #303133; border-right: 1px solid #ebeef5; display: flex; flex-direction: column; justify-content: center; }
.gantt-row.head .gantt-cell { font-weight: 600; color: #606266; padding: 6px 10px; }
.f-name { width: 160px; min-width: 160px; max-width: 160px; overflow: hidden; }
.f-name .nm { font-size: 13px; font-weight: 600; color: #303133; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-name .sub { font-size: 11px; color: #909399; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
.f-tag { width: 70px; display: flex; align-items: center; }
.f-tag .tag { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; text-align: center; }
.f-tag .tag.broken { background: #fef0f0; color: #f56c6c; }
.f-tag .tag.warn { background: #fdf6ec; color: #e6a23c; }
.f-tag .tag.safe { background: #f0f9eb; color: #67c23a; }
.f-tag .tag.empty { background: #f4f4f5; color: #909399; }
/* 时间轴区 */
.gantt-timeline { position: relative; flex-shrink: 0; }
.gantt-row.head .gantt-timeline { background: #f7f9fc; }
.day-col { position: absolute; top: 0; height: 100%; display: flex; align-items: center; justify-content: center; border-right: 1px solid #f0f2f5; font-size: 12px; }
.gantt-row.head .day-col { color: #606266; font-weight: 500; }
.day-col.weekend { background: #fafafa; color: #909399; }
.day-col.past { background: #f5f5f5; color: #c0c4cc; }
.day-col.month-end { border-right: 2px solid #c0c4cc; }
.day-col.today { background: #ecf5ff; color: #409eff; font-weight: 700; }
.day-col .v { position: relative; display: flex; align-items: center; justify-content: center; padding: 4px; }
/* 单元格内的数据元素 */
.cell-num { position: absolute; font-weight: 600; }
.cell-num.req { color: #409eff; font-size: 12px; }
.cell-num.arr { color: #67c23a; font-size: 12px; }
.cell-arr-label { color: #67c23a; font-size: 10px; font-weight: 500; }
/* 停线标记 - 黄底橙边(预警) */
.stop-mark { position: absolute; inset: 6px 4px; border: 2px solid #e6a23c; background: rgba(230, 162, 60, 0.12); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #c8770f; font-weight: 600; }
.stop-mark .icon { font-size: 11px; line-height: 1; }
/* 断线标记 - 红底红边(断线) */
.break-mark { position: absolute; inset: 6px 4px; border: 2px solid #f56c6c; background: rgba(245, 108, 108, 0.12); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #f56c6c; font-weight: 600; }
/* 库存说明(图表下方) */
.gantt-summary { margin-top: 10px; padding: 8px 12px; background: #f7f9fc; border-radius: 6px; font-size: 12px; color: #909399; line-height: 1.7; }
.loading, .empty { text-align: center; padding: 50px 0; color: #909399; font-size: 14px; }
</style>
</head>
<body>
<div id="sidebar"></div>
<div class="cards">
<div class="card total" data-risk="">
<div class="label">物料总数</div>
<div class="num" id="cardTotal">-</div>
<div class="sub">所有未结束排程物料</div>
</div>
<div class="card broken" data-risk="断线">
<div class="label">断线风险</div>
<div class="num" id="cardBroken">-</div>
<div class="sub">到货晚于停线(紧急)</div>
</div>
<div class="card warn" data-risk="预警">
<div class="label">预警关注</div>
<div class="num" id="cardWarn">-</div>
<div class="sub">到货日 = 停线日</div>
</div>
<div class="card safe" data-risk="安全">
<div class="label">安全供应</div>
<div class="num" id="cardSafe">-</div>
<div class="sub">到货早于停线</div>
</div>
</div>
<div class="toolbar">
<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>
<button id="btnRefresh">刷新</button>
<button id="btnAutoRefresh">自动刷新:开</button>
<div class="spacer"></div>
<span class="meta" id="metaInfo">加载中...</span>
</div>
<div class="gantt-wrap">
<div class="gantt-title">物料交付甘特图</div>
<div class="gantt-sub">按日展示每个物料的当日需求、到货、停线预警/断线情况</div>
<div class="gantt-legend">
<div class="item"><span class="dot req"></span> 当日需求</div>
<div class="item"><span class="dot arr"></span> 到货</div>
<div class="item"><span class="dot broken"></span> 断线</div>
<div class="item" style="border:2px solid #e6a23c;border-radius:3px;width:14px;height:12px;background:rgba(230,162,60,.12);"></div> 预警
<div class="item"><span class="dot weekend"></span> 周末</div>
</div>
<div id="ganttContainer" class="gantt-scroll">
<div class="loading">加载中...</div>
</div>
</div>
<!-- 公共导航栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
<script>
const API_BASE = '../../api/Deliver';
const DAY_WIDTH = 56; // 每天宽度(按截图样式,约56px/列)
const ROW_HEIGHT = 50; // 每行高度
const HEAD_HEIGHT = 36; // 表头高度
let autoRefreshTimer = null;
let currentProductType = '';
let currentRisk = '';
function parseDate(s) { return s ? new Date(s) : null; }
function fmtDate(d) {
return d.getFullYear() + '-' + String(d.getMonth()+1).padStart(2,'0') + '-' + String(d.getDate()).padStart(2,'0');
}
function dateDiffDays(a, b) { return Math.round((b - a) / 86400000); }
function isWeekend(d) { const w = d.getDay(); return w === 0 || w === 6; }
function loadSummary() {
fetch(API_BASE + '/GetBoardSummary').then(r => r.json()).then(res => {
if (res.success) {
document.getElementById('cardTotal').textContent = res.total;
document.getElementById('cardBroken').textContent = res.broken;
document.getElementById('cardWarn').textContent = res.warn;
document.getElementById('cardSafe').textContent = res.safe;
}
});
}
function loadProductTypes() {
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);
});
}
});
}
function loadGantt() {
document.getElementById('ganttContainer').innerHTML = '<div class="loading">加载中...</div>';
const params = new URLSearchParams();
if (currentProductType) params.append('productType', currentProductType);
if (currentRisk) params.append('risk', currentRisk);
fetch(API_BASE + '/GetBoardGantt?' + params).then(r => r.json()).then(res => {
if (!res.success) {
document.getElementById('ganttContainer').innerHTML = '<div class="empty">加载失败:' + (res.message || '') + '</div>';
return;
}
document.getElementById('metaInfo').textContent = '时间范围:' + res.startDate + ' ~ ' + res.endDate + '(共 ' + res.data.length + ' 个物料)';
renderGantt(res);
});
}
function renderGantt(res) {
const data = res.data;
if (!data || data.length === 0) {
document.getElementById('ganttContainer').innerHTML = '<div class="empty">暂无数据</div>';
return;
}
const startD = parseDate(res.startDate);
const endD = parseDate(res.endDate);
const today = parseDate(res.today);
if (!startD || !endD || endD < startD) {
document.getElementById('ganttContainer').innerHTML = '<div class="empty">日期范围无效</div>';
return;
}
const dayCount = dateDiffDays(startD, endD) + 1;
const timelineWidth = dayCount * DAY_WIDTH;
// 计算每个物料的"日均需求"(用于"需求X/天"标注)
function getDailyRate(reqMap) {
let total = 0, days = 0;
Object.values(reqMap).forEach(v => { if (v > 0) { total += v; days++; } });
if (days === 0) return 0;
// 计算频次
const dates = Object.keys(reqMap).filter(d => reqMap[d] > 0).sort();
if (dates.length < 2) return dates.length > 0 ? reqMap[dates[0]] : 0;
// 频次 = 总需求 / (最后一天 - 第一天的天数)
const d1 = parseDate(dates[0]), d2 = parseDate(dates[dates.length-1]);
const span = Math.max(1, dateDiffDays(d1, d2) + 1);
return Math.round(total / span);
}
const root = document.createElement('div');
root.className = 'gantt';
root.style.width = (160 + 70 + timelineWidth) + 'px';
// 表头
const head = document.createElement('div');
head.className = 'gantt-row head';
head.style.height = HEAD_HEIGHT + 'px';
const hFixed = document.createElement('div');
hFixed.className = 'gantt-fixed';
hFixed.innerHTML =
'<div class="gantt-cell f-name">物料</div>' +
'<div class="gantt-cell f-tag">风险</div>';
head.appendChild(hFixed);
const hTime = document.createElement('div');
hTime.className = 'gantt-timeline';
hTime.style.width = timelineWidth + 'px';
hTime.style.height = HEAD_HEIGHT + 'px';
for (let i = 0; i < dayCount; i++) {
const d = new Date(startD); d.setDate(d.getDate() + i);
const cell = document.createElement('div');
cell.className = 'day-col';
if (isWeekend(d)) cell.classList.add('weekend');
// 月末
const nextD = new Date(d); nextD.setDate(nextD.getDate() + 1);
if (nextD.getMonth() !== d.getMonth()) cell.classList.add('month-end');
// 今天
if (today && fmtDate(d) === fmtDate(today)) cell.classList.add('today');
// 今天之前(过期)
if (today && d < today && fmtDate(d) !== fmtDate(today)) cell.classList.add('past');
cell.style.left = (i * DAY_WIDTH) + 'px';
cell.style.width = DAY_WIDTH + 'px';
cell.textContent = (d.getMonth() + 1) + '/' + d.getDate();
hTime.appendChild(cell);
}
head.appendChild(hTime);
root.appendChild(head);
// 物料行
data.forEach(m => {
const row = document.createElement('div');
row.className = 'gantt-row';
row.style.height = ROW_HEIGHT + 'px';
// 固定列
const fx = document.createElement('div');
fx.className = 'gantt-fixed';
const riskCls = ({'断线':'broken','预警':'warn','安全':'safe'}[m.DeliveryRisk] || 'empty');
const dailyRate = getDailyRate(m.Requirement || {});
fx.innerHTML =
'<div class="gantt-cell f-name"><div class="nm" title="' + m.ChildMaterialId + '">' + m.ChildMaterialId + '</div><div class="sub" title="' + (m.MaterialName || '-') + (dailyRate > 0 ? ' · 需求' + dailyRate + '/天' : '') + '">' + (m.MaterialName || '-') + (dailyRate > 0 ? ' · 需求' + dailyRate + '/天' : '') + '</div></div>' +
'<div class="gantt-cell f-tag"><span class="tag ' + riskCls + '">' + (m.DeliveryRisk || '未判定') + '</span></div>';
row.appendChild(fx);
// 时间轴
const tl = document.createElement('div');
tl.className = 'gantt-timeline';
tl.style.width = timelineWidth + 'px';
tl.style.height = ROW_HEIGHT + 'px';
const reqMap = m.Requirement || {};
const arrList = m.Arrival || [];
const arrByDate = {};
arrList.forEach(a => {
if (!arrByDate[a.date]) arrByDate[a.date] = 0;
arrByDate[a.date] += a.qty;
});
for (let i = 0; i < dayCount; i++) {
const d = new Date(startD); d.setDate(d.getDate() + i);
const dateStr = fmtDate(d);
// 周末/今天/过期 背景
if (isWeekend(d)) {
const bg = document.createElement('div');
bg.className = 'day-col weekend';
bg.style.left = (i * DAY_WIDTH) + 'px';
bg.style.width = DAY_WIDTH + 'px';
tl.appendChild(bg);
} else if (today && d < today && fmtDate(d) !== fmtDate(today)) {
const bg = document.createElement('div');
bg.className = 'day-col past';
bg.style.left = (i * DAY_WIDTH) + 'px';
bg.style.width = DAY_WIDTH + 'px';
tl.appendChild(bg);
} else if (today && fmtDate(d) === fmtDate(today)) {
const bg = document.createElement('div');
bg.className = 'day-col today';
bg.style.left = (i * DAY_WIDTH) + 'px';
bg.style.width = DAY_WIDTH + 'px';
tl.appendChild(bg);
}
const nextD = new Date(d); nextD.setDate(nextD.getDate() + 1);
if (nextD.getMonth() !== d.getMonth()) {
const bg = document.createElement('div');
bg.className = 'day-col month-end';
bg.style.left = (i * DAY_WIDTH) + 'px';
bg.style.width = DAY_WIDTH + 'px';
tl.appendChild(bg);
}
// 内容容器(用于在格子里绝对定位)
const wrap = document.createElement('div');
wrap.className = 'v';
wrap.style.position = 'absolute';
wrap.style.left = (i * DAY_WIDTH) + 'px';
wrap.style.width = DAY_WIDTH + 'px';
wrap.style.height = '100%';
// 需求
const reqQty = reqMap[dateStr] || 0;
if (reqQty > 0) {
const num = document.createElement('div');
num.className = 'cell-num req';
num.textContent = reqQty;
num.style.top = '4px';
num.style.left = '4px';
wrap.appendChild(num);
}
// 到货
const arrQty = arrByDate[dateStr] || 0;
if (arrQty > 0) {
// 模拟图样式:到货/60 形式
const num = document.createElement('div');
num.className = 'cell-num arr';
num.innerHTML = '到' + arrQty;
num.style.bottom = '4px';
num.style.left = '4px';
wrap.appendChild(num);
}
// 停线/断线
if (m.ExpectedStopDate && dateStr === m.ExpectedStopDate) {
const mark = document.createElement('div');
if (m.DeliveryRisk === '断线') {
mark.className = 'break-mark';
mark.innerHTML = '<div class="icon">停</div><div>断线</div>';
} else {
mark.className = 'stop-mark';
mark.innerHTML = '<div class="icon">停</div><div>预警</div>';
}
wrap.appendChild(mark);
}
tl.appendChild(wrap);
}
row.appendChild(tl);
root.appendChild(row);
});
document.getElementById('ganttContainer').innerHTML = '';
document.getElementById('ganttContainer').appendChild(root);
// 滚动到今天
if (today) {
const offset = dateDiffDays(startD, today) * DAY_WIDTH;
const wrap = document.getElementById('ganttContainer');
setTimeout(() => { wrap.scrollLeft = Math.max(0, offset - 100); }, 50);
}
}
document.querySelectorAll('.card').forEach(card => {
card.addEventListener('click', () => {
const risk = card.dataset.risk;
const params = new URLSearchParams();
if (risk) params.append('risk', risk);
if (currentProductType) params.append('productType', currentProductType);
window.location.href = 'delivery_dashboard_risk.html?' + params.toString();
});
});
document.getElementById('filterProductType').addEventListener('change', e => { currentProductType = e.target.value; loadGantt(); });
document.getElementById('filterRisk').addEventListener('change', e => { currentRisk = e.target.value; loadGantt(); });
document.getElementById('btnRefresh').addEventListener('click', () => { loadSummary(); loadGantt(); });
let autoOn = true;
document.getElementById('btnAutoRefresh').addEventListener('click', e => {
autoOn = !autoOn;
e.target.textContent = '自动刷新:' + (autoOn ? '开' : '关');
if (autoOn) startAuto(); else stopAuto();
});
function startAuto() { stopAuto(); autoRefreshTimer = setInterval(() => { loadSummary(); loadGantt(); }, 600000); }
function stopAuto() { if (autoRefreshTimer) { clearInterval(autoRefreshTimer); autoRefreshTimer = null; } }
loadSummary();
loadProductTypes();
loadGantt();
startAuto();
</script>
</body>
</html>
@@ -0,0 +1,358 @@
<!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>
@@ -0,0 +1,630 @@
<!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="../common/nav.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
.top-bar{background:linear-gradient(135deg,#1a73e8,#1557b0);color:#fff;padding:0 24px;display:flex;align-items:center;height:56px;box-shadow:0 2px 8px rgba(0,0,0,.15);position:sticky;top:0;z-index:100}
.top-bar .logo{font-size:18px;font-weight:600;letter-spacing:1px;margin-right:32px}
.top-bar .nav-tabs{display:flex;gap:4px;height:100%}
.top-bar .nav-tabs a{color:rgba(255,255,255,.75);text-decoration:none;padding:0 16px;display:flex;align-items:center;font-size:13px;border-radius:4px 4px 0 0;transition:all .2s}
.top-bar .nav-tabs a:hover{color:#fff;background:rgba(255,255,255,.1)}
.top-bar .nav-tabs a.active{color:#fff;background:rgba(255,255,255,.2)}
.top-bar .user-info{margin-left:auto;font-size:13px;opacity:.85}
.main-container{max-width:1500px;margin:0 auto;padding:16px 20px}
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:12px}
.toolbar{display:flex;flex-direction:column;gap:10px;margin-bottom:12px}
.toolbar-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.toolbar input,.toolbar select{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.toolbar select{width:140px;max-width:140px;flex-shrink:0}
#selProductType{width:130px}
#selSupplier{width:160px}
#selPurchaser{width:130px}
#selRisk{width:100px}
.toolbar input:focus,.toolbar select:focus{border-color:#1a73e8}
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff}
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
.btn-primary:hover{opacity:.92}
.btn-green{background:#22c55e}
.btn-green:hover{opacity:.92}
.btn-red{background:#ef4444}
.btn-red:hover{opacity:.92}
.btn-blue{background:#3b82f6}
.btn-blue:hover{opacity:.92}
.btn-warning{background:#f59e0b}
.btn-warning:hover{opacity:.92}
.btn-outline{background:#fff;color:#666;border:2px solid #e0e0e0}
.btn-outline:hover{border-color:#1a73e8;color:#1a73e8}
table{width:100%;border-collapse:collapse;font-size:13px}
thead th{background:#f8f9fa;color:#555;font-weight:600;padding:9px 12px;text-align:left;border:1px solid #999;border-bottom:2px solid #999;white-space:nowrap}
tbody td{padding:9px 12px;border:1px solid #ddd;color:#333}
tbody tr:hover{background:#f0f6ff}
.badge{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:500}
.badge-danger{background:#fee2e2;color:#991b1b}
.badge-warning{background:#fef3c7;color:#92400e}
.badge-success{background:#dcfce7;color:#166534}
.badge-info{background:#dbeafe;color:#1e40af}
.pagination{display:flex;justify-content:flex-end;align-items:center;gap:8px;margin-top:12px;font-size:13px;color:#666}
.pagination button{min-width:30px;height:30px;border:1px solid #e0e0e0;border-radius:4px;background:#fff;cursor:pointer}
.pagination button.active{background:#1a73e8;color:#fff;border-color:#1a73e8}
.pagination button:disabled{opacity:.4;cursor:not-allowed}
.pagination select{height:28px;border:1px solid #e0e0e0;border-radius:4px;padding:0 4px}
.table-wrap{overflow-x:auto;width:100%}
#tblList{table-layout:fixed;min-width:1600px}
#tblList th{position:relative;padding:9px 8px}
#tblList tbody td{padding:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#tblList tbody td:last-child{overflow:visible}
.col-resizer{position:absolute;right:-3px;top:0;width:8px;height:100%;cursor:col-resize;z-index:5}
.col-resizer:hover{background:rgba(26,115,232,.25)}
.modal-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:999;justify-content:center;align-items:center}
.modal-overlay.show{display:flex}
.modal{background:#fff;border-radius:10px;width:760px;max-width:95vw;max-height:90vh;overflow-y:auto;box-shadow:0 20px 60px rgba(0,0,0,.2);padding:24px}
.modal h3{font-size:17px;color:#333;margin-bottom:16px}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.form-group{display:flex;flex-direction:column}
.form-group.full{grid-column:1/-1}
.form-group label{font-size:12px;color:#555;font-weight:600;margin-bottom:4px}
.form-group input,.form-group select,.form-group textarea{height:34px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.form-group textarea{height:60px;resize:vertical;padding:6px 10px}
.form-group input:focus,.form-group select:focus,.form-group textarea:focus{border-color:#1a73e8}
.form-group input.readonly{background:#f8f9fa;color:#999}
.modal-actions{display:flex;gap:8px;justify-content:flex-end;margin-top:18px}
.arrival-table{width:100%;border-collapse:collapse;font-size:12px;margin-top:10px}
.arrival-table th{background:#f1f5f9;padding:6px;border:1px solid #e2e8f0;font-weight:600;color:#64748b}
.arrival-table td{padding:4px;border:1px solid #e2e8f0;text-align:center}
.arrival-table input,.arrival-table select{width:110px;border:1px solid #ddd;border-radius:4px;padding:2px 4px;font-size:12px}
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
</style>
</head>
<body>
<div id="sidebar"></div>
<div class="main-content">
<div class="panel">
<h3>物料交付维护</h3>
<div class="toolbar">
<div class="toolbar-row">
<select id="selProductType"><option value="">产品类型:全部</option></select>
<select id="selSupplier"><option value="">供应商:全部</option></select>
<select id="selPurchaser"><option value="">采购员:全部</option></select>
<select id="selRisk">
<option value="">风险:全部</option>
<option value="断线">断线</option>
<option value="预警">预警</option>
<option value="安全">安全</option>
</select>
<input type="text" id="txtKeyword" placeholder="搜索 物料编码 / 物料名称" style="width:200px">
<button class="btn btn-primary" onclick="loadList()">查询</button>
<button class="btn btn-outline" onclick="resetSearch()">重置</button>
</div>
<div class="toolbar-row">
<button class="btn btn-primary" onclick="startDeliveryCalc()" id="btnRecalcDelivery">🔄 重算交付数据</button>
<button class="btn btn-blue" onclick="downloadBatchArrivalTpl()">📄 到货计划模板</button>
<button class="btn btn-outline" onclick="document.getElementById('batchArrivalFile').click()">📥 导入到货计划</button>
<input type="file" id="batchArrivalFile" accept=".xls,.xlsx" style="display:none" onchange="importBatchArrivalExcel(this)">
<span style="font-size:13px;color:#666;margin-left:8px" id="totalCount"></span>
</div>
</div>
<div id="calcProgressWrap" style="display:none;margin-bottom:12px">
<div style="background:#e5e7eb;border-radius:4px;height:18px;overflow:hidden">
<div id="calcProgressBar" style="background:linear-gradient(135deg,#10b981,#059669);height:100%;width:0%;transition:width .3s"></div>
</div>
<div style="display:flex;justify-content:space-between;margin-top:4px">
<span id="calcProgressText" style="font-size:12px;color:#666"></span>
<span id="calcProgressPercent" style="font-size:12px;color:#059669;font-weight:600"></span>
</div>
</div>
<div class="table-wrap">
<table id="tblList">
<thead>
<tr>
<th style="width:48px">序号</th>
<th style="width:130px">操作</th>
<th style="width:110px">物料编码</th><th style="width:120px">物料名称</th><th style="width:80px">产品类型</th><th style="width:150px">供应商</th><th style="width:110px">采购员</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>
</tr>
</thead>
<tbody id="tbodyList"></tbody>
</table>
</div>
<div class="pagination" id="pagination"></div>
</div>
</div>
<div class="modal-overlay" id="editModal">
<div class="modal">
<h3>物料交付 - 编辑</h3>
<div class="form-grid">
<div class="form-group">
<label>产品编码</label>
<input type="text" id="fProductCode" class="readonly" readonly>
</div>
<div class="form-group">
<label>BOM版本</label>
<input type="text" id="fBOMVersion" class="readonly" readonly>
</div>
<div class="form-group">
<label>物料编码</label>
<input type="text" id="fChildMaterialId" class="readonly" readonly>
</div>
<div class="form-group">
<label>物料名称</label>
<input type="text" id="fMaterialName" class="readonly" readonly>
</div>
<div class="form-group">
<label>供应商</label>
<input type="text" id="fSupplier">
</div>
<div class="form-group">
<label>采购员</label>
<input type="text" id="fPurchaser">
</div>
<div class="form-group">
<label>预计停线日期 <span style="color:#94a3b8;font-weight:400">(系统自动计算)</span></label>
<input type="date" id="fExpectedStopDate" class="readonly" readonly>
</div>
<div class="form-group">
<label>预计到货日期 <span style="color:#94a3b8;font-weight:400">(最近未到货批次)</span></label>
<input type="date" id="fExpectedArrivalDate" class="readonly" readonly>
</div>
<div class="form-group">
<label>交付风险</label>
<select id="fDeliveryRisk">
<option value="">自动判定</option>
<option value="安全">安全</option>
<option value="预警">预警</option>
<option value="断线">断线</option>
</select>
</div>
<div class="form-group">
<label>震泽库存</label>
<input type="text" id="fZhenZeStock" class="readonly" readonly>
</div>
<div class="form-group">
<label>晋江库存</label>
<input type="text" id="fJinJiangStock" class="readonly" readonly>
</div>
<div class="form-group">
<label>资阳库存</label>
<input type="text" id="fZiYangStock" class="readonly" readonly>
</div>
<div class="form-group">
<label>量产在途</label>
<input type="text" id="fMassInTransit" class="readonly" readonly>
</div>
<div class="form-group">
<label>研发在途</label>
<input type="text" id="fResearchInTransit" class="readonly" readonly>
</div>
<div class="form-group">
<label>线边库存</label>
<input type="text" id="fLineSideStock" class="readonly" readonly>
</div>
<div class="form-group">
<label>已收货(上月1号至今)</label>
<input type="text" id="fReceivedQty" class="readonly" readonly>
</div>
<div class="form-group">
<label>可用库存</label>
<input type="text" id="fAvailableStock" class="readonly" readonly>
</div>
<div class="form-group full">
<label>交付进度及后续交付计划</label>
<textarea id="fDeliveryProgress" placeholder="如:8/20到货500PCS,8/25剩余300PCS"></textarea>
</div>
<div class="form-group full">
<label>备注</label>
<textarea id="fRemark"></textarea>
</div>
</div>
<div class="modal-actions">
<button class="btn btn-outline" onclick="closeModal('editModal')">取消</button>
<button class="btn btn-primary" onclick="saveDelivery()">保存</button>
</div>
</div>
</div>
<div class="modal-overlay" id="arrivalModal">
<div class="modal">
<h3>到货计划管理 - <span id="arrivalMaterialName"></span></h3>
<div class="toolbar">
<button class="btn btn-green" onclick="addArrivalRow()">+ 新增批次</button>
</div>
<table class="arrival-table">
<thead>
<tr>
<th>序号</th><th>预计到货日</th><th>到货数量</th><th>删除行</th>
</tr>
</thead>
<tbody id="arrivalBody"></tbody>
</table>
<div class="modal-actions">
<button class="btn btn-green" onclick="saveAllArrival()">保存全部批次</button>
<button class="btn btn-outline" onclick="closeModal('arrivalModal')">关闭</button>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
var curDeliveryId=0;
var curDelivery={};
var options=null;
var arrivals=[];
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
function api(url,method,data,cb){
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
if(data)opts.body=JSON.stringify(data);
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
cb&&cb(res);
}).catch(function(e){toast('请求失败:'+e.message,'error')});
}
function getApiUrl(){return '../../api/deliver/'}
function loadOptions(cb){
api(getApiUrl()+'GetOptions','GET',null,function(res){
options=res.data||{};
var h='<option value="">产品类型:全部</option>';
(options.productTypes||[]).forEach(function(t){h+='<option value="'+t+'">'+t+'</option>'});
document.getElementById('selProductType').innerHTML=h;
var h2='<option value="">供应商:全部</option>';
(options.suppliers||[]).forEach(function(s){h2+='<option value="'+s+'">'+s+'</option>'});
document.getElementById('selSupplier').innerHTML=h2;
var h3='<option value="">采购员:全部</option>';
(options.purchasers||[]).forEach(function(p){h3+='<option value="'+p+'">'+p+'</option>'});
document.getElementById('selPurchaser').innerHTML=h3;
cb&&cb();
});
}
function getFilters(){
var t=document.getElementById('selProductType').value;
var s=document.getElementById('selSupplier').value;
var pu=document.getElementById('selPurchaser').value;
var r=document.getElementById('selRisk').value;
var kw=document.getElementById('txtKeyword').value.trim();
return {t:t,s:s,pu:pu,r:r,kw:kw};
}
var curPage=1,curPageSize=50,curList=[];
function loadList(page){
page=page||1;
curPage=page;
var f=getFilters();
var url=getApiUrl()+'GetDeliveryList?productType='+encodeURIComponent(f.t)+'&supplier='+encodeURIComponent(f.s)+'&purchaser='+encodeURIComponent(f.pu)+'&risk='+encodeURIComponent(f.r)+'&keyword='+encodeURIComponent(f.kw)+'&page='+page+'&pageSize='+curPageSize;
api(url,'GET',null,function(res){
var rows=res.data||[];
curList=rows;
var html='';
if(rows.length===0)html='<tr><td colspan="18" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
rows.forEach(function(r,i){
var seq=(curPage-1)*curPageSize+i+1;
var rk=r.DeliveryRisk||'安全';
var cls=rk=='断线'?'badge-danger':(rk=='预警'?'badge-warning':'badge-success');
html+='<tr>'+
'<td>'+seq+'</td>'+
'<td style="white-space:nowrap">'+
'<button class="btn btn-primary" style="height:26px;padding:0 8px;font-size:11px" onclick="openEdit('+r.Id+')">编辑</button> '+
'<button class="btn btn-blue" style="height:26px;padding:0 8px;font-size:11px" onclick="openArrival('+r.Id+',\''+r.MaterialName+'\')">到货计划</button>'+
'</td>'+
'<td>'+r.ChildMaterialId+'</td>'+
'<td>'+r.MaterialName+'</td>'+
'<td>'+(r.ProductTypes||'')+'</td>'+
'<td>'+r.Supplier+'</td>'+
'<td>'+r.Purchaser+'</td>'+
'<td>'+r.ExpectedStopDate+'</td>'+
'<td>'+r.ExpectedArrivalDate+'</td>'+
'<td><span class="badge '+cls+'">'+rk+'</span></td>'+
'<td>'+r.DailyRequirement+'</td>'+
'<td>'+r.ZhenZeStock+'</td>'+
'<td>'+r.JinJiangStock+'</td>'+
'<td>'+r.ZiYangStock+'</td>'+
'<td>'+r.AvailableStock+'</td>'+
'<td>'+r.MassInTransit+'</td>'+
'<td>'+r.ResearchInTransit+'</td>'+
'<td>'+r.LineSideStock+'</td>'+
'<td>'+r.ReceivedQty+'</td>'+
'</tr>';
});
document.getElementById('tbodyList').innerHTML=html;
document.getElementById('totalCount').textContent='共 '+res.total+' 条';
renderPagination(res.total,res.page);
});
}
function renderPagination(total,page){
var pages=Math.ceil(total/curPageSize)||1;
var sizeOpts=[20,50,100,200].map(function(s){
return '<option value="'+s+'"'+(s==curPageSize?' selected':'')+'>'+s+'</option>';
}).join('');
var html='<span>每页 <select onchange="changePageSize(this.value)">'+sizeOpts+'</select> 条</span>';
html+='<button '+(page<=1?'disabled':'')+' onclick="loadList(1)">首页</button>';
html+='<button '+(page<=1?'disabled':'')+' onclick="loadList('+(page-1)+')">上一页</button>';
var start=Math.max(1,page-2),end=Math.min(pages,page+2);
for(var i=start;i<=end;i++){
html+='<button class="'+(i==page?'active':'')+'" onclick="loadList('+i+')">'+i+'</button>';
}
html+='<button '+(page>=pages?'disabled':'')+' onclick="loadList('+(page+1)+')">下一页</button>';
html+='<button '+(page>=pages?'disabled':'')+' onclick="loadList('+pages+')">末页</button>';
html+='<span>第 '+page+' / '+pages+' 页,共 '+total+' 条</span>';
document.getElementById('pagination').innerHTML=html;
}
function changePageSize(v){
curPageSize=parseInt(v)||50;
loadList(1);
}
// 表头列宽左右拖动
function initColResize(){
var table=document.getElementById('tblList');
if(!table)return;
var ths=table.querySelectorAll('thead th');
[].forEach.call(ths,function(th){
if(th.querySelector('.col-resizer'))return;
var grip=document.createElement('div');
grip.className='col-resizer';
th.appendChild(grip);
grip.addEventListener('mousedown',function(e){
e.preventDefault();e.stopPropagation();
var startX=e.clientX,startW=th.offsetWidth;
function onMove(ev){
var w=Math.max(40,startW+(ev.clientX-startX));
th.style.width=w+'px';
}
function onUp(){
document.removeEventListener('mousemove',onMove);
document.removeEventListener('mouseup',onUp);
}
document.addEventListener('mousemove',onMove);
document.addEventListener('mouseup',onUp);
});
});
}
function resetSearch(){
document.getElementById('selProductType').value='';
document.getElementById('selSupplier').value='';
document.getElementById('selPurchaser').value='';
document.getElementById('selRisk').value='';
document.getElementById('txtKeyword').value='';
loadList();
}
function openEdit(id){
api(getApiUrl()+'GetDeliveryDetail?id='+id,'GET',null,function(res){
if(!res.success||!res.data){toast('未找到记录','error');return}
var d=res.data;
curDeliveryId=d.Id;
curDelivery=d;
document.getElementById('fProductCode').value=d.ProductCode;
document.getElementById('fBOMVersion').value=d.BOMVersion;
document.getElementById('fChildMaterialId').value=d.ChildMaterialId;
document.getElementById('fMaterialName').value=d.MaterialName;
document.getElementById('fSupplier').value=d.Supplier;
document.getElementById('fPurchaser').value=d.Purchaser;
document.getElementById('fExpectedStopDate').value=d.ExpectedStopDate;
document.getElementById('fExpectedArrivalDate').value=d.ExpectedArrivalDate;
document.getElementById('fDeliveryRisk').value=d.DeliveryRisk;
document.getElementById('fZhenZeStock').value=d.ZhenZeStock||0;
document.getElementById('fJinJiangStock').value=d.JinJiangStock||0;
document.getElementById('fZiYangStock').value=d.ZiYangStock||0;
document.getElementById('fMassInTransit').value=d.MassInTransit||0;
document.getElementById('fResearchInTransit').value=d.ResearchInTransit||0;
document.getElementById('fLineSideStock').value=d.LineSideStock;
document.getElementById('fReceivedQty').value=d.ReceivedQty||0;
calcAvailable();
document.getElementById('fDeliveryProgress').value=d.DeliveryProgress;
document.getElementById('fRemark').value=d.Remark;
document.getElementById('editModal').classList.add('show');
});
}
function calcAvailable(){
var z=parseFloat(document.getElementById('fZhenZeStock').value)||0;
var j=parseFloat(document.getElementById('fJinJiangStock').value)||0;
var t=parseFloat(document.getElementById('fZiYangStock').value)||0;
var m=parseFloat(document.getElementById('fMassInTransit').value)||0;
var r=parseFloat(document.getElementById('fResearchInTransit').value)||0;
var l=parseFloat(document.getElementById('fLineSideStock').value)||0;
document.getElementById('fAvailableStock').value=(z+j+t+m+r+l);
}
function saveDelivery(){
var data={
Id:curDeliveryId,
Supplier:document.getElementById('fSupplier').value.trim(),
Purchaser:document.getElementById('fPurchaser').value.trim(),
DeliveryRisk:document.getElementById('fDeliveryRisk').value,
LineSideStock:document.getElementById('fLineSideStock').value,
DeliveryProgress:document.getElementById('fDeliveryProgress').value,
Remark:document.getElementById('fRemark').value
};
api(getApiUrl()+'SaveDelivery','POST',data,function(res){
if(res.success){toast('保存成功,停线日已自动计算','success');closeModal('editModal');loadList()}
});
}
function openArrival(id,materialName){
curDeliveryId=id;
curDelivery={Id:id,MaterialName:materialName,ChildMaterialId:''};
for(var i=0;i<curList.length;i++){if(curList[i].Id===id){curDelivery.ChildMaterialId=curList[i].ChildMaterialId;curDelivery.MaterialName=curList[i].MaterialName;break}}
document.getElementById('arrivalMaterialName').textContent=materialName;
loadArrival(id);
document.getElementById('arrivalModal').classList.add('show');
}
function loadArrival(id){
api(getApiUrl()+'GetDeliveryDetail?id='+id,'GET',null,function(res){
if(!res.data)return;
arrivals=(res.data.arrivals||[]).map(function(a){
return {Id:a.Id,BatchNo:a.BatchNo,ExpectedArrivalDate:a.ExpectedArrivalDate,ActualArrivalDate:a.ActualArrivalDate,ArrivalQty:a.ArrivalQty,Status:a.Status};
});
renderArrival();
});
}
function renderArrival(){
var html='';
if(arrivals.length===0)html='<tr><td colspan="4" style="padding:20px;color:#bbb">暂无到货计划</td></tr>';
arrivals.forEach(function(a,i){
html+='<tr>'+
'<td>'+(i+1)+'</td>'+
'<td><input type="date" value="'+a.ExpectedArrivalDate+'" onchange="arrivals['+i+'].ExpectedArrivalDate=this.value"></td>'+
'<td><input type="number" value="'+a.ArrivalQty+'" onchange="arrivals['+i+'].ArrivalQty=this.value"></td>'+
'<td><button class="btn btn-red" style="height:24px;padding:0 8px;font-size:11px" onclick="delArrival('+i+','+a.Id+')">删除</button></td>'+
'</tr>';
});
document.getElementById('arrivalBody').innerHTML=html;
}
function addArrivalRow(){
arrivals.push({Id:0,BatchNo:arrivals.length+1,ExpectedArrivalDate:'',ArrivalQty:'',Status:'待发货'});
renderArrival();
}
// 列表页:下载批量到货计划导入模板
function downloadBatchArrivalTpl(){
var url=getApiUrl()+'DownloadBatchArrivalTemplate';
var a=document.createElement('a');
a.href=url;a.download='到货计划导入模板.xls';a.style.display='none';
document.body.appendChild(a);a.click();
setTimeout(function(){document.body.removeChild(a)},100);
}
// 列表页:导入批量到货计划
function importBatchArrivalExcel(input){
var file=input.files[0];if(!file)return;
if(file.size>10*1024*1024){toast('文件不能超过10MB','error');input.value='';return}
var reader=new FileReader();
reader.onload=function(e){
var b64=e.target.result.split(',')[1];
api(getApiUrl()+'ImportBatchArrivalPlan','POST',{FileBase64:b64},function(res){
if(res.success){
toast(res.message||'导入成功','success');
loadList(curPage);
}else{
toast(res.message||'导入失败','error');
}
input.value='';
});
};
reader.readAsDataURL(file);
}
function saveAllArrival(){
var saved=0,err=0;
var list=arrivals.map(function(a){return a});
// 串行保存
function saveNext(i){
if(i>=list.length){closeModal('arrivalModal');loadArrival(curDeliveryId);toast('到货计划保存完成,共保存'+saved+'个批次','success');return}
var a=list[i];
if(!a.ExpectedArrivalDate&&!a.ActualArrivalDate&&a.ArrivalQty===''){
// 空行跳过
saveNext(i+1);return;
}
var data={Id:a.Id,DeliveryId:curDeliveryId,BatchNo:a.BatchNo,ExpectedArrivalDate:a.ExpectedArrivalDate,ActualArrivalDate:a.ActualArrivalDate,ArrivalQty:a.ArrivalQty,Status:a.Status};
api(getApiUrl()+'SaveArrivalPlan','POST',data,function(res){
if(res.success){saved++}else{err++}
saveNext(i+1);
});
}
saveNext(0);
}
function delArrival(idx,id){
if(id>0){
if(!confirm('确认删除该批次?'))return;
api(getApiUrl()+'DeleteArrivalPlan','POST',{Id:id},function(res){
if(res.success){toast('删除成功','success');loadArrival(curDeliveryId)}
});
}else{
arrivals.splice(idx,1);
renderArrival();
}
}
// 保存全部到货批次
document.addEventListener('click',function(e){
if(e.target.id==='')return;
});
function closeModal(id){document.getElementById(id).classList.remove('show')}
loadOptions(function(){loadList();checkRunningCalc();});
initColResize();
var _calcTimer=null;
function startDeliveryCalc(){
if(!confirm('确定要重新计算物料交付数据吗?\n\n该操作会:\n1. 收集计划完成日>=当天的生产排程\n2. 补展开缺失的BOM\n3. 重算物料需求\n4. 同步物料交付主表\n5. 同步金蝶三地库存\n6. 计算预计停线日与交付风险\n\n数据量大时可能需要几分钟,请稍候。'))return;
var btn=document.getElementById('btnRecalcDelivery');
btn.disabled=true;btn.textContent='计算中...';
document.getElementById('calcProgressWrap').style.display='block';
document.getElementById('calcProgressBar').style.width='0%';
document.getElementById('calcProgressText').textContent='正在启动...';
document.getElementById('calcProgressPercent').textContent='0%';
api(getApiUrl()+'RecalcDelivery','POST',null,function(res){
if(res.success){
toast('已开始重算物料交付数据','success');
pollCalcProgress();
}else{
btn.disabled=false;btn.textContent='🔄 重算交付数据';
toast(res.message||'启动失败','error');
}
});
}
function pollCalcProgress(){
if(_calcTimer)clearInterval(_calcTimer);
_calcTimer=setInterval(function(){
api(getApiUrl()+'GetDeliveryCalcProgress','GET',null,function(res){
if(!res||res.success===false)return;
var p=res.percent||0;
var bar=document.getElementById('calcProgressBar');
var txt=document.getElementById('calcProgressText');
var pct=document.getElementById('calcProgressPercent');
bar.style.width=p+'%';
pct.textContent=p+'%';
txt.textContent=(res.stage||'')+(res.message?' - ':'')+(res.message||'');
if(res.status==='success'){
clearInterval(_calcTimer);_calcTimer=null;
document.getElementById('btnRecalcDelivery').disabled=false;
document.getElementById('btnRecalcDelivery').textContent='🔄 重算交付数据';
toast(res.message||'重算完成','success');
loadList();
}else if(res.status==='error'){
clearInterval(_calcTimer);_calcTimer=null;
document.getElementById('btnRecalcDelivery').disabled=false;
document.getElementById('btnRecalcDelivery').textContent='🔄 重算交付数据';
toast((res.stage||'')+' - '+(res.message||'失败'),'error');
}
});
},1500);
}
function checkRunningCalc(){
api(getApiUrl()+'GetDeliveryCalcProgress','GET',null,function(res){
if(res&&res.status==='running'){
document.getElementById('calcProgressWrap').style.display='block';
document.getElementById('calcProgressBar').style.width=(res.percent||0)+'%';
document.getElementById('calcProgressPercent').textContent=(res.percent||0)+'%';
document.getElementById('calcProgressText').textContent=(res.stage||'')+(res.message?' - ':'')+(res.message||'');
document.getElementById('btnRecalcDelivery').disabled=true;
document.getElementById('btnRecalcDelivery').textContent='计算中...';
pollCalcProgress();
}
});
}
</script>
<!-- 公共导航栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>
@@ -0,0 +1,534 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>生产交付 - GX-WMS</title>
<link rel="stylesheet" href="../common/nav.css">
<link rel="stylesheet" href="../common/style.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
.main-content{max-width:1500px;margin:0 auto;padding:16px 20px}
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:12px}
.toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
.toolbar input,.toolbar select{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.toolbar input:focus,.toolbar select:focus{border-color:#1a73e8}
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff;white-space:nowrap}
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
.btn-primary:hover{opacity:.92}
.btn-green{background:#22c55e}
.btn-green:hover{opacity:.92}
.btn-red{background:#ef4444}
.btn-red:hover{opacity:.92}
.btn-outline{background:#fff;color:#475569;border:1px solid #d1d5db}
.btn-outline:hover{background:#f8fafc}
.btn-blue{background:#3b82f6}
.btn-blue:hover{opacity:.92}
.btn-warning{background:#f59e0b}
.btn-warning:hover{opacity:.92}
.table-wrap{overflow-x:auto;width:100%}
table{width:100%;border-collapse:collapse;font-size:13px;table-layout:fixed;min-width:900px}
th{background:#f1f5f9;padding:9px 8px;border-bottom:2px solid #e2e8f0;font-weight:600;color:#475569;text-align:left;white-space:nowrap;position:relative}
td{padding:8px;border-bottom:1px solid #f1f5f9;color:#334155;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
tr:hover{background:#f8fafc}
.pagination{display:flex;gap:6px;justify-content:center;align-items:center;margin-top:14px;font-size:13px;color:#475569;flex-wrap:wrap}
.pagination button{min-width:32px;height:32px;border:1px solid #e2e8f0;background:#fff;border-radius:5px;cursor:pointer;font-size:13px;color:#475569}
.pagination button.active{background:#1a73e8;color:#fff;border-color:#1a73e8}
.pagination button:disabled{opacity:.4;cursor:not-allowed}
.pagination select{height:28px;border:1px solid #e2e8f0;border-radius:5px;padding:0 4px;font-size:13px}
.col-resizer{position:absolute;right:-3px;top:0;width:8px;height:100%;cursor:col-resize;z-index:5}
.col-resizer:hover{background:rgba(26,115,232,.25)}
.modal-overlay{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.45);display:none;align-items:center;justify-content:center;z-index:1000}
.modal-overlay.show{display:flex}
.modal{background:#fff;border-radius:10px;width:520px;max-width:95vw;max-height:90vh;overflow:auto;box-shadow:0 10px 40px rgba(0,0,0,.18)}
.modal-header{padding:16px 20px;border-bottom:1px solid #e2e8f0;display:flex;align-items:center;justify-content:space-between}
.modal-header h3{font-size:15px;color:#333;font-weight:600}
.modal-close{background:none;border:none;font-size:22px;color:#94a3b8;cursor:pointer;line-height:1}
.modal-close:hover{color:#334155}
.modal-body{padding:20px}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.form-group{display:flex;flex-direction:column;gap:5px}
.form-group label{font-size:12px;color:#64748b;font-weight:600}
.form-group input,.form-group select{height:34px;padding:0 10px;border:1px solid #d1d5db;border-radius:5px;font-size:13px;outline:none}
.input-with-picker{position:relative}
.input-with-picker input{padding-right:34px;cursor:pointer}
.input-with-picker .picker-btn{position:absolute;right:6px;top:50%;transform:translateY(-50%);width:24px;height:24px;border:none;background:transparent;color:#94a3b8;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;border-radius:4px}
.input-with-picker .picker-btn:hover{background:#f1f5f9;color:#1a73e8}
/* ===== 物料查询弹窗(仿金蝶) ===== */
#materialPicker{z-index:1100}
.picker-modal{width:1100px;max-width:95vw;height:80vh}
.picker-toolbar{padding:10px 16px;background:#f8fafc;border-bottom:1px solid #e2e8f0;display:flex;gap:10px;align-items:center;flex-shrink:0}
.picker-toolbar select,.picker-toolbar input{height:30px;padding:0 10px;border:1px solid #d1d5db;border-radius:4px;font-size:12px;outline:none;min-width:130px}
.picker-toolbar input{min-width:180px}
.picker-toolbar label{font-size:12px;color:#475569;margin-right:4px}
.picker-toolbar .cond-row{display:flex;gap:6px;align-items:center;margin-right:12px}
.picker-toolbar .actions{margin-left:auto;display:flex;gap:8px}
.picker-toolbar .btn{height:30px;padding:0 14px;font-size:12px;border-radius:4px}
.picker-table-wrap{flex:1;overflow:auto}
.picker-table{width:100%;border-collapse:collapse;font-size:13px}
.picker-table thead th{position:sticky;top:0;z-index:1;background:#f1f5f9;color:#475569;font-weight:600;padding:9px 10px;text-align:left;border-bottom:2px solid #cbd5e1;white-space:nowrap}
.picker-table tbody td{padding:7px 10px;border-bottom:1px solid #f1f5f9;color:#334155}
.picker-table tbody tr:hover{background:#eff6ff;cursor:pointer}
.picker-table tbody tr.selected{background:#dbeafe}
.picker-table .col-check{width:36px;text-align:center}
.picker-table .filter-input{width:100%;padding:3px 6px;border:1px solid #e2e8f0;border-radius:3px;font-size:11px;margin-top:3px;outline:none}
.picker-table .filter-input:focus{border-color:#3b82f6}
.picker-pagination{padding:8px 16px;background:#f8fafc;border-top:1px solid #e2e8f0;display:flex;justify-content:space-between;align-items:center;font-size:12px;color:#64748b;flex-shrink:0}
.picker-pagination .pages{display:flex;gap:4px}
.picker-pagination .pages button{min-width:26px;height:26px;border:1px solid #d1d5db;background:#fff;border-radius:3px;cursor:pointer;font-size:12px;color:#475569}
.picker-pagination .pages button.active{background:#3b82f6;color:#fff;border-color:#3b82f6}
.picker-pagination .pages button:hover:not(.active){border-color:#3b82f6;color:#3b82f6}
.form-group input:focus,.form-group select:focus{border-color:#1a73e8;box-shadow:0 0 0 2px rgba(26,115,232,.1)}
.form-group input.readonly{background:#f8f9fa;color:#94a3b8}
.modal-actions{display:flex;gap:8px;justify-content:flex-end;margin-top:18px}
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
</style>
</head>
<body>
<div id="sidebar"></div>
<!-- 物料查询弹窗(仿金蝶数据查询) -->
<div class="modal-overlay" id="materialPicker">
<div class="modal picker-modal">
<div class="modal-header">
<h3>📋 物料查询(数据查询)</h3>
<button class="modal-close" onclick="closeModal('materialPicker')">×</button>
</div>
<div class="picker-toolbar">
<div class="cond-row">
<label>物料代码</label>
<select id="pkCodeOp" style="width:90px">
<option>包含</option><option>不包含</option><option>等于</option><option>不等于</option><option>开始于</option><option>结束于</option><option>为空</option><option>不为空</option>
</select>
<input type="text" id="pkCodeVal" placeholder="输入物料代码" style="min-width:160px">
</div>
<div class="cond-row">
<label>物料名称</label>
<select id="pkNameOp" style="width:90px">
<option>包含</option><option>不包含</option><option>等于</option><option>不等于</option><option>开始于</option><option>结束于</option><option>为空</option><option>不为空</option>
</select>
<input type="text" id="pkNameVal" placeholder="输入物料名称" style="min-width:160px">
</div>
<div class="actions">
<button class="btn btn-primary" onclick="doSearch()">🔍 搜索</button>
<button class="btn btn-outline" onclick="resetSearchPK()">重置</button>
<button class="btn btn-green" onclick="addSelectedMaterial()">添加</button>
</div>
</div>
<div class="picker-table-wrap">
<table class="picker-table">
<thead>
<tr>
<th class="col-check"><input type="checkbox" id="pkCheckAll" onchange="toggleCheckAll(this.checked)"></th>
<th>物料代码 <input class="filter-input" id="pkFilterCode" oninput="doSearch()"></th>
<th>物料名称 <input class="filter-input" id="pkFilterName" oninput="doSearch()"></th>
<th>规格型号 <input class="filter-input" id="pkFilterSpec" oninput="doSearch()"></th>
</tr>
</thead>
<tbody id="pkBody"></tbody>
</table>
</div>
<div class="picker-pagination">
<span>共 <span id="pkTotal">0</span> 条 每页 <span id="pkPageSize">2000</span> 条</span>
<div class="pages" id="pkPages"></div>
</div>
</div>
</div>
<div id="toast" class="toast"></div>
<div class="main-content">
<div class="panel">
<h3>生产交付 - 线边仓库存维护</h3>
<div class="toolbar">
<input type="text" id="txtKeyword" placeholder="搜索 物料编号 / 物料名称" style="width:220px">
<input type="date" id="dateStart" style="width:140px">
<span style="color:#64748b;font-size:12px">至</span>
<input type="date" id="dateEnd" style="width:140px">
<button class="btn btn-primary" onclick="loadList()">查询</button>
<button class="btn btn-outline" onclick="resetSearch()">重置</button>
<span style="flex:1"></span>
<button class="btn btn-green" onclick="exportExcel()">导出Excel</button>
<button class="btn btn-blue" onclick="document.getElementById('fileImport').click()">导入Excel</button>
<input type="file" id="fileImport" accept=".xls,.xlsx" style="display:none" onchange="importExcel(this)">
<button class="btn btn-outline" onclick="downloadTemplate()">下载模板</button>
<button class="btn btn-red" onclick="batchDelete()">删除选中</button>
<button class="btn btn-primary" onclick="openEdit(0)">+ 新增</button>
<span style="font-size:13px;color:#666;margin-left:8px" id="totalCount"></span>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th style="width:32px"><input type="checkbox" id="chkAll" onclick="toggleAll(this)"></th>
<th style="width:48px">序号</th>
<th style="width:130px">物料编号</th><th style="width:180px">物料名称</th><th style="width:120px">线边仓库存数</th><th style="width:110px">日期</th><th style="width:160px">更新时间</th><th style="width:130px">操作</th>
</tr>
</thead>
<tbody id="tbodyList"></tbody>
</table>
</div>
<div class="pagination" id="pagination"></div>
</div>
</div>
<div class="modal-overlay" id="editModal">
<div class="modal">
<div class="modal-header">
<h3 id="modalTitle">新增生产交付</h3>
<button class="modal-close" onclick="closeModal('editModal')">×</button>
</div>
<div class="modal-body">
<div class="form-grid">
<div class="form-group">
<label>物料编号 <span style="color:#ef4444">*</span></label>
<div class="input-with-picker">
<input type="text" id="fMaterialCode" placeholder="点击选择物料" readonly onclick="openMaterialPicker()">
<button type="button" class="picker-btn" onclick="openMaterialPicker()">🔍</button>
</div>
</div>
<div class="form-group">
<label>物料名称</label>
<input type="text" id="fMaterialName" placeholder="请输入物料名称">
</div>
<div class="form-group">
<label>线边仓库存数 <span style="color:#ef4444">*</span></label>
<input type="number" id="fLineSideStock" placeholder="0" step="0.01">
</div>
<div class="form-group">
<label>日期</label>
<input type="date" id="fStockDate">
</div>
</div>
<div class="modal-actions">
<button class="btn btn-outline" onclick="closeModal('editModal')">取消</button>
<button class="btn btn-primary" onclick="save()">保存</button>
</div>
</div>
</div>
</div>
<script>
var curId=0;
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
function api(url,method,data,cb){
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
if(data)opts.body=JSON.stringify(data);
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
cb&&cb(res);
}).catch(function(e){toast('请求失败:'+e.message,'error')});
}
function getApiUrl(){return '../../api/deliver/'}
function getFilters(){
var kw=document.getElementById('txtKeyword').value.trim();
var ds=document.getElementById('dateStart').value;
var de=document.getElementById('dateEnd').value;
return {kw:kw,ds:ds,de:de};
}
var curPage=1,curPageSize=50;
function loadList(page){
page=page||1;
curPage=page;
var f=getFilters();
var url=getApiUrl()+'GetProductionDeliveryList?keyword='+encodeURIComponent(f.kw)+'&dateStart='+encodeURIComponent(f.ds)+'&dateEnd='+encodeURIComponent(f.de)+'&page='+page+'&pageSize='+curPageSize;
api(url,'GET',null,function(res){
var rows=res.data||[];
var html='';
if(rows.length===0)html='<tr><td colspan="8" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
rows.forEach(function(r,i){
var seq=(curPage-1)*curPageSize+i+1;
html+='<tr>'+
'<td><input type="checkbox" class="chkRow" data-id="'+r.Id+'"></td>'+
'<td>'+seq+'</td>'+
'<td>'+r.MaterialCode+'</td>'+
'<td>'+r.MaterialName+'</td>'+
'<td>'+r.LineSideStock+'</td>'+
'<td>'+(r.StockDate||'')+'</td>'+
'<td>'+(r.UpdateTime||'')+'</td>'+
'<td style="white-space:nowrap">'+
'<button class="btn btn-primary" style="height:26px;padding:0 10px;font-size:11px" onclick="openEdit('+r.Id+')">编辑</button> '+
'<button class="btn btn-red" style="height:26px;padding:0 10px;font-size:11px" onclick="delOne('+r.Id+')">删除</button>'+
'</td></tr>';
});
document.getElementById('tbodyList').innerHTML=html;
document.getElementById('totalCount').textContent='共 '+res.total+' 条';
renderPagination(res.total,res.page);
});
}
function renderPagination(total,page){
var pages=Math.ceil(total/curPageSize)||1;
var sizeOpts=[20,50,100,200].map(function(s){
return '<option value="'+s+'"'+(s==curPageSize?' selected':'')+'>'+s+'</option>';
}).join('');
var html='<span>每页 <select onchange="changePageSize(this.value)">'+sizeOpts+'</select> 条</span>';
html+='<button '+(page<=1?'disabled':'')+' onclick="loadList(1)">首页</button>';
html+='<button '+(page<=1?'disabled':'')+' onclick="loadList('+(page-1)+')">上一页</button>';
var start=Math.max(1,page-2),end=Math.min(pages,page+2);
for(var i=start;i<=end;i++){
html+='<button class="'+(i==page?'active':'')+'" onclick="loadList('+i+')">'+i+'</button>';
}
html+='<button '+(page>=pages?'disabled':'')+' onclick="loadList('+(page+1)+')">下一页</button>';
html+='<button '+(page>=pages?'disabled':'')+' onclick="loadList('+pages+')">末页</button>';
html+='<span>第 '+page+' / '+pages+' 页,共 '+total+' 条</span>';
document.getElementById('pagination').innerHTML=html;
}
function changePageSize(v){
curPageSize=parseInt(v)||50;
loadList(1);
}
// 表头列宽左右拖动
function initColResize(){
var table=document.querySelector('.panel table');
if(!table)return;
var ths=table.querySelectorAll('thead th');
[].forEach.call(ths,function(th){
if(th.querySelector('.col-resizer'))return;
var grip=document.createElement('div');
grip.className='col-resizer';
th.appendChild(grip);
grip.addEventListener('mousedown',function(e){
e.preventDefault();e.stopPropagation();
var startX=e.clientX,startW=th.offsetWidth;
function onMove(ev){
var w=Math.max(40,startW+(ev.clientX-startX));
th.style.width=w+'px';
}
function onUp(){
document.removeEventListener('mousemove',onMove);
document.removeEventListener('mouseup',onUp);
}
document.addEventListener('mousemove',onMove);
document.addEventListener('mouseup',onUp);
});
});
}
function resetSearch(){
document.getElementById('txtKeyword').value='';
document.getElementById('dateStart').value='';
document.getElementById('dateEnd').value='';
loadList();
}
function openEdit(id){
curId=id;
document.getElementById('modalTitle').textContent=id>0?'编辑生产交付':'新增生产交付';
if(id>0){
api(getApiUrl()+'GetProductionDeliveryList?keyword=&page=1&pageSize=1','GET',null,function(res){
var rows=res.data||[];
var found=rows.find(function(r){return r.Id==id;});
if(found){
document.getElementById('fMaterialCode').value=found.MaterialCode;
document.getElementById('fMaterialName').value=found.MaterialName;
document.getElementById('fLineSideStock').value=found.LineSideStock;
document.getElementById('fStockDate').value=found.StockDate||'';
}
});
}else{
document.getElementById('fMaterialCode').value='';
document.getElementById('fMaterialName').value='';
document.getElementById('fLineSideStock').value='';
document.getElementById('fStockDate').value=new Date().toISOString().slice(0,10);
}
document.getElementById('editModal').classList.add('show');
}
function closeModal(id){
document.getElementById(id).classList.remove('show');
}
// ===== 物料开窗选择(与生产排程页一致) =====
var pkPage=1, pkPageSize=2000, pkTotal=0;
function openMaterialPicker(){
pkPage=1;
document.getElementById('materialPicker').classList.add('show');
doSearch();
}
function resetSearchPK(){
document.getElementById('pkCodeOp').value='包含';
document.getElementById('pkCodeVal').value='';
document.getElementById('pkNameOp').value='包含';
document.getElementById('pkNameVal').value='';
document.getElementById('pkFilterCode').value='';
document.getElementById('pkFilterName').value='';
document.getElementById('pkFilterSpec').value='';
document.getElementById('pkCheckAll').checked=false;
pkPage=1;
doSearch();
}
function doSearch(){
var codeOp=encodeURIComponent(document.getElementById('pkCodeOp').value);
var codeVal=document.getElementById('pkCodeVal').value.trim();
var nameOp=encodeURIComponent(document.getElementById('pkNameOp').value);
var nameVal=document.getElementById('pkNameVal').value.trim();
var fc=document.getElementById('pkFilterCode').value.trim().toLowerCase();
var fn=document.getElementById('pkFilterName').value.trim().toLowerCase();
var fs=document.getElementById('pkFilterSpec').value.trim().toLowerCase();
var url=getApiUrl()+'GetKingdeeMaterials?codeOp='+codeOp+'&codeVal='+encodeURIComponent(codeVal)+'&nameOp='+nameOp+'&nameVal='+encodeURIComponent(nameVal)+'&page='+pkPage+'&pageSize='+pkPageSize;
api(url,'GET',null,function(res){
var rows=res.data||[];
var html='';
rows.forEach(function(m){
if(fc && (m.code||'').toLowerCase().indexOf(fc)<0)return;
if(fn && (m.name||'').toLowerCase().indexOf(fn)<0)return;
if(fs && (m.spec||'').toLowerCase().indexOf(fs)<0)return;
html+='<tr onclick="selectMaterialRow(this)" data-code="'+m.code+'" data-name="'+m.name+'" data-spec="'+(m.spec||'')+'">'+
'<td class="col-check"><input type="checkbox" class="pkChk"></td>'+
'<td>'+m.code+'</td>'+
'<td>'+m.name+'</td>'+
'<td>'+(m.spec||'')+'</td>'+
'</tr>';
});
if(!html)html='<tr><td colspan="4" style="text-align:center;padding:30px;color:#bbb">暂无数据</td></tr>';
document.getElementById('pkBody').innerHTML=html;
pkTotal=res.total||0;
document.getElementById('pkTotal').textContent=pkTotal;
document.getElementById('pkPageSize').textContent=res.pageSize||pkPageSize;
renderPkPages(pkTotal,res.page||pkPage,res.pageSize||pkPageSize);
});
}
function renderPkPages(total,page,pageSize){
var pages=Math.ceil(total/pageSize);
var h='<button onclick="pkGoto('+(page-1)+')" '+(page<=1?'disabled':'')+'>‹</button>';
for(var i=1;i<=Math.min(pages,10);i++){
h+='<button class="'+(i==page?'active':'')+'" onclick="pkGoto('+i+')">'+i+'</button>';
}
if(pages>10)h+='<span style="padding:0 4px;">...</span><button class="'+(pages==page?'active':'')+'" onclick="pkGoto('+pages+')">'+pages+'</button>';
h+='<button onclick="pkGoto('+(page+1)+')" '+(page>=pages?'disabled':'')+'>›</button>';
document.getElementById('pkPages').innerHTML=h;
}
function pkGoto(p){
if(p<1)return;
var pages=Math.ceil(pkTotal/pkPageSize);
if(p>pages)return;
pkPage=p;
doSearch();
}
function toggleCheckAll(checked){
var cks=document.querySelectorAll('.pkChk');
for(var i=0;i<cks.length;i++)cks[i].checked=checked;
}
function selectMaterialRow(tr){
var cks=document.querySelectorAll('.pkChk');
cks.forEach(function(c){c.checked=false;});
var chk=tr.querySelector('.pkChk');
if(chk)chk.checked=true;
document.querySelectorAll('.picker-table tbody tr').forEach(function(r){r.classList.remove('selected');});
tr.classList.add('selected');
}
function addSelectedMaterial(){
var chks=document.querySelectorAll('.pkChk:checked');
if(chks.length===0){toast('请先勾选一条物料','error');return}
if(chks.length>1){toast('每次只能选择一个物料','error');return}
var tr=chks[0].parentElement.parentElement;
// 回填:编号+名称自动带出
document.getElementById('fMaterialCode').value=tr.getAttribute('data-code');
document.getElementById('fMaterialName').value=tr.getAttribute('data-name');
closeModal('materialPicker');
toast('已选择物料:'+tr.getAttribute('data-code'),'success');
}
function save(){
var code=document.getElementById('fMaterialCode').value.trim();
var name=document.getElementById('fMaterialName').value.trim();
var stock=document.getElementById('fLineSideStock').value;
var date=document.getElementById('fStockDate').value;
if(!code){toast('物料编号不能为空','error');return}
if(!stock && stock!=='0'){toast('线边仓库存数不能为空','error');return}
var data={MaterialCode:code,MaterialName:name,LineSideStock:stock,StockDate:date};
if(curId>0) data.Id=curId;
api(getApiUrl()+'SaveProductionDelivery','POST',data,function(res){
toast(res.message||'保存成功','success');
closeModal('editModal');
loadList();
});
}
function delOne(id){
if(!confirm('确定删除该记录?'))return;
api(getApiUrl()+'DeleteProductionDelivery','POST',{Ids:[id]},function(res){
toast(res.message||'删除成功','success');
loadList();
});
}
function toggleAll(el){
document.querySelectorAll('.chkRow').forEach(function(c){c.checked=el.checked});
}
function batchDelete(){
var ids=[];
document.querySelectorAll('.chkRow:checked').forEach(function(c){ids.push(parseInt(c.getAttribute('data-id')))});
if(ids.length===0){toast('请先选择要删除的记录','error');return}
if(!confirm('确定删除选中的 '+ids.length+' 条记录?'))return;
api(getApiUrl()+'DeleteProductionDelivery','POST',{Ids:ids},function(res){
toast(res.message||'删除成功','success');
loadList();
});
}
function downloadTemplate(){
var a=document.createElement('a');
a.href=getApiUrl()+'DownloadProductionDeliveryTemplate';
a.download='生产交付导入模板.xls';
a.style.display='none';
document.body.appendChild(a);
a.click();
setTimeout(function(){document.body.removeChild(a)},100);
}
function exportExcel(){
var f=getFilters();
var url=getApiUrl()+'ExportProductionDeliveryExcel?keyword='+encodeURIComponent(f.kw)+'&dateStart='+encodeURIComponent(f.ds)+'&dateEnd='+encodeURIComponent(f.de);
toast('正在导出,请稍候...','success');
fetch(url).then(function(r){return r.blob()}).then(function(blob){
var a=document.createElement('a');
a.href=URL.createObjectURL(blob);
a.download='生产交付_'+new Date().toISOString().slice(0,10)+'.xls';
a.click();
}).catch(function(e){toast('导出失败:'+e.message,'error')});
}
function importExcel(input){
var file=input.files[0];
if(!file)return;
var reader=new FileReader();
reader.onload=function(e){
var base64=e.target.result.split(',')[1];
api(getApiUrl()+'ImportProductionDelivery','POST',{FileContent:base64,FileName:file.name},function(res){
toast(res.message||'导入完成','success');
loadList();
});
};
reader.readAsDataURL(file);
input.value='';
}
// 初始化
loadList();
initColResize();
</script>
<!-- 公共导航栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>
@@ -0,0 +1,792 @@
<!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="../common/nav.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
.main-content{max-width:1500px;margin:0 auto;padding:16px 20px}
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:12px}
.toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
.toolbar input,.toolbar select{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.toolbar input:focus,.toolbar select:focus{border-color:#1a73e8}
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff}
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
.btn-primary:hover{opacity:.92}
.btn-green{background:#22c55e}
.btn-green:hover{opacity:.92}
.btn-red{background:#ef4444}
.btn-red:hover{opacity:.92}
.btn-blue{background:#3b82f6}
.btn-blue:hover{opacity:.92}
.btn-outline{background:#fff;color:#666;border:2px solid #e0e0e0}
.btn-outline:hover{border-color:#1a73e8;color:#1a73e8}
table{width:100%;border-collapse:collapse;font-size:13px}
thead th{background:#f8f9fa;color:#555;font-weight:600;padding:9px 12px;text-align:left;border:1px solid #999;border-bottom:2px solid #999;white-space:nowrap}
tbody td{padding:9px 12px;border:1px solid #ddd;color:#333}
tbody tr:hover{background:#f0f6ff}
/* 宽松:列表区留白 + 左右可滑动 */
.table-wrap{overflow-x:auto;overflow-y:auto;max-height:680px;border:1px solid #e2e8f0;border-radius:8px;background:#fff}
.table-wrap table{min-width:1480px}
.table-wrap thead th{position:sticky;top:0;z-index:2;background:#f8f9fa}
/* 固定列:序号 / 选中 / 操作 */
.col-num,.col-check,.col-op{position:sticky;left:0;z-index:3;background:#fff;box-shadow:1px 0 0 #e2e8f0}
.col-num{width:50px;text-align:center}
.col-check{width:44px;text-align:center}
.col-op{width:130px;text-align:center}
.col-num,.col-check input{cursor:pointer}
/* 行 hover 时固定列同步变色,避免横向滚动透出底色 */
.table-wrap tbody tr:hover .col-num,
.table-wrap tbody tr:hover .col-check,
.table-wrap tbody tr:hover .col-op{background:#f0f6ff}
.table-wrap tbody tr{cursor:pointer}
/* 批量操作栏 */
.batch-bar{display:flex;align-items:center;gap:10px;padding:10px 16px;background:#fef2f2;border:1px solid #fecaca;border-radius:8px;margin-top:10px;font-size:13px}
.badge{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:500}
.badge-success{background:#dcfce7;color:#166534}
.badge-warning{background:#fef3c7;color:#92400e}
.badge-info{background:#dbeafe;color:#1e40af}
.badge-muted{background:#f1f5f9;color:#64748b}
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
/* ===== 排程弹窗(铺满、宽屏、多列)===== */
.modal-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:999;justify-content:center;align-items:center;padding:24px}
body.with-sidebar:not(.sidebar-collapsed) .modal-overlay{padding-left:240px}
body.with-sidebar.sidebar-collapsed .modal-overlay{padding-left:60px}
.modal-overlay.show{display:flex}
.modal{background:#fff;border-radius:10px;width:1200px;max-width:96vw;height:88vh;display:flex;flex-direction:column;box-shadow:0 20px 60px rgba(0,0,0,.2);overflow:hidden}
.modal-header{padding:18px 24px;border-bottom:1px solid #e2e8f0;background:linear-gradient(135deg,#f8fafc,#f1f5f9);display:flex;align-items:center;justify-content:space-between;flex-shrink:0}
.modal-header h3{font-size:17px;color:#0f172a;font-weight:600;letter-spacing:.5px}
.modal-close{background:transparent;border:none;font-size:20px;color:#94a3b8;cursor:pointer;padding:4px 8px;line-height:1}
.modal-close:hover{color:#ef4444}
.modal-body{padding:20px 24px;flex:1;overflow-y:auto}
.modal-footer{padding:14px 24px;border-top:1px solid #e2e8f0;background:#f8fafc;display:flex;justify-content:flex-end;gap:8px;flex-shrink:0}
.form-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:16px}
.form-group{display:flex;flex-direction:column}
.form-group.full{grid-column:1/-1}
.form-group label{font-size:12px;color:#475569;font-weight:600;margin-bottom:6px}
.form-group label .req{color:#ef4444;margin-left:2px}
.form-group input,.form-group select{height:36px;padding:0 12px;border:2px solid #e2e8f0;border-radius:6px;font-size:13px;outline:none;background:#fff;transition:all .15s}
.form-group input:focus,.form-group select:focus{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}
.form-group input.readonly{background:#f1f5f9;color:#64748b;cursor:not-allowed}
.form-group input[readonly]{background:#f1f5f9;color:#64748b}
.input-with-picker{position:relative}
.input-with-picker input{padding-right:34px;cursor:pointer}
.input-with-picker .picker-btn{position:absolute;right:6px;top:50%;transform:translateY(-50%);width:24px;height:24px;border:none;background:transparent;color:#94a3b8;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;border-radius:4px}
.input-with-picker .picker-btn:hover{background:#f1f5f9;color:#1a73e8}
.section-divider{margin:24px 0 16px;padding:8px 12px;background:linear-gradient(90deg,#eff6ff,transparent);border-left:3px solid #3b82f6;color:#1e40af;font-size:13px;font-weight:600;border-radius:0 4px 4px 0}
/* 每日生产计划表 */
.daily-table{width:100%;border-collapse:collapse;font-size:12px;background:#fff;border-radius:6px;overflow:hidden}
.daily-table th{background:#f1f5f9;padding:8px 6px;border-bottom:1px solid #e2e8f0;font-weight:600;color:#64748b;white-space:nowrap}
.daily-table td{padding:6px;border-bottom:1px solid #f1f5f9;text-align:center}
.daily-table .weekend{background:#fafbfc;color:#cbd5e1}
.daily-table .weekend input{background:#fafbfc;color:#cbd5e1}
.daily-table input{width:90%;text-align:right;border:1px solid #e2e8f0;border-radius:4px;padding:5px 8px;font-size:12px;outline:none}
.daily-table input:focus{border-color:#3b82f6;box-shadow:0 0 0 2px rgba(59,130,246,.1)}
.daily-table tr:hover{background:#f8fafc}
.daily-scroll{overflow-x:auto;max-height:340px;border:1px solid #e2e8f0;border-radius:6px}
/* ===== 物料查询弹窗(仿金蝶) ===== */
#materialPicker{z-index:1100}
.picker-modal{width:1100px;max-width:95vw;height:80vh}
.picker-toolbar{padding:10px 16px;background:#f8fafc;border-bottom:1px solid #e2e8f0;display:flex;gap:10px;align-items:center;flex-shrink:0}
.picker-toolbar select,.picker-toolbar input{height:30px;padding:0 10px;border:1px solid #d1d5db;border-radius:4px;font-size:12px;outline:none;min-width:130px}
.picker-toolbar input{min-width:180px}
.picker-toolbar label{font-size:12px;color:#475569;margin-right:4px}
.picker-toolbar .cond-row{display:flex;gap:6px;align-items:center;margin-right:12px}
.picker-toolbar .remove-cond{color:#ef4444;background:transparent;border:none;cursor:pointer;font-size:14px;padding:0 4px;line-height:1}
.picker-toolbar .actions{margin-left:auto;display:flex;gap:8px}
.picker-toolbar .btn{height:30px;padding:0 14px;font-size:12px;border-radius:4px}
.picker-table-wrap{flex:1;overflow:auto}
.picker-table{width:100%;border-collapse:collapse;font-size:13px}
.picker-table thead th{position:sticky;top:0;z-index:1;background:#f1f5f9;color:#475569;font-weight:600;padding:9px 10px;text-align:left;border-bottom:2px solid #cbd5e1;white-space:nowrap}
.picker-table tbody td{padding:7px 10px;border-bottom:1px solid #f1f5f9;color:#334155}
.picker-table tbody tr:hover{background:#eff6ff;cursor:pointer}
.picker-table tbody tr.selected{background:#dbeafe}
.picker-table .col-check{width:36px;text-align:center}
.picker-table .filter-input{width:100%;padding:3px 6px;border:1px solid #e2e8f0;border-radius:3px;font-size:11px;margin-top:3px;outline:none}
.picker-table .filter-input:focus{border-color:#3b82f6}
.picker-pagination{padding:8px 16px;background:#f8fafc;border-top:1px solid #e2e8f0;display:flex;justify-content:space-between;align-items:center;font-size:12px;color:#64748b;flex-shrink:0}
.picker-pagination .pages{display:flex;gap:4px}
.picker-pagination .pages button{min-width:26px;height:26px;border:1px solid #d1d5db;background:#fff;border-radius:3px;cursor:pointer;font-size:12px;color:#475569}
.picker-pagination .pages button.active{background:#3b82f6;color:#fff;border-color:#3b82f6}
.picker-pagination .pages button:hover:not(.active){border-color:#3b82f6;color:#3b82f6}
/* 列表分页 */
.pagination{display:flex;justify-content:space-between;align-items:center;padding:10px 4px;border-top:1px solid #f0f0f0;font-size:12px;color:#666}
.pagination .btns{display:flex;gap:2px;flex-wrap:wrap}
.pagination .btns button,.pagination .size-btn{min-width:30px;height:26px;border:1px solid #e0e0e0;border-radius:4px;background:#fff;color:#555;cursor:pointer;font-size:12px;padding:0 8px}
.pagination .btns button:hover,.pagination .size-btn:hover{border-color:#1a73e8;color:#1a73e8}
.pagination .btns button.active,.pagination .size-btn.active{background:#1a73e8;color:#fff;border-color:#1a73e8}
.pagination .size-group{display:inline-flex;gap:2px;margin-left:8px}
</style>
</head>
<body>
<div id="sidebar"></div>
<div class="main-content">
<div class="panel">
<h3>生产计划排程 - 维护</h3>
<div class="toolbar">
<select id="selProduct" style="min-width:120px"><option value="">产品编码:全部</option></select>
<select id="selVersion" style="min-width:100px"><option value="">BOM版本:全部</option></select>
<select id="selProductType" style="min-width:120px"><option value="">产品类型:全部</option></select>
<select id="selStatus" style="min-width:100px">
<option value="">状态:全部</option>
<option value="待开始">待开始</option>
<option value="进行中">进行中</option>
<option value="已完成">已完成</option>
<option value="已暂停">已暂停</option>
</select>
<input type="text" id="txtKeyword" placeholder="搜索 产品编码 / 产品名称" style="width:200px">
<button class="btn btn-primary" onclick="searchList()">查询</button>
<button class="btn btn-outline" onclick="resetSearch()">重置</button>
<div style="flex:1"></div>
<button class="btn btn-outline" onclick="downloadTemplate()">📄 下载导入模板</button>
<button class="btn btn-green" onclick="triggerImport()">📥 导入Excel</button>
<button class="btn btn-primary" onclick="openAddModal()">+ 新建排程任务</button>
</div>
<div class="table-wrap">
<div class="batch-bar" id="batchBar" style="display:none">
<span>已选中 <b id="selCount">0</b> 项</span>
<button class="btn btn-red" onclick="delSelected()">🗑 删除选中</button>
<button class="btn btn-outline" onclick="clearSelection()">取消选择</button>
</div>
<table>
<thead>
<tr>
<th class="col-num">序号</th>
<th class="col-check"><input type="checkbox" id="chkAll" onchange="toggleCheckAllRows(this.checked)"></th>
<th class="col-op">操作</th>
<th>产品编码</th><th>BOM版本</th><th>产品名称</th><th>产品类型</th>
<th>工厂</th><th>区域</th><th>国家</th>
<th>计划开始日</th><th>计划完成日</th><th>总产量</th><th>状态</th>
</tr>
</thead>
<tbody id="tbodyList"></tbody>
</table>
</div>
<div class="pagination" id="pagination" style="display:none">
<div><span>共 <em id="totalCnt">0</em> 条</span><span class="size-group" id="sizeBtns"></span></div>
<div class="btns" id="pageBtns"></div>
</div>
</div>
</div>
<!-- 排程编辑弹窗 -->
<div class="modal-overlay" id="editModal">
<div class="modal">
<div class="modal-header">
<h3 id="modalTitle">新建排程任务</h3>
<button class="modal-close" onclick="closeModal('editModal')">×</button>
</div>
<div class="modal-body">
<div class="form-grid">
<div class="form-group">
<label>产品编码 <span class="req">*</span></label>
<div class="input-with-picker">
<input type="text" id="fProductCode" placeholder="点击右侧图标选择产品" readonly>
<button type="button" class="picker-btn" onclick="openMaterialPicker()" title="选择产品">🔍</button>
</div>
</div>
<div class="form-group">
<label>BOM版本 <span class="req">*</span></label>
<input type="text" id="fBOMVersion" placeholder="选产品后自动带出,无BOM版本可手动输入">
</div>
<div class="form-group">
<label>产品名称</label>
<input type="text" id="fProductName" class="readonly" readonly>
</div>
<div class="form-group">
<label>产品类型</label>
<input type="text" id="fProductType" placeholder="如:标准机 / 定制机 / 样机(人为维护)">
</div>
<div class="form-group">
<label>工厂</label>
<input type="text" id="fFactory" placeholder="工厂">
</div>
<div class="form-group">
<label>区域</label>
<input type="text" id="fRegion" placeholder="区域">
</div>
<div class="form-group">
<label>国家</label>
<input type="text" id="fCountry" placeholder="国家">
</div>
<div class="form-group">
<label>计划开始日 <span class="req">*</span></label>
<input type="date" id="fPlanStart" onchange="genDaily()">
</div>
<div class="form-group">
<label>计划完成日 <span class="req">*</span></label>
<input type="date" id="fPlanEnd" onchange="genDaily()">
</div>
<div class="form-group">
<label>状态 <span class="req">*</span></label>
<select id="fStatus">
<option value="待开始">待开始</option>
<option value="进行中" selected>进行中</option>
<option value="已完成">已完成</option>
<option value="已暂停">已暂停</option>
</select>
</div>
<div class="form-group">
<label>备注</label>
<input type="text" id="fRemark" placeholder="排程调整原因...">
</div>
</div>
<div class="section-divider">每日生产计划(计划人员只维护成品每日产量,周末自动标记无产量)</div>
<div class="daily-scroll">
<table class="daily-table" id="dailyTable">
<thead id="dailyHeader"><tr><th>日期</th><th>星期</th><th>日产量</th></tr></thead>
<tbody id="dailyBody"></tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-outline" onclick="closeModal('editModal')">取消</button>
<button class="btn btn-primary" onclick="saveSchedule()">保存</button>
</div>
</div>
</div>
<!-- 物料查询弹窗(仿金蝶数据查询) -->
<div class="modal-overlay" id="materialPicker">
<div class="modal picker-modal">
<div class="modal-header">
<h3>📋 物料查询(数据查询)</h3>
<button class="modal-close" onclick="closeModal('materialPicker')">×</button>
</div>
<div class="picker-toolbar">
<div class="cond-row">
<label>物料代码</label>
<select id="pkCodeOp" style="width:90px">
<option>包含</option><option>不包含</option><option>等于</option><option>不等于</option><option>开始于</option><option>结束于</option><option>为空</option><option>不为空</option>
</select>
<input type="text" id="pkCodeVal" placeholder="输入物料代码" style="min-width:160px">
</div>
<div class="cond-row">
<label>物料名称</label>
<select id="pkNameOp" style="width:90px">
<option>包含</option><option>不包含</option><option>等于</option><option>不等于</option><option>开始于</option><option>结束于</option><option>为空</option><option>不为空</option>
</select>
<input type="text" id="pkNameVal" placeholder="输入物料名称" style="min-width:160px">
</div>
<div class="actions">
<button class="btn btn-primary" onclick="doSearch()">🔍 搜索</button>
<button class="btn btn-outline" onclick="resetSearchPK()">重置</button>
<button class="btn btn-green" onclick="addSelectedMaterial()">添加</button>
</div>
</div>
<div class="picker-table-wrap">
<table class="picker-table">
<thead>
<tr>
<th class="col-check"><input type="checkbox" id="pkCheckAll" onchange="toggleCheckAll(this.checked)"></th>
<th>物料代码 <input class="filter-input" id="pkFilterCode" oninput="doSearch()"></th>
<th>物料名称 <input class="filter-input" id="pkFilterName" oninput="doSearch()"></th>
<th>规格型号 <input class="filter-input" id="pkFilterSpec" oninput="doSearch()"></th>
</tr>
</thead>
<tbody id="pkBody"></tbody>
</table>
</div>
<div class="picker-pagination">
<span>共 <span id="pkTotal">0</span> 条 每页 <span id="pkPageSize">2000</span> 条</span>
<div class="pages" id="pkPages"></div>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
var curId=0;
var options=null;
var dailyData=[];
var pkPage=1, pkPageSize=2000;
var pkTotal=0;
var selectedMaterial=null; // {code, name, spec, bomVersion}
var curPage=1, pageSize=20, totalCnt=0;
var pageSizeOptions=[20,50,100,200];
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
function api(url,method,data,cb){
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
if(data)opts.body=JSON.stringify(data);
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
cb&&cb(res);
}).catch(function(e){toast('请求失败:'+e.message,'error')});
}
function getApiUrl(){return '../../api/deliver/'}
function loadOptions(cb){
api(getApiUrl()+'GetOptions','GET',null,function(res){
options=res.data||{};
var h='<option value="">产品编码:全部</option>';
(options.products||[]).forEach(function(p){h+='<option value="'+p+'">'+p+'</option>'});
document.getElementById('selProduct').innerHTML=h;
var h2='<option value="">BOM版本:全部</option>';
(options.versions||[]).forEach(function(v){h2+='<option value="'+v+'">'+v+'</option>'});
document.getElementById('selVersion').innerHTML=h2;
var h3='<option value="">产品类型:全部</option>';
(options.productTypes||[]).forEach(function(t){h3+='<option value="'+t+'">'+t+'</option>'});
document.getElementById('selProductType').innerHTML=h3;
cb&&cb();
});
}
function searchList(){curPage=1;loadList()}
function loadList(){
var p=document.getElementById('selProduct').value;
var v=document.getElementById('selVersion').value;
var t=document.getElementById('selProductType').value;
var s=document.getElementById('selStatus').value;
var kw=document.getElementById('txtKeyword').value.trim();
var url=getApiUrl()+'GetScheduleList?productCode='+encodeURIComponent(p)+'&bomVersion='+encodeURIComponent(v)+'&productType='+encodeURIComponent(t)+'&status='+encodeURIComponent(s)+'&keyword='+encodeURIComponent(kw)+'&page='+curPage+'&pageSize='+pageSize;
api(url,'GET',null,function(res){
var rows=res.data||[];
totalCnt=res.total||0;
var html='';
if(rows.length===0)html='<tr><td colspan="14" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
rows.forEach(function(r,idx){
var stClass=r.Status=='进行中'?'badge-success':(r.Status=='待开始'?'badge-warning':(r.Status=='已完成'?'badge-info':'badge-muted'));
var rowNo=(curPage-1)*pageSize+idx+1;
html+='<tr data-id="'+r.Id+'" onclick="openEdit('+r.Id+')">'+
'<td class="col-num">'+rowNo+'</td>'+
'<td class="col-check" onclick="event.stopPropagation()"><input type="checkbox" class="rowChk" onchange="updateSelCount()"></td>'+
'<td class="col-op" style="white-space:nowrap" onclick="event.stopPropagation()">'+
'<button class="btn btn-blue" style="height:26px;padding:0 10px;font-size:11px" onclick="recalc('+r.Id+')">重算需求</button>'+
'</td>'+
'<td>'+r.ProductCode+'</td>'+
'<td><span class="badge badge-info">'+r.BOMVersion+'</span></td>'+
'<td>'+r.ProductName+'</td>'+
'<td>'+(r.ProductType||'')+'</td>'+
'<td>'+(r.Factory||'')+'</td>'+
'<td>'+(r.Region||'')+'</td>'+
'<td>'+(r.Country||'')+'</td>'+
'<td>'+r.PlanStartDate+'</td>'+
'<td>'+r.PlanEndDate+'</td>'+
'<td>'+r.TotalOutput+'</td>'+
'<td><span class="badge '+stClass+'">'+r.Status+'</span></td>'+
'</tr>';
});
document.getElementById('tbodyList').innerHTML=html;
renderPagination();
});
}
function resetSearch(){
document.getElementById('selProduct').value='';
document.getElementById('selVersion').value='';
document.getElementById('selProductType').value='';
document.getElementById('selStatus').value='';
document.getElementById('txtKeyword').value='';
curPage=1;
loadList();
}
// ===== 列表分页 =====
function renderPagination(){
var tp=Math.ceil(totalCnt/pageSize)||1;
var pc=document.getElementById('pagination');
if(totalCnt<=pageSize){pc.style.display='none';return}
pc.style.display='flex';
document.getElementById('totalCnt').textContent=totalCnt;
document.getElementById('sizeBtns').innerHTML=pageSizeOptions.map(function(s){return '<button class="size-btn'+(s===pageSize?' active':'')+'" onclick="setPageSize('+s+')">'+s+'条</button>'}).join('');
var pb=document.getElementById('pageBtns');
if(tp<=1){pb.innerHTML='';return}
var h='<button '+(curPage<=1?'disabled':'')+' onclick="goPage(1)">首页</button><button '+(curPage<=1?'disabled':'')+' onclick="goPage('+(curPage-1)+')">‹</button>';
for(var i=Math.max(1,curPage-2);i<=Math.min(tp,curPage+2);i++)h+='<button class="'+(i===curPage?'active':'')+'" onclick="goPage('+i+')">'+i+'</button>';
h+='<button '+(curPage>=tp?'disabled':'')+' onclick="goPage('+(curPage+1)+')">›</button><button '+(curPage>=tp?'disabled':'')+' onclick="goPage('+tp+')">末页</button>';
pb.innerHTML=h;
}
function goPage(p){
if(p<1||p>Math.ceil(totalCnt/pageSize))return;
curPage=p;
loadList();
}
function setPageSize(s){
pageSize=s;curPage=1;loadList();
}
function openAddModal(){
curId=0;
document.getElementById('modalTitle').textContent='新建排程任务';
document.getElementById('fProductCode').value='';
document.getElementById('fBOMVersion').value='';
document.getElementById('fProductName').value='';
document.getElementById('fProductType').value='';
document.getElementById('fFactory').value='';
document.getElementById('fRegion').value='';
document.getElementById('fCountry').value='';
document.getElementById('fPlanStart').value='';
document.getElementById('fPlanEnd').value='';
document.getElementById('fStatus').value='进行中';
document.getElementById('fRemark').value='';
selectedMaterial=null;
dailyData=[];
renderDaily();
document.getElementById('editModal').classList.add('show');
}
// 打开物料查询弹窗
function openMaterialPicker(){
pkPage=1;
document.getElementById('materialPicker').classList.add('show');
doSearch();
}
// 重置查询条件
function resetSearchPK(){
document.getElementById('pkCodeOp').value='包含';
document.getElementById('pkCodeVal').value='';
document.getElementById('pkNameOp').value='包含';
document.getElementById('pkNameVal').value='';
document.getElementById('pkFilterCode').value='';
document.getElementById('pkFilterName').value='';
document.getElementById('pkFilterSpec').value='';
document.getElementById('pkCheckAll').checked=false;
pkPage=1;
doSearch();
}
// 搜索物料
function doSearch(){
var codeOp=encodeURIComponent(document.getElementById('pkCodeOp').value);
var codeVal=document.getElementById('pkCodeVal').value.trim();
var nameOp=encodeURIComponent(document.getElementById('pkNameOp').value);
var nameVal=document.getElementById('pkNameVal').value.trim();
// 列表内过滤(叠加在服务器条件之上)
var fc=document.getElementById('pkFilterCode').value.trim().toLowerCase();
var fn=document.getElementById('pkFilterName').value.trim().toLowerCase();
var fs=document.getElementById('pkFilterSpec').value.trim().toLowerCase();
var url=getApiUrl()+'GetKingdeeMaterials?codeOp='+codeOp+'&codeVal='+encodeURIComponent(codeVal)+'&nameOp='+nameOp+'&nameVal='+encodeURIComponent(nameVal)+'&page='+pkPage+'&pageSize='+pkPageSize;
api(url,'GET',null,function(res){
var rows=res.data||[];
var html='';
rows.forEach(function(m){
if(fc && (m.code||'').toLowerCase().indexOf(fc)<0)return;
if(fn && (m.name||'').toLowerCase().indexOf(fn)<0)return;
if(fs && (m.spec||'').toLowerCase().indexOf(fs)<0)return;
html+='<tr onclick="selectMaterialRow(this)" data-code="'+m.code+'" data-name="'+m.name+'" data-spec="'+(m.spec||'')+'" data-bom="'+m.bomVersion+'">'+
'<td class="col-check"><input type="checkbox" class="pkChk"></td>'+
'<td>'+m.code+'</td>'+
'<td>'+m.name+'</td>'+
'<td>'+(m.spec||'')+'</td>'+
'</tr>';
});
if(!html)html='<tr><td colspan="4" style="text-align:center;padding:30px;color:#bbb">暂无数据</td></tr>';
document.getElementById('pkBody').innerHTML=html;
pkTotal=res.total||0;
document.getElementById('pkTotal').textContent=pkTotal;
document.getElementById('pkPageSize').textContent=res.pageSize||pkPageSize;
renderPkPages(pkTotal,res.page||pkPage,res.pageSize||pkPageSize);
});
}
function renderPkPages(total,page,pageSize){
var pages=Math.ceil(total/pageSize);
var h='<button onclick="pkGoto('+(page-1)+')" '+(page<=1?'disabled':'')+'>‹</button>';
for(var i=1;i<=Math.min(pages,10);i++){
h+='<button class="'+(i==page?'active':'')+'" onclick="pkGoto('+i+')">'+i+'</button>';
}
if(pages>10)h+='<span style="padding:0 4px;">...</span><button class="'+(pages==page?'active':'')+'" onclick="pkGoto('+pages+')">'+pages+'</button>';
h+='<button onclick="pkGoto('+(page+1)+')" '+(page>=pages?'disabled':'')+'>›</button>';
document.getElementById('pkPages').innerHTML=h;
}
function pkGoto(p){
if(p<1)return;
var pages=Math.ceil(pkTotal/pkPageSize);
if(p>pages)return;
pkPage=p;
doSearch();
}
function toggleCheckAll(checked){
var cks=document.querySelectorAll('.pkChk');
for(var i=0;i<cks.length;i++)cks[i].checked=checked;
}
function selectMaterialRow(tr){
var cks=document.querySelectorAll('.pkChk');
cks.forEach(function(c){c.checked=false;});
cks.forEach(function(c){if(c.parentElement.parentElement===tr)c.checked=true;});
var chk=tr.querySelector('.pkChk');
if(chk)chk.checked=true;
document.querySelectorAll('.picker-table tbody tr').forEach(function(r){r.classList.remove('selected');});
tr.classList.add('selected');
// 双击行直接添加(提升体验)
// 单击选中,多选/添加走按钮
}
function addSelectedMaterial(){
var chks=document.querySelectorAll('.pkChk:checked');
if(chks.length===0){toast('请先勾选一条物料','error');return}
if(chks.length>1){toast('每次只能选择一个产品','error');return}
var tr=chks[0].parentElement.parentElement;
selectedMaterial={
code:tr.getAttribute('data-code'),
name:tr.getAttribute('data-name'),
spec:tr.getAttribute('data-spec'),
bomVersion:tr.getAttribute('data-bom')||''
};
// 回填到排程表单
document.getElementById('fProductCode').value=selectedMaterial.code;
document.getElementById('fBOMVersion').value=selectedMaterial.bomVersion;
document.getElementById('fProductName').value=selectedMaterial.name;
closeModal('materialPicker');
toast('已选择产品:'+selectedMaterial.code+(selectedMaterial.bomVersion?('(BOM版本:'+selectedMaterial.bomVersion+')'):''),'success');
}
function openEdit(id){
api(getApiUrl()+'GetScheduleDetail?id='+id,'GET',null,function(res){
if(!res.success||!res.data){toast('未找到记录','error');return}
var d=res.data;
curId=d.Id;
document.getElementById('modalTitle').textContent='编辑排程任务 - '+d.ProductCode;
document.getElementById('fProductCode').value=d.ProductCode||'';
document.getElementById('fBOMVersion').value=d.BOMVersion||'';
document.getElementById('fProductName').value=d.ProductName||'';
document.getElementById('fProductType').value=d.ProductType||'';
document.getElementById('fFactory').value=d.Factory||'';
document.getElementById('fRegion').value=d.Region||'';
document.getElementById('fCountry').value=d.Country||'';
document.getElementById('fPlanStart').value=d.PlanStartDate||'';
document.getElementById('fPlanEnd').value=d.PlanEndDate||'';
document.getElementById('fStatus').value=d.Status||'待开始';
document.getElementById('fRemark').value=d.Remark||'';
selectedMaterial={code:d.ProductCode,name:d.ProductName,bomVersion:d.BOMVersion};
dailyData=(d.daily||[]).map(function(x){return {date:x.PlanDate,output:x.DailyOutput||'0'}});
renderDaily();
document.getElementById('editModal').classList.add('show');
});
}
function genDaily(){
var start=document.getElementById('fPlanStart').value;
var end=document.getElementById('fPlanEnd').value;
if(!start||!end)return;
if(end<start){toast('计划完成日不能早于开始日','error');return}
var dates=[];
var cur=new Date(start);
var last=new Date(end);
while(cur<=last){
dates.push({date:formatDate(cur),output:''});
cur.setDate(cur.getDate()+1);
}
dailyData=dates;
renderDaily();
}
function formatDate(d){
var y=d.getFullYear(),m=('0'+(d.getMonth()+1)).slice(-2),dd=('0'+d.getDate()).slice(-2);
return y+'-'+m+'-'+dd;
}
function renderDaily(){
var header='<tr><th>日期</th><th>星期</th><th>日产量</th></tr>';
var body='';
dailyData.forEach(function(item,i){
var d=new Date(item.date);
var week=['日','一','二','三','四','五','六'][d.getDay()];
var isWeekend=(d.getDay()==0||d.getDay()==6);
var cls=isWeekend?'weekend':'';
body+='<tr class="'+cls+'">'+
'<td>'+item.date+'</td>'+
'<td>周'+week+'</td>'+
'<td><input type="number" data-idx="'+i+'" value="'+item.output+'" oninput="updateOutput(this)"></td>'+
'</tr>';
});
document.getElementById('dailyHeader').innerHTML=header;
document.getElementById('dailyBody').innerHTML=body;
}
function updateOutput(el){
var idx=el.getAttribute('data-idx');
dailyData[idx].output=el.value;
}
function saveSchedule(){
var data={
Id:curId,
ProductCode:document.getElementById('fProductCode').value.trim(),
BOMVersion:document.getElementById('fBOMVersion').value.trim(),
ProductName:document.getElementById('fProductName').value.trim(),
ProductType:document.getElementById('fProductType').value.trim(),
Factory:document.getElementById('fFactory').value.trim(),
Region:document.getElementById('fRegion').value.trim(),
Country:document.getElementById('fCountry').value.trim(),
PlanStartDate:document.getElementById('fPlanStart').value,
PlanEndDate:document.getElementById('fPlanEnd').value,
Status:document.getElementById('fStatus').value,
Remark:document.getElementById('fRemark').value,
CreateUser:(function(){try{var u=JSON.parse(sessionStorage.getItem('gx_user'));return u.userId||''}catch(e){return ''}})()
};
if(!data.ProductCode){toast('请先选择产品编码','error');return}
if(!data.BOMVersion){toast('所选产品没有BOM版本,请在物料查询中选择已建立BOM的物料','error');return}
if(!data.PlanStartDate||!data.PlanEndDate){toast('请选择计划开始日和完成日','error');return}
// 保存前从DOM同步最新输入值,确保oninput/onchange都能捕获
var inputs=document.querySelectorAll('#dailyBody input[type="number"]');
inputs.forEach(function(el){updateOutput(el)});
data.daily=dailyData.filter(function(x){return x.output&&parseFloat(x.output)>0}).map(function(x){return {PlanDate:x.date,DailyOutput:x.output}});
// 关闭按钮防止重复提交
var saveBtn=document.querySelector('.modal-footer .btn-primary');
if(saveBtn)saveBtn.disabled=true;
try{
api(getApiUrl()+'SaveSchedule','POST',data,function(res){
if(saveBtn)saveBtn.disabled=false;
if(res.success){toast('排程保存成功,已自动登记到BOM主数据','success');closeModal('editModal');loadList()}
});
}catch(e){if(saveBtn)saveBtn.disabled=false;}
}
// 下载导入模板
function downloadTemplate(){
var a=document.createElement('a');
a.href=getApiUrl()+'DownloadScheduleTemplate';
a.download='生产排程导入模板.xls';
a.style.display='none';
document.body.appendChild(a);
a.click();
setTimeout(function(){document.body.removeChild(a)},100);
}
function recalc(id){
if(!confirm('确认重新计算该排程的物料需求?'))return;
api(getApiUrl()+'RecalcSchedule','POST',{ScheduleId:id},function(res){
if(res.success){showRecalcProgress(id)}
else if(res.message&&res.message.indexOf('正在重算')>=0){showRecalcProgress(id)}
});
}
// 显示重算进度条并轮询后端进度
function showRecalcProgress(id){
var modal=document.getElementById('recalcModal');
if(!modal){
modal=document.createElement('div');
modal.id='recalcModal';
modal.style.cssText='position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.45);z-index:99999;display:none;align-items:center;justify-content:center;';
modal.innerHTML=
'<div style="background:#fff;border-radius:10px;padding:26px 32px;width:440px;box-shadow:0 8px 30px rgba(0,0,0,0.25);">'+
'<h4 style="margin:0 0 18px;font-size:16px;color:#303133;">物料需求重算中</h4>'+
'<div style="height:10px;background:#ebeef5;border-radius:5px;overflow:hidden;">'+
'<div id="recalcBar" style="height:100%;width:0%;background:linear-gradient(90deg,#409eff,#79bbff);border-radius:5px;transition:width 0.5s;"></div></div>'+
'<div style="margin-top:12px;font-size:13px;color:#606266;display:flex;justify-content:space-between;">'+
'<span id="recalcStage">准备中...</span><span id="recalcPercent" style="font-weight:bold;color:#409eff;">0%</span></div>'+
'<div id="recalcMsg" style="margin-top:10px;font-size:12px;color:#909399;"></div>'+
'</div>';
document.body.appendChild(modal);
}
modal.style.display='flex';
document.getElementById('recalcBar').style.width='0%';
document.getElementById('recalcPercent').textContent='0%';
document.getElementById('recalcStage').textContent='准备中...';
document.getElementById('recalcMsg').textContent='';
var timer=setInterval(function(){
fetch(getApiUrl()+'GetRecalcProgress?scheduleId='+id,{method:'GET'})
.then(function(r){return r.json()})
.then(function(res){
if(!res||res.success===false){clearInterval(timer);hideRecalcModal();toast((res&&res.message)||'获取进度失败','error');return;}
document.getElementById('recalcBar').style.width=res.percent+'%';
document.getElementById('recalcPercent').textContent=res.percent+'%';
document.getElementById('recalcStage').textContent=res.stage||'';
document.getElementById('recalcMsg').textContent=res.message||'';
if(res.status==='success'){
clearInterval(timer);
setTimeout(function(){hideRecalcModal();toast(res.message||'重算完成','success');loadList();},600);
}else if(res.status==='error'){
clearInterval(timer);
setTimeout(function(){hideRecalcModal();toast(res.message||'重算失败','error');},600);
}
})
.catch(function(e){clearInterval(timer);hideRecalcModal();toast('获取进度失败:'+e.message,'error');});
},1000);
}
function hideRecalcModal(){
var modal=document.getElementById('recalcModal');
if(modal)modal.style.display='none';
}
function delSchedule(id){
if(!confirm('确认删除该排程?相关需求明细将一并删除'))return;
api(getApiUrl()+'DeleteSchedule','POST',{Id:id},function(res){
if(res.success){toast('删除成功','success');loadList()}
});
}
// ===== 列表多选 / 批量删除 =====
function getCheckedIds(){
var ids=[];
document.querySelectorAll('#tbodyList .rowChk:checked').forEach(function(c){
var tr=c.closest('tr');
if(tr&&tr.dataset.id)ids.push(Number(tr.dataset.id));
});
return ids;
}
function toggleCheckAllRows(checked){
document.querySelectorAll('#tbodyList .rowChk').forEach(function(c){c.checked=checked;});
updateSelCount();
}
function updateSelCount(){
var ids=getCheckedIds();
var bar=document.getElementById('batchBar');
if(ids.length>0){
bar.style.display='flex';
document.getElementById('selCount').textContent=ids.length;
}else{
bar.style.display='none';
}
}
function clearSelection(){
document.querySelectorAll('#tbodyList .rowChk').forEach(function(c){c.checked=false;});
updateSelCount();
}
function delSelected(){
var ids=getCheckedIds();
if(ids.length===0){toast('请选择要删除的行','error');return}
if(!confirm('确认批量删除选中的 '+ids.length+' 条排程?'))return;
api(getApiUrl()+'DeleteSchedule','POST',{Ids:ids},function(res){
if(res.success){toast('批量删除完成','success');loadList()}
});
}
function triggerImport(){
var input=document.createElement('input');
input.type='file';
input.accept='.xls,.xlsx';
input.onchange=function(){
var file=input.files[0];
if(!file)return;
var reader=new FileReader();
reader.onload=function(){
var base64=reader.result.split(',')[1];
api(getApiUrl()+'ImportScheduleExcel','POST',{FileName:file.name,FileContent:base64},function(res){
if(res.success){toast(res.message,'success');loadList()}
});
};
reader.readAsDataURL(file);
};
input.click();
}
function closeModal(id){document.getElementById(id).classList.remove('show')}
loadOptions(function(){loadList()});
</script>
<!-- 公共侧边栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>
@@ -0,0 +1,325 @@
<!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="../common/nav.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
.main-content{max-width:100%;margin:0 auto;padding:16px 20px}
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:4px}
.panel .sub{font-size:12px;color:#94a3b8;margin-bottom:12px}
.toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
.toolbar select,.toolbar input{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
.toolbar select:focus,.toolbar input:focus{border-color:#1a73e8}
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff}
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
.btn-primary:hover{opacity:.92}
.btn-outline{background:#fff;color:#666;border:2px solid #e0e0e0}
.btn-outline:hover{border-color:#1a73e8;color:#1a73e8}
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
.badge{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:500}
.badge-success{background:#dcfce7;color:#166534}
.badge-warning{background:#fef3c7;color:#92400e}
.badge-info{background:#dbeafe;color:#1e40af}
.badge-muted{background:#f1f5f9;color:#64748b}
/* ===== 看板:左侧固定信息列 + 右侧横向日期甘特 ===== */
.board-wrap{overflow:auto;border:1px solid #e2e8f0;border-radius:8px;background:#fff;max-height:75vh}
.board-table{border-collapse:separate;border-spacing:0;font-size:12px;min-width:100%}
.board-table thead th{position:sticky;top:0;z-index:4;background:#f8f9fa;color:#555;font-weight:600;padding:9px 10px;text-align:center;border-bottom:2px solid #cbd5e1;border-right:1px solid #e2e8f0;white-space:nowrap}
.board-table tbody td{padding:7px 10px;border-bottom:1px solid #f1f5f9;border-right:1px solid #f1f5f9;color:#334155;text-align:center}
.board-table tbody tr:hover{background:#f0f6ff}
/* 左侧信息列固定 */
.col-fix1{position:sticky;left:0;z-index:3;background:#fff;text-align:left!important;min-width:110px;box-shadow:1px 0 0 #e2e8f0}
thead .col-fix1{background:#f8f9fa;z-index:5}
.col-fix2{position:sticky;left:110px;z-index:3;background:#fff;text-align:left!important;min-width:130px;box-shadow:1px 0 0 #e2e8f0}
thead .col-fix2{background:#f8f9fa;z-index:5}
.col-fix3{position:sticky;left:240px;z-index:3;background:#fff;text-align:left!important;min-width:150px;box-shadow:1px 0 0 #e2e8f0}
thead .col-fix3{background:#f8f9fa;z-index:5}
.col-fix4{position:sticky;left:390px;z-index:3;background:#fff;text-align:left!important;min-width:150px;box-shadow:1px 0 0 #e2e8f0}
thead .col-fix4{background:#f8f9fa;z-index:5}
.board-table tbody tr:hover .col-fix1,
.board-table tbody tr:hover .col-fix2,
.board-table tbody tr:hover .col-fix3,
.board-table tbody tr:hover .col-fix4{background:#f0f6ff}
/* 合计行 */
.board-table tbody tr.total-row{background:#fef3c7;font-weight:600}
.board-table tbody tr.total-row td{color:#92400e}
.board-table tbody tr.type-row{background:#f1f5f9;font-weight:600}
.board-table tbody tr.type-row td{color:#475569}
/* 日期格子 */
.cell-date{text-align:center;padding:4px 2px;min-width:44px}
.cell-date .day{font-size:10px;color:#94a3b8;display:block;margin-bottom:2px}
.cell-date .qty{display:inline-block;min-width:30px;padding:2px 6px;border-radius:4px;font-size:12px;font-weight:600;color:#fff;background:transparent}
.cell-date.has .qty{background:linear-gradient(135deg,#3b82f6,#2563eb)}
.cell-date.today{background:#fef9c3}
.weekend{background:#fafbfc}
.legend{display:flex;gap:16px;align-items:center;font-size:12px;color:#64748b;margin-top:8px}
.legend .dot{display:inline-block;width:12px;height:12px;border-radius:3px;margin-right:4px;vertical-align:middle}
.legend .dot.blue{background:#3b82f6}
.legend .dot.yellow{background:#fef9c3;border:1px solid #eab308}
</style>
</head>
<body>
<div id="sidebar"></div>
<div class="main-content">
<div class="panel">
<h3>生产计划排程 - 看板</h3>
<div class="sub">横向展示各排程在每日的产量分布(数据来源:生产计划排程)</div>
<div class="toolbar">
<select id="selFactory" style="min-width:120px"><option value="">工厂:全部</option></select>
<select id="selProductType" style="min-width:120px"><option value="">产品类型:全部</option></select>
<select id="selRegion" style="min-width:120px"><option value="">区域:全部</option></select>
<select id="selCountry" style="min-width:120px"><option value="">国家:全部</option></select>
<select id="selStatus" style="min-width:100px">
<option value="">状态:全部</option>
<option value="待开始">待开始</option>
<option value="进行中">进行中</option>
<option value="已完成">已完成</option>
<option value="已暂停">已暂停</option>
</select>
<input type="text" id="txtKeyword" placeholder="搜索 产品编码 / 产品名称" style="width:200px">
<button class="btn btn-primary" onclick="renderBoard()">查询</button>
<button class="btn btn-outline" onclick="resetFilter()">重置</button>
<div style="flex:1"></div>
<button class="btn btn-outline" onclick="location.reload()">🔄 刷新</button>
</div>
<div class="board-wrap">
<table class="board-table" id="boardTable">
<thead id="boardHead"></thead>
<tbody id="boardBody"></tbody>
</table>
</div>
<div class="legend">
<span><span class="dot blue"></span>有排产量</span>
<span><span class="dot yellow"></span>今天</span>
<span id="legendTotal"></span>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
var boardData=[];
var dateList=[];
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
function api(url,method,data,cb){
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
if(data)opts.body=JSON.stringify(data);
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
cb&&cb(res);
}).catch(function(e){toast('请求失败:'+e.message,'error')});
}
function getApiUrl(){return '../../api/deliver/'}
// 生成本月的所有日期(yyyy-MM-dd,1号到月末)
function buildMonthDates(){
var arr=[];
var now=new Date();
var y=now.getFullYear(),m=now.getMonth();
var first=new Date(y,m,1);
var last=new Date(y,m+1,0); // 下月0号 = 本月最后一天
var s=first;
while(s<=last){
var yy=s.getFullYear(),mm=('0'+(s.getMonth()+1)).slice(-2),dd=('0'+s.getDate()).slice(-2);
arr.push(yy+'-'+mm+'-'+dd);
s=new Date(s.getTime()+86400000);
}
return arr;
}
function fmtDate(d){
if(!d)return '';
var dt=new Date(d);
if(isNaN(dt.getTime()))return d;
return dt.getFullYear()+'-'+('0'+(dt.getMonth()+1)).slice(-2)+'-'+('0'+dt.getDate()).slice(-2);
}
function isWeekend(dateStr){
var d=new Date(dateStr);
var w=d.getDay();
return w===0||w===6;
}
function todayStr(){return fmtDate(new Date())}
// 从数据提取筛选选项
function fillFilters(){
var f={},pt={},rg={},ct={};
boardData.forEach(function(row){
if(row.Factory){f[row.Factory]=1}
if(row.ProductType){pt[row.ProductType]=1}
if(row.Region){rg[row.Region]=1}
if(row.Country){ct[row.Country]=1}
});
function fill(id,map,label){
var el=document.getElementById(id);
var cur=el.value;
var h='<option value="">'+label+':全部</option>';
Object.keys(map).sort().forEach(function(k){h+='<option value="'+k+'">'+k+'</option>'});
el.innerHTML=h;
el.value=cur;
}
fill('selFactory',f,'工厂');
fill('selProductType',pt,'产品类型');
fill('selRegion',rg,'区域');
fill('selCountry',ct,'国家');
}
// 渲染看板
function renderBoard(){
var kw=(document.getElementById('txtKeyword').value||'').trim().toLowerCase();
var f=document.getElementById('selFactory').value;
var pt=document.getElementById('selProductType').value;
var rg=document.getElementById('selRegion').value;
var ct=document.getElementById('selCountry').value;
var st=document.getElementById('selStatus').value;
var rows=boardData.filter(function(row){
if(f&&row.Factory!==f)return false;
if(pt&&row.ProductType!==pt)return false;
if(rg&&row.Region!==rg)return false;
if(ct&&row.Country!==ct)return false;
if(st&&row.Status!==st)return false;
if(kw){
var code=(row.ProductCode||'').toLowerCase();
var name=(row.ProductName||'').toLowerCase();
if(code.indexOf(kw)<0&&name.indexOf(kw)<0)return false;
}
return true;
});
// 按产品类型分组排序
var typeOrder={};
var types=[];
rows.forEach(function(row){
var t=row.ProductType||'(未分类)';
if(!(t in typeOrder)){typeOrder[t]=[];types.push(t)}
typeOrder[t].push(row);
});
types.sort();
var today=todayStr();
// 表头:工厂 / 产品类型 / 区域 / 国家 / 产品编码BOM / 产品名称 / 总产量 / 日期列
var headHtml='<tr>';
headHtml+='<th class="col-fix" style="min-width:90px">工厂</th>';
headHtml+='<th class="col-fix-info" style="left:90px;min-width:100px">产品类型</th>';
headHtml+='<th class="col-fix-info" style="left:190px;min-width:100px">区域</th>';
headHtml+='<th class="col-fix-info" style="left:290px;min-width:100px">国家</th>';
headHtml+='<th class="col-fix-info" style="left:390px;min-width:120px">产品编码 / BOM</th>';
headHtml+='<th class="col-fix-info" style="left:510px;min-width:130px">产品名称</th>';
headHtml+='<th>总产量</th>';
dateList.forEach(function(d){
var cls='cell-date';
if(isWeekend(d))cls+=' weekend';
if(d===today)cls+=' today';
var label=d.slice(5);
headHtml+='<th class="'+cls+'">'+label+'</th>';
});
headHtml+='</tr>';
document.getElementById('boardHead').innerHTML=headHtml;
// 表体
var bodyHtml='';
var totalRowCount=0;
if(rows.length===0){
bodyHtml='<tr><td colspan="'+(7+dateList.length)+'" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
}
// 每组:先列明细行,最后加一行"产品类型合计"
types.forEach(function(t){
var group=typeOrder[t];
// 明细行
group.forEach(function(row){
var stCls=row.Status==='进行中'?'badge-success':(row.Status==='待开始'?'badge-warning':(row.Status==='已完成'?'badge-info':'badge-muted'));
var dailyMap={};
(row.Daily||[]).forEach(function(d){dailyMap[d.PlanDate]=Number(d.DailyOutput)||0});
bodyHtml+='<tr>';
bodyHtml+='<td class="col-fix">'+row.Factory+'</td>';
bodyHtml+='<td class="col-fix-info" style="left:90px">'+row.ProductType+'</td>';
bodyHtml+='<td class="col-fix-info" style="left:190px">'+row.Region+'</td>';
bodyHtml+='<td class="col-fix-info" style="left:290px">'+row.Country+'</td>';
bodyHtml+='<td class="col-fix-info" style="left:390px"><div style="font-weight:600">'+row.ProductCode+'</div><div style="font-size:11px;color:#94a3b8">'+row.BOMVersion+'</div></td>';
bodyHtml+='<td class="col-fix-info" style="left:510px">'+row.ProductName+'</td>';
bodyHtml+='<td style="font-weight:600">'+(row.TotalOutput||0)+'</td>';
dateList.forEach(function(d){
var cls='cell-date';
if(isWeekend(d))cls+=' weekend';
if(d===today)cls+=' today';
var q=dailyMap[d];
if(q>0)cls+=' has';
bodyHtml+='<td class="'+cls+'"><span class="qty">'+(q>0?q:'')+'</span></td>';
});
bodyHtml+='</tr>';
totalRowCount++;
});
// 合计行(该产品类型下所有排程按日汇总 + 总产量合计)
var sumDaily={},sumTotal=0;
group.forEach(function(row){
(row.Daily||[]).forEach(function(d){
var dd=d.PlanDate, v=Number(d.DailyOutput)||0;
sumDaily[dd]=(sumDaily[dd]||0)+v;
sumTotal+=v;
});
});
bodyHtml+='<tr class="sum-row" style="background:#eef4ff;font-weight:600">';
bodyHtml+='<td class="col-fix" style="background:#eef4ff"></td>';
bodyHtml+='<td class="col-fix-info" style="left:90px;background:#eef4ff">'+t+' 合计</td>';
bodyHtml+='<td class="col-fix-info" style="left:190px;background:#eef4ff"></td>';
bodyHtml+='<td class="col-fix-info" style="left:290px;background:#eef4ff"></td>';
bodyHtml+='<td class="col-fix-info" style="left:390px;background:#eef4ff"></td>';
bodyHtml+='<td class="col-fix-info" style="left:510px;background:#eef4ff"></td>';
bodyHtml+='<td style="background:#eef4ff;font-weight:700">'+sumTotal+'</td>';
dateList.forEach(function(d){
var cls='cell-date';
if(isWeekend(d))cls+=' weekend';
if(d===today)cls+=' today';
var q=sumDaily[d]||0;
if(q>0)cls+=' has';
bodyHtml+='<td class="'+cls+'" style="background:#eef4ff"><span class="qty">'+(q>0?q:'')+'</span></td>';
});
bodyHtml+='</tr>';
});
document.getElementById('boardBody').innerHTML=bodyHtml;
document.getElementById('legendTotal').textContent='共 '+totalRowCount+' 条排程,'+types.length+' 个产品类型';
}
function resetFilter(){
document.getElementById('txtKeyword').value='';
document.getElementById('selFactory').value='';
document.getElementById('selProductType').value='';
document.getElementById('selRegion').value='';
document.getElementById('selCountry').value='';
document.getElementById('selStatus').value='';
renderBoard();
}
// 加载看板数据
function loadBoard(){
api(getApiUrl()+'GetScheduleBoard','GET',null,function(res){
boardData=res.data||[];
dateList=buildMonthDates(); // 本月所有日期
fillFilters();
renderBoard();
});
}
loadBoard();
</script>
<!-- 公共侧边栏组件(菜单维护点:View/common/nav.js) -->
<script src="../common/nav.js"></script>
</body>
</html>