后端: - MultiLike/MultiExact/MultiCsvContains 三个 Helper - .NET Framework 4.6 无 TrimEntries,改用 Select(v=>v.Trim()) 手动去空格 - 7 个接口 where 条件从单值改多值 OR 模式 前端: - material_delivery.html + delivery_dashboard_risk.html 各 4 个下拉改 MultiSelect 组件 - 原生 select 隐藏,组件同步 .value 为逗号分隔,原页面 JS 零改动 - 支持动态 options 刷新 + reset/setValuesMulti/refreshMulti
631 lines
32 KiB
Plaintext
Executable File
631 lines
32 KiB
Plaintext
Executable File
<!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>
|