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,139 @@
/**
* ============================================
* GX-WMS 通用列表(Grid)组件
*
* 功能:
* 1. 表头固定(上下滚动时不消失)
* 2. 列宽可拖动(拖动表头右边调整,列与列之间互不影响)
* 3. 行 hover 高亮
* 4. 风险标签自动着色(断线/预警/安全)
* 5. 数字自动格式化(0 灰色、负数红色)
* 6. 横向滚动自然
* 7. 自动重新绑定(数据刷新后)
*
* 用法:
* 1. 引入 CSS:<link rel="stylesheet" href="../common/grid.css">
* 2. 引入 JS:<script src="../common/grid.js"></script>
* 3. HTML 结构:
* <div id="myGrid" class="gx-grid">
* <table>
* <thead><tr><th style="width:80px">列名</th>...</tr></thead>
* <tbody id="myTbody"></tbody>
* </table>
* </div>
* 4. JS 渲染后调用:Grid.bind('myGrid');
* 5. 工具函数:
* Grid.riskTag('断线') => <span class="tag broken">断线</span>
* Grid.num(120) => <span class="num">120</span>
* Grid.num(0) => <span class="num zero">0</span>
* Grid.num(-5) => <span class="num neg">-5</span>
* Grid.muted('未填写') => <span class="muted">未填写</span>
* ============================================
*/
const Grid = (function() {
/**
* 绑定列宽拖动 + 重新绑定的工具
* @param {string} containerId - 容器元素的 id(含 class="gx-grid")
*/
function bind(containerId) {
const wrap = document.getElementById(containerId);
if (!wrap) return;
const table = wrap.querySelector('table');
if (!table) return;
// 确保有 <colgroup>,按列设置宽度(改 col 宽度,浏览器自动应用到整列,无需遍历 td,性能好)
let colgroup = table.querySelector('colgroup');
if (!colgroup) {
colgroup = document.createElement('colgroup');
table.insertBefore(colgroup, table.firstChild);
}
const theadRow = table.querySelector('thead tr');
const colCount = theadRow ? theadRow.children.length : 0;
const cols = [];
for (let i = 0; i < colCount; i++) {
let col = colgroup.children[i];
if (!col) {
col = document.createElement('col');
colgroup.appendChild(col);
}
cols.push(col);
}
const ths = wrap.querySelectorAll('thead th');
ths.forEach((th, idx) => {
if (th.querySelector('.gx-resizer')) return;
// 用 th 当前宽度初始化 col 宽度(保持原列宽不被 colgroup 覆盖)
if (cols[idx]) {
const w = th.style.width || th.getBoundingClientRect().width + 'px';
cols[idx].style.width = w;
}
const r = document.createElement('div');
r.className = 'gx-resizer';
th.appendChild(r);
r.addEventListener('mousedown', function(e) {
e.preventDefault();
e.stopPropagation();
const startX = e.pageX;
const startW = th.getBoundingClientRect().width;
let raf = null;
let pendingW = startW;
r.classList.add('active');
const onMove = function(ev) {
const dx = ev.pageX - startX;
pendingW = Math.max(8, startW + dx); // 最小 8px,允许一直收缩到很小
if (raf) return; // 已有待处理的帧,跳过(该帧会用最新 pendingW)
raf = requestAnimationFrame(function() {
raf = null;
if (cols[idx]) cols[idx].style.width = pendingW + 'px';
th.style.width = pendingW + 'px'; // 同步 th,保证表头与列内容对齐
});
};
const onUp = function() {
if (raf) { cancelAnimationFrame(raf); raf = null; }
// 最终确保应用一次
if (cols[idx]) cols[idx].style.width = pendingW + 'px';
th.style.width = pendingW + 'px';
r.classList.remove('active');
document.removeEventListener('mousemove', onMove);
document.removeEventListener('mouseup', onUp);
};
document.addEventListener('mousemove', onMove);
document.addEventListener('mouseup', onUp);
});
});
}
/**
* 风险标签
*/
function riskTag(risk) {
if (!risk) return '<span class="tag empty">未判定</span>';
const cls = ({'断线':'broken','预警':'warn','安全':'safe'})[risk] || 'empty';
return '<span class="tag ' + cls + '">' + risk + '</span>';
}
/**
* 数字格式化
*/
function num(v) {
if (v === null || v === undefined || v === '' || v === '-') return '<span class="muted">-</span>';
const n = Number(v);
if (isNaN(n)) return v;
if (n === 0) return '<span class="num zero">0</span>';
if (n < 0) return '<span class="num neg">' + n + '</span>';
return '<span class="num">' + n + '</span>';
}
/**
* 占位符
*/
function muted(v, placeholder) {
if (!v) return '<span class="muted">' + (placeholder || '-') + '</span>';
return v;
}
return { bind: bind, riskTag: riskTag, num: num, muted: muted };
})();
@@ -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>