903 lines
47 KiB
HTML
Executable File
903 lines
47 KiB
HTML
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}
|
||
/* ===== MultiSelect 多选下拉组件(方案B:下拉+checkbox)===== */
|
||
.ms-wrap{position:relative;display:inline-block;vertical-align:middle}
|
||
.ms-native{display:none}/* 隐藏原生select,保留id供JS取值 */
|
||
.ms-trigger{display:flex;align-items:center;justify-content:space-between;min-width:160px;padding:0 28px 0 10px;height:30px;background:#fff;border:1px solid #d9d9d9;border-radius:4px;font-size:13px;color:#333;cursor:pointer;user-select:none;transition:border-color .2s}
|
||
.ms-trigger:hover{border-color:#1890ff}
|
||
.ms-trigger.active{border-color:#1890ff;box-shadow:0 0 0 2px rgba(24,144,255,.15)}
|
||
.ms-trigger .ms-arrow{position:absolute;right:8px;top:50%;transform:translateY(-50%);width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #999;pointer-events:none}
|
||
.ms-trigger .ms-placeholder{color:#999}
|
||
.ms-trigger .ms-tags{display:flex;flex-wrap:wrap;gap:4px;margin-right:12px;max-width:260px}
|
||
.ms-trigger .ms-tag{display:inline-flex;align-items:center;gap:3px;background:#e6f4ff;color:#1890ff;padding:0 6px;height:20px;border-radius:3px;font-size:12px;line-height:1}
|
||
.ms-trigger .ms-tag .ms-tag-close{cursor:pointer;font-size:14px;line-height:1;margin-top:-1px}
|
||
.ms-trigger .ms-tag .ms-tag-close:hover{color:#096dd9}
|
||
.ms-trigger .ms-more{color:#999;font-size:12px;padding:0 4px}
|
||
.ms-dropdown{display:none;position:absolute;top:calc(100% + 4px);left:0;min-width:200px;max-height:280px;background:#fff;border:1px solid #e8e8e8;border-radius:6px;box-shadow:0 6px 16px rgba(0,0,0,.12);z-index:100;overflow:hidden}
|
||
.ms-dropdown.active{display:block}
|
||
.ms-search{padding:8px;border-bottom:1px solid #f0f0f0}
|
||
.ms-search input{width:100%;height:26px;padding:0 8px;border:1px solid #d9d9d9;border-radius:3px;font-size:12px;outline:none}
|
||
.ms-search input:focus{border-color:#1890ff}
|
||
.ms-options{max-height:220px;overflow-y:auto;padding:4px 0}
|
||
.ms-options label{display:flex;align-items:center;gap:8px;padding:5px 10px;cursor:pointer;font-size:13px;color:#333;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||
.ms-options label:hover{background:#f5f5f5}
|
||
.ms-options input[type=checkbox]{cursor:pointer}
|
||
.ms-footer{display:flex;justify-content:space-between;padding:6px 10px;border-top:1px solid #f0f0f0;font-size:12px}
|
||
.ms-footer .ms-btn{padding:2px 10px;border:1px solid #d9d9d9;border-radius:3px;background:#fff;cursor:pointer;color:#555}
|
||
.ms-footer .ms-btn:hover{border-color:#1890ff;color:#1890ff}
|
||
.ms-footer .ms-btn.primary{background:#1890ff;border-color:#1890ff;color:#fff}
|
||
.ms-footer .ms-btn.primary:hover{background:#096dd9}
|
||
/* ===== MultiSelect 结束 ===== */
|
||
.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">
|
||
<!-- MultiSelect 多选:原生 select 隐藏,保留 id 供 getFilters() 取值;组件同步更新 .value 为逗号分隔值 -->
|
||
<select id="selProductType" class="ms-native"><option value="">产品类型:全部</option></select>
|
||
<select id="selSupplier" class="ms-native"><option value="">供应商:全部</option></select>
|
||
<select id="selPurchaser" class="ms-native"><option value="">采购员:全部</option></select>
|
||
<select id="selRisk" class="ms-native">
|
||
<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-outline" onclick="resetSearch()">重置</button>
|
||
</div>
|
||
<div class="toolbar-row">
|
||
<button class="btn btn-primary" onclick="startDeliveryCalc()" id="btnRecalcDelivery">🔄 重算交付数据</button>
|
||
<!-- [2026-11-10 临时隐藏] 旧版"自定义模板"导入到货计划,会触发断线重算;
|
||
已被下方"📥 导入SRM排程"替代(供应商真实承诺,不参与断线计算)。
|
||
如需恢复,删除 style="display:none" 即可,后端 ImportBatchArrivalPlan 接口仍保留 -->
|
||
<button class="btn btn-blue" onclick="downloadBatchArrivalTpl()" style="display:none">📄 到货计划模板</button>
|
||
<button class="btn btn-outline" onclick="document.getElementById('batchArrivalFile').click()" style="display:none">📥 导入到货计划</button>
|
||
<input type="file" id="batchArrivalFile" accept=".xls,.xlsx" style="display:none" onchange="importBatchArrivalExcel(this)">
|
||
<button class="btn btn-green" onclick="document.getElementById('srmFile').click()">📥 导入SRM排程</button>
|
||
<input type="file" id="srmFile" accept=".xlsx,.xls" style="display:none" onchange="importSRMSchedule(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:105px">物料编码</th><th style="width:110px">物料名称</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:70px">到货计划</th><th style="width:65px">PO总量</th><th style="width:65px">申请单</th>
|
||
<th style="width:65px">可用库存</th><th style="width:65px">量产在途</th><th style="width:65px">研发在途</th><th style="width:60px">线边</th><th style="width:60px">已收货</th>
|
||
<th style="width:65px">震泽</th><th style="width:65px">晋江</th><th style="width:65px">资阳</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;
|
||
// 刷新 MultiSelect 的 checkbox 列表(动态 innerHTML 后重建)
|
||
['selProductType','selSupplier','selPurchaser'].forEach(function(id){
|
||
var el=document.getElementById(id);if(el&&el.refreshMulti)el.refreshMulti();
|
||
});
|
||
cb&&cb();
|
||
});
|
||
}
|
||
|
||
function getFilters(){
|
||
// 优先从 MultiSelect 组件读(数组),fallback 原生 .value
|
||
function multiValue(id){
|
||
var el=document.getElementById(id);
|
||
if(el.getMultiValues)return el.getMultiValues().join(',');
|
||
return el.value||'';
|
||
}
|
||
var t=multiValue('selProductType');
|
||
var s=multiValue('selSupplier');
|
||
var pu=multiValue('selPurchaser');
|
||
var r=multiValue('selRisk');
|
||
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="21" 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');
|
||
var delIds=r.DeliveryIds||r.Id||'';
|
||
var openEditUrl=(delIds.indexOf(',')>=0)?'openEditMultiple(\''+delIds+'\')':'openEdit('+r.Id+')';
|
||
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="'+openEditUrl+'">编辑</button> '+
|
||
'<button class="btn btn-blue" style="height:26px;padding:0 8px;font-size:11px" onclick="openArrival('+(r.Id||0)+',\''+r.MaterialName.replace(/'/g,"\\'")+'\')">到货计划</button>'+
|
||
'</td>'+
|
||
'<td>'+r.ChildMaterialId+'</td>'+
|
||
'<td>'+r.MaterialName+'</td>'+
|
||
'<td style="font-size:11px">'+(r.ProductCode||'')+'</td>'+
|
||
'<td style="font-size:11px;max-width:140px;overflow:hidden;text-overflow:ellipsis" title="'+(r.Supplier||'').replace(/"/g,'"')+'">'+(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||'0')+'</td>'+
|
||
'<td>'+(r.ArrivalQty||'0')+'</td>'+
|
||
'<td>'+(r.PoTotalQty||'0')+'</td>'+
|
||
'<td>'+(r.ReqTotalQty||'0')+'</td>'+
|
||
'<td style="font-weight:600">'+(r.AvailableStock||'0')+'</td>'+
|
||
'<td>'+(r.MassInTransit||'0')+'</td>'+
|
||
'<td>'+(r.ResearchInTransit||'0')+'</td>'+
|
||
'<td>'+(r.LineSideStock||'0')+'</td>'+
|
||
'<td>'+(r.ReceivedQty||'0')+'</td>'+
|
||
'<td>'+(r.ZhenZeStock||'0')+'</td>'+
|
||
'<td>'+(r.JinJiangStock||'0')+'</td>'+
|
||
'<td>'+(r.ZiYangStock||'0')+'</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(){
|
||
['selProductType','selSupplier','selPurchaser','selRisk'].forEach(function(id){
|
||
var el=document.getElementById(id);
|
||
if(el.resetMulti)el.resetMulti();else el.value='';
|
||
});
|
||
document.getElementById('txtKeyword').value='';
|
||
// resetMulti 已触发 triggerAutoSearch(防抖 300ms 自动 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;
|
||
var rc=parseFloat(document.getElementById('fReceivedQty').value)||0;
|
||
document.getElementById('fAvailableStock').value=(z+j+t+m+r+l+rc);
|
||
}
|
||
|
||
function openEditMultiple(deliveryIds){
|
||
var ids=deliveryIds.split(',').filter(function(s){return s});
|
||
if(ids.length<=1){openEdit(ids[0]||0);return}
|
||
var rows=curList.filter(function(r){return (r.DeliveryIds||'').split(',').indexOf(ids[0])>=0||r.Id==ids[0]});
|
||
// 找出所有涉及的 ChildMaterialId 对应的 DeliveryIds
|
||
var idsInRow=(rows[0]&&rows[0].DeliveryIds)?rows[0].DeliveryIds.split(','):ids;
|
||
if(idsInRow.length===1){openEdit(idsInRow[0]);return}
|
||
var choices='<div style="max-height:300px;overflow-y:auto">';
|
||
idsInRow.forEach(function(id,idx){
|
||
var row=curList.find(function(r){return (r.DeliveryIds||'').split(',').indexOf(id)>=0||r.Id==id});
|
||
var title='排程关联(DeliveryId:'+id+')';
|
||
if(row){
|
||
// 尝试从 DeliveryDetail 拿到产品编码/排程ID
|
||
title='DeliveryId:'+id;
|
||
}
|
||
choices+='<label style="display:block;padding:8px;border-bottom:1px solid #e2e8f0;cursor:pointer"><input type="radio" name="editChoice" value="'+id+'" '+(idx===0?'checked':'')+'> 选择 DeliveryId: '+id+'</label>';
|
||
});
|
||
choices+='</div>';
|
||
if(!confirm('该物料关联 '+idsInRow.length+' 个排程的交付记录。\n点击"确定"编辑第一个(DeliveryId:'+idsInRow[0]+'),点击"取消"后可手动刷新重算。')){return}
|
||
openEdit(idsInRow[0]);
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
// 列表页:导入 SRM 供应商排程承诺(不触发断线重算,仅作参考展示)
|
||
function importSRMSchedule(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()+'ImportSRMSchedule','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();
|
||
}
|
||
});
|
||
}
|
||
|
||
/* ===== MultiSelect 组件初始化(方案B:下拉+checkbox)===== */
|
||
function initMultiSelect(selectEl, placeholder){
|
||
var wrap=document.createElement('div');
|
||
wrap.className='ms-wrap';
|
||
var trigger=document.createElement('div');
|
||
trigger.className='ms-trigger';
|
||
trigger.innerHTML='<span class="ms-tags"></span><span class="ms-placeholder">'+placeholder+'</span><span class="ms-arrow"></span>';
|
||
var dropdown=document.createElement('div');
|
||
dropdown.className='ms-dropdown';
|
||
var searchWrap=document.createElement('div');searchWrap.className='ms-search';
|
||
var searchInput=document.createElement('input');searchInput.type='text';searchInput.placeholder='搜索...';
|
||
searchWrap.appendChild(searchInput);
|
||
var optionsWrap=document.createElement('div');optionsWrap.className='ms-options';
|
||
var footer=document.createElement('div');footer.className='ms-footer';
|
||
footer.innerHTML='<button class="ms-btn" data-action="clear">清空</button><button class="ms-btn primary" data-action="ok">确定</button>';
|
||
dropdown.appendChild(searchWrap);dropdown.appendChild(optionsWrap);dropdown.appendChild(footer);
|
||
|
||
wrap.appendChild(trigger);wrap.appendChild(dropdown);
|
||
selectEl.parentNode.insertBefore(wrap, selectEl);
|
||
|
||
// 读原生 options 构建 checkbox 列表
|
||
var origOptions=selectEl.querySelectorAll('option');
|
||
var listItems=[];
|
||
origOptions.forEach(function(opt){
|
||
if(!opt.value)return;// 跳过"全部"空值
|
||
var lbl=document.createElement('label');
|
||
var cb=document.createElement('input');cb.type='checkbox';cb.value=opt.value;
|
||
var txt=document.createElement('span');txt.textContent=opt.textContent;
|
||
lbl.appendChild(cb);lbl.appendChild(txt);
|
||
optionsWrap.appendChild(lbl);
|
||
listItems.push({cb:cb,txt:txt,label:lbl});
|
||
});
|
||
|
||
function getSelectedValues(){
|
||
return listItems.filter(i=>i.cb.checked).map(i=>i.cb.value);
|
||
}
|
||
var _msDebounce=null;
|
||
function triggerAutoSearch(){
|
||
if(_msDebounce)clearTimeout(_msDebounce);
|
||
_msDebounce=setTimeout(function(){loadList(1);},300);
|
||
}
|
||
function renderTags(){
|
||
var vals=getSelectedValues();
|
||
var tagsSpan=trigger.querySelector('.ms-tags');
|
||
var ph=trigger.querySelector('.ms-placeholder');
|
||
if(vals.length===0){
|
||
tagsSpan.innerHTML='';ph.style.display='inline';ph.textContent=placeholder;
|
||
trigger.style.minWidth='160px';
|
||
}else{
|
||
ph.style.display='none';
|
||
if(vals.length<=2){
|
||
tagsSpan.innerHTML=vals.map(function(v){
|
||
var label=selectEl.querySelector('option[value="'+v+'"]');
|
||
var txt=label?label.textContent:v;
|
||
return '<span class="ms-tag">'+txt+'<span class="ms-tag-close" data-val="'+v+'">×</span></span>';
|
||
}).join('');
|
||
}else{
|
||
var shown=vals.slice(0,1);
|
||
var hidden=vals.length-1;
|
||
tagsSpan.innerHTML='<span class="ms-tag">'+(selectEl.querySelector('option[value="'+shown[0]+'"]')?.textContent||shown[0])+'<span class="ms-tag-close" data-val="'+shown[0]+'">×</span></span><span class="ms-more">+'+hidden+'</span>';
|
||
}
|
||
}
|
||
trigger.style.minWidth='';
|
||
}
|
||
|
||
// 点 trigger 打开
|
||
trigger.addEventListener('click',function(e){
|
||
e.stopPropagation();
|
||
// 关闭其他
|
||
document.querySelectorAll('.ms-dropdown.active').forEach(function(d){if(d!==dropdown)d.classList.remove('active');document.querySelectorAll('.ms-trigger.active').forEach(function(t){t.classList.remove('active')});});
|
||
dropdown.classList.toggle('active');
|
||
trigger.classList.toggle('active');
|
||
if(dropdown.classList.contains('active')){
|
||
searchInput.focus();searchInput.value='';
|
||
listItems.forEach(function(i){i.label.style.display=''});
|
||
}
|
||
});
|
||
|
||
// 搜索
|
||
searchInput.addEventListener('input',function(){
|
||
var q=searchInput.value.toLowerCase();
|
||
listItems.forEach(function(i){
|
||
if(!q||i.txt.textContent.toLowerCase().indexOf(q)>=0)i.label.style.display='';
|
||
else i.label.style.display='none';
|
||
});
|
||
});
|
||
|
||
// checkbox 变更 → 防抖自动筛选
|
||
listItems.forEach(function(i){
|
||
i.cb.addEventListener('change',function(){renderTags();triggerAutoSearch();});
|
||
});
|
||
|
||
// tag 里的 × 关闭
|
||
wrap.addEventListener('click',function(e){
|
||
var close=e.target.closest('.ms-tag-close');
|
||
if(close){
|
||
e.stopPropagation();
|
||
var v=close.getAttribute('data-val');
|
||
var item=listItems.find(function(x){return x.cb.value===v});
|
||
if(item){item.cb.checked=false;renderTags();triggerAutoSearch();}
|
||
}
|
||
});
|
||
|
||
// footer 按钮
|
||
footer.addEventListener('click',function(e){
|
||
var btn=e.target.closest('.ms-btn');if(!btn)return;
|
||
if(btn.getAttribute('data-action')==='clear'){
|
||
listItems.forEach(function(i){i.cb.checked=false;});
|
||
renderTags();triggerAutoSearch();
|
||
dropdown.classList.remove('active');trigger.classList.remove('active');
|
||
}else if(btn.getAttribute('data-action')==='ok'){
|
||
dropdown.classList.remove('active');trigger.classList.remove('active');
|
||
}
|
||
});
|
||
|
||
// 点外面关闭
|
||
document.addEventListener('click',function(e){
|
||
if(!wrap.contains(e.target)){
|
||
dropdown.classList.remove('active');trigger.classList.remove('active');
|
||
}
|
||
});
|
||
|
||
// 提供 reset 方法供 resetSearch() 调用
|
||
selectEl.resetMulti=function(){listItems.forEach(function(i){i.cb.checked=false;});renderTags();triggerAutoSearch();};
|
||
// 提供 setValues 供 loadOptions 后回填
|
||
selectEl.setValuesMulti=function(csv){
|
||
var arr=(csv||'').split(',').filter(Boolean);
|
||
listItems.forEach(function(i){i.cb.checked=arr.indexOf(i.cb.value)>=0;});
|
||
renderTags();
|
||
};
|
||
// getFilters() 优先调用这个(数组),绕过原生 select .value
|
||
selectEl.getMultiValues=function(){return getSelectedValues();};
|
||
|
||
// 刷新 options(当原生 select innerHTML 被动态更新后调用,如 loadOptions 回调)
|
||
selectEl.refreshMulti=function(){
|
||
var saved=getSelectedValues();// 先保存当前选中值
|
||
optionsWrap.innerHTML='';
|
||
listItems=[];
|
||
origOptions=selectEl.querySelectorAll('option');
|
||
origOptions.forEach(function(opt){
|
||
if(!opt.value)return;
|
||
var lbl=document.createElement('label');
|
||
var cb=document.createElement('input');cb.type='checkbox';cb.value=opt.value;
|
||
var txt=document.createElement('span');txt.textContent=opt.textContent;
|
||
lbl.appendChild(cb);lbl.appendChild(txt);
|
||
optionsWrap.appendChild(lbl);
|
||
listItems.push({cb:cb,txt:txt,label:lbl});
|
||
});
|
||
listItems.forEach(function(i){
|
||
i.cb.addEventListener('change',function(){renderTags();triggerAutoSearch();});
|
||
});
|
||
// 恢复之前的选中值
|
||
listItems.forEach(function(i){i.cb.checked=saved.indexOf(i.cb.value)>=0;});
|
||
renderTags();
|
||
};
|
||
|
||
renderTags();
|
||
return selectEl;
|
||
}
|
||
|
||
// 搜索框:防抖 300ms 自动 loadList
|
||
var _kwDebounce=null;
|
||
document.addEventListener('DOMContentLoaded',function(){
|
||
initMultiSelect(document.getElementById('selProductType'),'产品类型:全部');
|
||
initMultiSelect(document.getElementById('selSupplier'),'供应商:全部');
|
||
initMultiSelect(document.getElementById('selPurchaser'),'采购员:全部');
|
||
initMultiSelect(document.getElementById('selRisk'),'风险:全部');
|
||
|
||
var kw=document.getElementById('txtKeyword');
|
||
if(kw){
|
||
kw.addEventListener('input',function(){
|
||
if(_kwDebounce)clearTimeout(_kwDebounce);
|
||
_kwDebounce=setTimeout(function(){loadList(1);},300);
|
||
});
|
||
}
|
||
});
|
||
</script>
|
||
<!-- 公共导航栏组件(菜单维护点:View/common/nav.js) -->
|
||
<script src="../common/nav.js"></script>
|
||
</body>
|
||
</html>
|