feat: 子卷包装关系crud

This commit is contained in:
2026-08-17 10:43:10 +08:00
parent 95286d126e
commit 3d11668705
25 changed files with 2492 additions and 6 deletions

View File

@@ -0,0 +1,74 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>子卷包装关系 - 批量新增原型</title>
<style>
:root{--primary:#1677ff;--primary-hover:#4096ff;--text:#1f2329;--muted:#646a73;--border:#d9d9d9;--line:#e5e6eb;--page:#f5f5f5;--surface:#fff;--danger:#ff4d4f;--success:#52c41a;--shadow:0 10px 38px rgba(0,0,0,.18);--radius:6px}
*{box-sizing:border-box}html,body{height:100%;margin:0;font-family:"Segoe UI","Microsoft YaHei",Arial,sans-serif;color:var(--text);font-size:14px;background:var(--page)}button,input,select{font:inherit}button{cursor:pointer}.app{display:grid;grid-template-columns:208px 1fr;height:100%;overflow:hidden}.sidebar{background:#001529;color:#fff}.brand{height:56px;display:flex;align-items:center;gap:10px;padding:0 20px;font-size:16px;font-weight:600;border-bottom:1px solid rgba(255,255,255,.08)}.brand-mark{width:28px;height:28px;border-radius:7px;background:linear-gradient(145deg,#4ca5ff,#1465da);display:grid;place-items:center;font-size:13px}.menu{padding:12px 8px}.menu-title{padding:10px 12px;color:#788898;font-size:12px}.menu-item{height:42px;display:flex;align-items:center;gap:11px;padding:0 14px;border-radius:6px;color:#bac5cf;margin-bottom:3px}.menu-item.active{background:var(--primary);color:#fff}.menu-item .ico{width:18px;text-align:center}.shell{min-width:0;display:flex;flex-direction:column}.topbar{height:56px;background:#fff;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:0 22px}.top-actions{display:flex;align-items:center;gap:18px;color:#555}.avatar{width:30px;height:30px;border-radius:50%;background:#d9eaff;color:#1465da;display:grid;place-items:center;font-weight:600}.main{padding:16px;overflow:auto}.crumb{color:#7a7f87;font-size:13px;margin-bottom:14px}.card{background:#fff;border-radius:8px;border:1px solid #eceef1}.search-card{padding:18px 20px;margin-bottom:14px}.filter-grid{display:grid;grid-template-columns:repeat(4,minmax(180px,1fr));gap:15px 20px}.field{display:flex;align-items:center;gap:10px}.field label{white-space:nowrap;color:#4d5157}.input,.select{height:32px;border:1px solid var(--border);border-radius:6px;background:#fff;padding:0 10px;color:#333;outline:none}.field .input,.field .select{flex:1;min-width:0}.input:focus,.select:focus{border-color:var(--primary);box-shadow:0 0 0 2px rgba(22,119,255,.12)}.search-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:16px}.btn{height:32px;padding:0 14px;border-radius:6px;border:1px solid var(--border);background:#fff;color:#333;display:inline-flex;align-items:center;justify-content:center;gap:6px;transition:.15s}.btn:hover{border-color:var(--primary);color:var(--primary)}.btn.primary{background:var(--primary);border-color:var(--primary);color:#fff}.btn.primary:hover{background:var(--primary-hover)}.btn.danger{color:var(--danger);border-color:#ffccc7}.btn.text{border-color:transparent;background:transparent;color:var(--primary);padding:0 6px}.btn.text.danger{color:var(--danger)}.table-card{padding:16px}.table-toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.table-title{font-size:16px;font-weight:600}.toolbar-actions{display:flex;gap:8px}.data-table{width:100%;border-collapse:collapse;font-size:13px}.data-table th{height:40px;background:#fafafa;text-align:left;color:#4e5969;border-bottom:1px solid var(--line);padding:0 12px;font-weight:600}.data-table td{height:46px;border-bottom:1px solid #f0f0f0;padding:0 12px;white-space:nowrap}.tag{display:inline-flex;padding:2px 8px;border-radius:4px;background:#e6f4ff;color:#1677ff}.pager{display:flex;justify-content:flex-end;align-items:center;gap:8px;padding-top:14px;color:#69707a}.page-num{width:30px;height:30px;border:1px solid var(--primary);color:var(--primary);border-radius:5px;display:grid;place-items:center}
.mask{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:20;display:flex;align-items:center;justify-content:center;padding:28px}.mask.hidden{display:none}.modal{width:min(1280px,calc(100vw - 48px));height:min(720px,calc(100vh - 56px));background:#fff;border-radius:10px;box-shadow:var(--shadow);display:flex;flex-direction:column;overflow:hidden;animation:pop .18s ease-out}@keyframes pop{from{opacity:0;transform:scale(.985)}to{opacity:1;transform:scale(1)}}.modal-header{height:58px;flex:none;padding:0 22px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line)}.modal-title{font-size:17px;font-weight:600}.close-btn{width:34px;height:34px;border:0;background:transparent;border-radius:6px;color:#6b7280;font-size:22px;line-height:1}.close-btn:hover{background:#f2f3f5}.modal-body{flex:1;min-height:0;padding:16px 20px;display:flex;flex-direction:column;gap:12px}.notice{min-height:38px;border:1px solid #91caff;background:#e6f4ff;border-radius:6px;padding:9px 12px;color:#0958d9;display:flex;align-items:center;justify-content:space-between}.notice.error{border-color:#ffccc7;background:#fff2f0;color:#cf1322}.notice .summary{font-weight:600}.batch-toolbar{display:flex;align-items:center;justify-content:space-between}.batch-tools{display:flex;gap:8px}.count{color:#69707a}.count strong{color:var(--primary);font-size:16px}.editor-wrap{flex:1;min-height:0;border:1px solid var(--line);border-radius:7px;overflow:auto;position:relative}.editor{border-collapse:separate;border-spacing:0;min-width:2180px;width:100%;font-size:13px}.editor th,.editor td{border-right:1px solid var(--line);border-bottom:1px solid var(--line);padding:6px 8px;background:#fff;vertical-align:top}.editor thead th{position:sticky;top:0;z-index:4;background:#fafafa;text-align:left;color:#4e5969;font-weight:600}.editor thead tr.group th{height:32px;text-align:center;background:#f2f6fc;color:#36516f;border-bottom-color:#d8e4f3}.editor thead tr.labels th{top:32px;height:42px;vertical-align:middle}.editor .sticky-left{position:sticky;left:0;z-index:3}.editor thead .sticky-left{z-index:7}.editor .sticky-right{position:sticky;right:0;z-index:3;box-shadow:-4px 0 8px rgba(0,0,0,.05)}.editor thead .sticky-right{z-index:7}.editor td.sticky-left,.editor td.sticky-right{background:#fff}.editor .row-index{width:48px;min-width:48px;text-align:center;color:#8c8c8c}.editor .required:before{content:"*";color:var(--danger);margin-right:3px}.cell{min-height:52px}.cell input,.cell select{width:100%;height:32px;border:1px solid var(--border);border-radius:5px;padding:0 9px;outline:none;background:#fff}.cell input:focus,.cell select:focus{border-color:var(--primary);box-shadow:0 0 0 2px rgba(22,119,255,.1)}.cell input[readonly]{background:#f5f5f5;color:#666}.unit-input{position:relative}.unit-input input{padding-right:32px}.unit{position:absolute;right:9px;top:8px;color:#8c8c8c;font-size:12px}.cell.invalid input,.cell.invalid select{border-color:var(--danger);background:#fff2f0}.error-text{display:none;color:var(--danger);font-size:11px;line-height:16px;margin-top:2px;white-space:normal}.cell.invalid .error-text{display:block}.row-actions{display:flex;align-items:center;justify-content:center;gap:3px;height:34px}.modal-footer{height:62px;flex:none;border-top:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:0 22px;background:#fff}.footer-tip{font-size:12px;color:#8c8c8c}.footer-actions{display:flex;gap:10px}.modal-footer .btn{height:34px;min-width:88px}.confirm-mask{position:absolute;inset:0;background:rgba(0,0,0,.25);z-index:30;display:grid;place-items:center}.confirm-mask.hidden{display:none}.confirm{width:390px;background:#fff;border-radius:8px;box-shadow:var(--shadow);padding:22px}.confirm h3{margin:0 0 10px;font-size:16px}.confirm p{margin:0;color:#646a73;line-height:1.7}.confirm-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:22px}.toast{position:fixed;z-index:60;top:20px;left:50%;transform:translateX(-50%);background:#fff;border-radius:7px;box-shadow:0 6px 22px rgba(0,0,0,.16);padding:11px 18px;display:flex;align-items:center;gap:9px;opacity:0;pointer-events:none;transition:.2s}.toast.show{opacity:1}.toast-icon{color:var(--success);font-weight:700}.empty{padding:30px;text-align:center;color:#8c8c8c}@media(max-width:1100px){.app{grid-template-columns:64px 1fr}.sidebar .brand span,.menu-item span,.menu-title{display:none}.brand{padding:0;justify-content:center}.menu-item{justify-content:center;padding:0}.filter-grid{grid-template-columns:repeat(2,1fr)}}@media(prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
</style>
</head>
<body>
<div class="app">
<aside class="sidebar"><div class="brand"><div class="brand-mark">NL</div><span>华创智能制造</span></div><nav class="menu"><div class="menu-title">业务管理</div><div class="menu-item"><span class="ico"></span><span>仓储管理</span></div><div class="menu-item active"><span class="ico"></span><span>子卷包装关系</span></div><div class="menu-item"><span class="ico"></span><span>包装点管理</span></div><div class="menu-title">系统管理</div><div class="menu-item"><span class="ico"></span><span>基础配置</span></div></nav></aside>
<section class="shell">
<header class="topbar"><div></div><div class="top-actions"><span></span><span></span><span>管理员</span><div class="avatar"></div></div></header>
<main class="main"><div class="crumb">首页 / 物流管理 / 子卷包装关系</div>
<section class="card search-card"><div class="filter-grid"><div class="field"><label>木箱唯一码</label><input class="input" placeholder="请输入木箱唯一码"></div><div class="field"><label>销售订单号</label><input class="input" placeholder="请输入销售订单号"></div><div class="field"><label>客户名称</label><input class="input" placeholder="请输入客户名称"></div><div class="field"><label>子卷号</label><input class="input" placeholder="请输入子卷号"></div></div><div class="search-actions"><button class="btn">↻ 重置</button><button class="btn primary">⌕ 搜索</button></div></section>
<section class="card table-card"><div class="table-toolbar"><div class="table-title">子卷包装关系列表</div><div class="toolbar-actions"><button class="btn primary"> 新增</button><button class="btn primary" id="openBatchBtn">⊞ 批量新增</button><button class="btn">⇩ 导出</button><button class="btn danger">⌫ 批量删除</button></div></div><div style="overflow:auto"><table class="data-table"><thead><tr><th>木箱唯一码</th><th>木箱类型</th><th>重量(kg)</th><th>销售订单号</th><th>客户名称</th><th>入库日期</th><th>子卷号</th><th>操作</th></tr></thead><tbody id="backgroundBody"><tr><td>BXSN-20260817-001</td><td><span class="tag">BX-A</span></td><td>38.50</td><td>SO20260817001</td><td>华东新能源材料有限公司</td><td>2026-08-17</td><td>JR-260817-001</td><td><button class="btn text">编辑</button><button class="btn text danger">删除</button></td></tr><tr><td>BXSN-20260817-002</td><td><span class="tag">BX-B</span></td><td>32.80</td><td>SO20260817002</td><td>南方精密科技有限公司</td><td>2026-08-16</td><td>JR-260816-018</td><td><button class="btn text">编辑</button><button class="btn text danger">删除</button></td></tr></tbody></table></div><div class="pager"><span>共 28 条</span><div class="page-num">1</div><span>2 3 </span></div></section>
</main>
</section>
</div>
<div class="mask" id="batchModal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<section class="modal">
<header class="modal-header"><div class="modal-title" id="modalTitle">批量新增子卷包装关系</div><button class="close-btn" id="closeBtn" aria-label="关闭">×</button></header>
<div class="modal-body">
<div class="notice" id="notice"><span id="noticeText"> 每行录入一条完整包装关系,选择木箱类型后自动带出长、宽、高。</span><span class="summary" id="errorSummary"></span></div>
<div class="batch-toolbar"><div class="batch-tools"><button class="btn primary" id="addRowBtn"> 新增一行</button><button class="btn" id="clearBtn">⌫ 清空全部</button></div><div class="count">当前共 <strong id="rowCount">3</strong></div></div>
<div class="editor-wrap" id="editorWrap"><table class="editor"><thead><tr class="group"><th class="sticky-left" colspan="2">木箱信息</th><th colspan="6">木箱信息</th><th colspan="3">订单信息</th><th>子卷信息</th><th class="sticky-right">操作</th></tr><tr class="labels"><th class="row-index sticky-left">序号</th><th class="required" style="min-width:190px">木箱唯一码</th><th class="required" style="min-width:130px">重量</th><th class="required" style="min-width:150px">保质期</th><th class="required" style="min-width:160px">木箱类型</th><th style="min-width:120px">木箱长</th><th style="min-width:120px">木箱宽</th><th style="min-width:120px">木箱高</th><th class="required" style="min-width:190px">销售订单号</th><th class="required" style="min-width:220px">客户名称</th><th class="required" style="min-width:150px">入库日期</th><th class="required" style="min-width:190px">子卷号</th><th class="sticky-right" style="min-width:112px;text-align:center">操作</th></tr></thead><tbody id="editableBody"></tbody></table></div>
</div>
<footer class="modal-footer"><div class="footer-tip"><span style="color:#ff4d4f">*</span> 为必填项,尺寸单位为 mm</div><div class="footer-actions"><button class="btn" id="cancelBtn">取消</button><button class="btn primary" id="submitBtn">确认新增3 条)</button></div></footer>
</section>
<div class="confirm-mask hidden" id="confirmMask"><div class="confirm"><h3 id="confirmTitle">确认操作</h3><p id="confirmText"></p><div class="confirm-actions"><button class="btn" id="confirmCancel">取消</button><button class="btn primary" id="confirmOk">确认</button></div></div></div>
</div>
<div class="toast" id="toast"><span class="toast-icon"></span><span id="toastText"></span></div>
<script>
const boxTypes={'BX-A':{length:1200,width:1000,high:900},'BX-B':{length:1100,width:900,high:850},'BX-C':{length:800,width:600,high:600}};
const fields=['package_box_sn','box_weight','quality_guaran_period','box_type','box_length','box_width','box_high','sale_order_name','customer_name','date_of_fg_inbound','container_name'];
const required=['package_box_sn','box_weight','quality_guaran_period','box_type','sale_order_name','customer_name','date_of_fg_inbound','container_name'];
let nextKey=1,rows=[],errors=[],confirmAction=null;
const $=id=>document.getElementById(id), modal=$('batchModal'), body=$('editableBody'), notice=$('notice'), noticeText=$('noticeText');
const emptyRow=()=>({key:nextKey++,package_box_sn:'',box_weight:'',quality_guaran_period:'',sale_order_name:'',customer_name:'',date_of_fg_inbound:'',container_name:'',box_type:'',box_length:'',box_width:'',box_high:''});
function resetRows(){rows=[emptyRow(),emptyRow(),emptyRow()];errors=[];render();resetNotice()}
function resetNotice(){notice.classList.remove('error');noticeText.textContent=' 每行录入一条完整包装关系,选择木箱类型后自动带出长、宽、高。';$('errorSummary').textContent=''}
function esc(v){return String(v??'').replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]))}
function err(key,field){return errors.find(e=>e.rowKey===key&&e.field===field)}
function cell(row,field,html){const e=err(row.key,field);return `<td><div class="cell ${e?'invalid':''}" data-cell="${row.key}-${field}">${html}<div class="error-text">${e?esc(e.message):''}</div></div></td>`}
function render(){
body.innerHTML=rows.map((r,i)=>`<tr><td class="row-index sticky-left">${i+1}</td>${cell(r,'package_box_sn',`<input aria-label="第${i+1}行木箱唯一码" data-key="${r.key}" data-field="package_box_sn" value="${esc(r.package_box_sn)}" placeholder="请输入唯一码">`)}${cell(r,'box_weight',`<div class="unit-input"><input type="number" min="0" step="0.01" data-key="${r.key}" data-field="box_weight" value="${esc(r.box_weight)}" placeholder="0.00"><span class="unit">kg</span></div>`)}${cell(r,'quality_guaran_period',`<input type="date" data-key="${r.key}" data-field="quality_guaran_period" value="${esc(r.quality_guaran_period)}">`)}${cell(r,'box_type',`<select data-key="${r.key}" data-field="box_type"><option value="">请选择木箱类型</option>${Object.keys(boxTypes).map(x=>`<option ${r.box_type===x?'selected':''}>${x}</option>`).join('')}</select>`)}${cell(r,'box_length',`<div class="unit-input"><input readonly value="${esc(r.box_length)}" placeholder="自动带出"><span class="unit">mm</span></div>`)}${cell(r,'box_width',`<div class="unit-input"><input readonly value="${esc(r.box_width)}" placeholder="自动带出"><span class="unit">mm</span></div>`)}${cell(r,'box_high',`<div class="unit-input"><input readonly value="${esc(r.box_high)}" placeholder="自动带出"><span class="unit">mm</span></div>`)}${cell(r,'sale_order_name',`<input data-key="${r.key}" data-field="sale_order_name" value="${esc(r.sale_order_name)}" placeholder="请输入销售订单号">`)}${cell(r,'customer_name',`<input data-key="${r.key}" data-field="customer_name" value="${esc(r.customer_name)}" placeholder="请输入客户名称">`)}${cell(r,'date_of_fg_inbound',`<input type="date" data-key="${r.key}" data-field="date_of_fg_inbound" value="${esc(r.date_of_fg_inbound)}">`)}${cell(r,'container_name',`<input data-key="${r.key}" data-field="container_name" value="${esc(r.container_name)}" placeholder="请输入子卷号">`)}<td class="sticky-right"><div class="row-actions"><button class="btn text" data-action="copy" data-key="${r.key}">复制</button><button class="btn text danger" data-action="delete" data-key="${r.key}">删除</button></div></td></tr>`).join('');
$('rowCount').textContent=rows.length;$('submitBtn').textContent=`确认新增(${rows.length} 条)`;
}
body.addEventListener('input',e=>{const el=e.target,key=Number(el.dataset.key),field=el.dataset.field;if(!key||!field)return;const row=rows.find(x=>x.key===key);row[field]=el.value;errors=errors.filter(x=>!(x.rowKey===key&&x.field===field));const c=el.closest('.cell');if(c){c.classList.remove('invalid');c.querySelector('.error-text').textContent=''}if(!errors.length)resetNotice()});
body.addEventListener('change',e=>{const el=e.target,key=Number(el.dataset.key),field=el.dataset.field;if(field!=='box_type')return;const row=rows.find(x=>x.key===key),size=boxTypes[el.value];Object.assign(row,size||{length:'',width:'',high:''});row.box_length=row.length??'';row.box_width=row.width??'';row.box_high=row.high??'';delete row.length;delete row.width;delete row.high;render()});
body.addEventListener('click',e=>{const b=e.target.closest('[data-action]');if(!b)return;const idx=rows.findIndex(x=>x.key===Number(b.dataset.key));if(b.dataset.action==='copy'){const copy={...rows[idx],key:nextKey++,package_box_sn:'',container_name:''};rows.splice(idx+1,0,copy);errors=[];render();showToast('已复制第 '+(idx+1)+' 行,请补充唯一码和子卷号')}else{rows.splice(idx,1);if(!rows.length)rows=[emptyRow()];errors=[];render();resetNotice()}});
$('addRowBtn').onclick=()=>{rows.push(emptyRow());render();body.lastElementChild?.querySelector('input')?.focus()};
function hasContent(){return rows.some(r=>fields.some(f=>String(r[f]??'').trim()))}
function ask(title,text,action){$('confirmTitle').textContent=title;$('confirmText').textContent=text;confirmAction=action;$('confirmMask').classList.remove('hidden')}
$('clearBtn').onclick=()=>ask('清空全部数据','将清空当前已录入的所有内容,并恢复为 3 个空行。此操作不可撤销。',resetRows);
$('confirmCancel').onclick=()=>{$('confirmMask').classList.add('hidden');confirmAction=null};$('confirmOk').onclick=()=>{const fn=confirmAction;$('confirmMask').classList.add('hidden');confirmAction=null;fn?.()};
function closeModal(){modal.classList.add('hidden')}
function requestClose(){hasContent()?ask('放弃本次录入?','当前存在未提交的内容,关闭后将不会保留。',()=>{closeModal();resetRows()}):closeModal()}
$('cancelBtn').onclick=requestClose;$('closeBtn').onclick=requestClose;modal.addEventListener('click',e=>{if(e.target===modal)requestClose()});
$('openBatchBtn').onclick=()=>{resetRows();modal.classList.remove('hidden')};
function addError(row,field,message){if(!errors.some(e=>e.rowKey===row.key&&e.field===field))errors.push({rowKey:row.key,field,message})}
function validate(){errors=[];rows.forEach((r,i)=>{required.forEach(f=>{if(!String(r[f]??'').trim())addError(r,f,'此项为必填')});if(r.box_weight!==''&&Number(r.box_weight)<=0)addError(r,'box_weight','重量必须大于 0')});['package_box_sn','container_name'].forEach(field=>{const seen=new Map();rows.forEach((r,i)=>{const v=String(r[field]||'').trim();if(!v)return;if(seen.has(v)){const first=seen.get(v);addError(rows[first],field,`与第 ${i+1} 行重复`);addError(r,field,`与第 ${first+1} 行重复`)}else seen.set(v,i)})});render();if(errors.length){notice.classList.add('error');noticeText.textContent='⚠ 请检查表格中的必填项或重复数据。';$('errorSummary').textContent=`${errors.length} 处错误`;const first=errors[0];const input=document.querySelector(`[data-cell="${first.rowKey}-${first.field}"] input,[data-cell="${first.rowKey}-${first.field}"] select`);input?.focus();input?.scrollIntoView({block:'center',inline:'center'});return false}resetNotice();return true}
$('submitBtn').onclick=()=>{if(!validate())return;const btn=$('submitBtn'),n=rows.length;btn.disabled=true;btn.textContent='正在提交…';setTimeout(()=>{const r=rows[0];$('backgroundBody').insertAdjacentHTML('afterbegin',`<tr><td>${esc(r.package_box_sn)}</td><td><span class="tag">${esc(r.box_type)}</span></td><td>${esc(r.box_weight)}</td><td>${esc(r.sale_order_name)}</td><td>${esc(r.customer_name)}</td><td>${esc(r.date_of_fg_inbound)}</td><td>${esc(r.container_name)}</td><td><button class="btn text">编辑</button><button class="btn text danger">删除</button></td></tr>`);btn.disabled=false;closeModal();showToast(`成功新增 ${n} 条子卷包装关系`);resetRows()},650)};
function showToast(text){$('toastText').textContent=text;$('toast').classList.add('show');setTimeout(()=>$('toast').classList.remove('show'),2200)}
resetRows();
</script>
</body>
</html>