+
+
+
+
+
+
+
@@ -265,23 +362,339 @@ tr:hover td{background:#FAFAFA;}
function toggleSubgroup(header){header.parentElement.classList.toggle('open');}
(function(){var active=document.querySelector('.sidebar-item.active');if(!active)return;var sub=active.closest('.sidebar-subgroup');if(sub)sub.classList.add('open');})();
-function openModal(mode, name){
- var modal=document.getElementById('lineModal');
- var title=document.getElementById('modalTitle');
- var input=document.getElementById('lineName');
- if(mode==='edit'){
- title.textContent='编辑餐线';
- input.value=name||'';
+/* ========== 常量 ========== */
+var MEALS=['早餐','午餐','晚餐','加餐'];
+var WEEKDAYS=['周一','周二','周三','周四','周五','周六','周日'];
+var MODE_OPTIONS=[
+ {value:'byMeal',label:'按餐计费'},
+ {value:'byWeight',label:'称重计费'},
+ {value:'free',label:'免费'}
+];
+/* 生成收费模式矩阵:7天×4餐次,同一模式 */
+function genCharging(mode, prices){
+ return WEEKDAYS.map(function(){
+ return MEALS.map(function(_, mi){
+ return {mode:mode, price: mode==='byMeal' ? (prices&&prices[mi]||'') : ''};
+ });
+ });
+}
+
+/* ========== 餐线数据 ========== */
+var lines=[
+ {
+ id:'L1', name:'A餐线(自选餐)', settleType:'auto', status:'on',
+ charging: genCharging('byMeal', [8,15,15,6]),
+ devices:[
+ {type:'营养秤', code:'CL-A01', name:'餐线营养秤1号', days:326, online:true},
+ {type:'营养秤', code:'CL-A02', name:'餐线营养秤2号', days:326, online:true},
+ {type:'营养秤', code:'CL-A03', name:'餐线营养秤3号', days:210, online:false},
+ {type:'结算终端', code:'CL-A04', name:'结算终端1号', days:326, online:true},
+ {type:'结算终端', code:'CL-A05', name:'结算终端2号', days:300, online:true},
+ {type:'餐盘机', code:'CL-A06', name:'智能餐盘机1号', days:120, online:true}
+ ]
+ },
+ {
+ id:'L2', name:'B餐线(营养点餐)', settleType:'auto', status:'on',
+ charging: genCharging('byWeight'),
+ devices:[
+ {type:'营养秤', code:'CL-B01', name:'餐线营养秤4号', days:400, online:true},
+ {type:'营养秤', code:'CL-B02', name:'餐线营养秤5号', days:400, online:true},
+ {type:'结算终端', code:'CL-B03', name:'结算终端3号', days:400, online:false},
+ {type:'餐盘机', code:'CL-B04', name:'智能餐盘机2号', days:180, online:true}
+ ]
+ },
+ {
+ id:'L3', name:'C餐线(清真)', settleType:'manual', status:'off',
+ charging: genCharging('free'),
+ devices:[
+ {type:'营养秤', code:'CL-C01', name:'餐线营养秤6号', days:90, online:true},
+ {type:'结算终端', code:'CL-C02', name:'结算终端4号', days:90, online:false}
+ ]
+ }
+];
+
+/* ========== 列表渲染 ========== */
+function renderLines(){
+ document.getElementById('lineCount').textContent=lines.length;
+ document.getElementById('linePager').textContent='显示 '+lines.length+' 条,共 '+lines.length+' 条';
+ document.getElementById('lineTbody').innerHTML=lines.map(function(l){
+ var settle=l.settleType==='auto'?'自动结算':'手动结算';
+ var settleCls=l.settleType==='auto'?'tag-green':'tag-gray';
+ var status=l.status==='on'
+ ? '
启用 '
+ : '
停用 ';
+ var devCount='
'+l.devices.length+' ';
+ return '
'+
+ ''+l.name+' '+
+ ''+settle+' '+
+ ''+devCount+' '+
+ ''+status+' '+
+ '餐线设置 详情 删除 '+
+ ' ';
+ }).join('');
+}
+function toggleLineStatus(id){
+ var l=lines.find(function(x){return x.id===id;});
+ if(!l) return;
+ l.status=l.status==='on'?'off':'on';
+ renderLines();
+}
+function deleteLine(id){
+ var l=lines.find(function(x){return x.id===id;});
+ if(!l) return;
+ if(!confirm('确认删除餐线「'+l.name+'」?')) return;
+ lines=lines.filter(function(x){return x.id!==id;});
+ renderLines();
+}
+
+/* ========== 餐线设置弹窗 ========== */
+var editingLineId=null;
+var tempCharging=null;
+var tempStatus='on';
+
+function openLineModal(id){
+ editingLineId=id;
+ var title=document.getElementById('lineModalTitle');
+ var nameInput=document.getElementById('lineName');
+ var settle=document.getElementById('lineSettle');
+ document.getElementById('batchBar').style.display='none';
+ document.getElementById('batchMode').value='byMeal';
+ document.getElementById('batchPrice').value='';
+ onBatchModeChange();
+ if(id){
+ var l=lines.find(function(x){return x.id===id;});
+ if(!l) return;
+ title.textContent='餐线设置';
+ nameInput.value=l.name;
+ settle.value=l.settleType;
+ tempStatus=l.status;
+ tempCharging=JSON.parse(JSON.stringify(l.charging));
}else{
title.textContent='新增餐线';
- input.value='';
+ nameInput.value='';
+ settle.value='auto';
+ tempStatus='on';
+ tempCharging=genCharging('free');
}
- modal.classList.add('show');
+ renderStatusSwitch();
+ renderChargeTable();
+ document.getElementById('lineModal').classList.add('show');
}
-function closeModal(e){
+function closeLineModal(e){
if(e&&e.target!==e.currentTarget)return;
document.getElementById('lineModal').classList.remove('show');
}
+function renderStatusSwitch(){
+ var sw=document.getElementById('lineStatusSwitch');
+ sw.classList.toggle('on',tempStatus==='on');
+ sw.classList.toggle('off',tempStatus!=='on');
+ sw.textContent=tempStatus==='on'?'启用':'停用';
+}
+function toggleLineStatusSwitch(){
+ tempStatus=tempStatus==='on'?'off':'on';
+ renderStatusSwitch();
+}
+
+/* ========== 收费模式矩阵 ========== */
+function renderChargeTable(){
+ var html='
星期 ';
+ MEALS.forEach(function(m){html+=''+m+' ';});
+ html+='';
+ for(var w=0;w<7;w++){
+ html+=''+WEEKDAYS[w]+' ';
+ for(var m=0;m<4;m++){
+ var cell=tempCharging[w][m];
+ var opts=MODE_OPTIONS.map(function(o){
+ return ''+o.label+' ';
+ }).join('');
+ var isMeal=cell.mode==='byMeal';
+ html+=''+
+ ''+opts+' '+
+ ' '+
+ '元 '+
+ ' ';
+ }
+ html+=' ';
+ }
+ html+=' ';
+ document.getElementById('chargeTable').innerHTML=html;
+}
+function onModeChange(sel){
+ var w=parseInt(sel.dataset.w,10), m=parseInt(sel.dataset.m,10);
+ var mode=sel.value;
+ tempCharging[w][m].mode=mode;
+ if(mode!=='byMeal'){ tempCharging[w][m].price=''; }
+ /* 刷新该格金额框禁用态、占位符与单位显隐 */
+ var row=document.querySelectorAll('#chargeTable tbody tr')[w];
+ var cell=row.querySelectorAll('td')[m+1];
+ var priceInput=cell.querySelector('.cm-price');
+ var unit=cell.querySelector('.cm-unit');
+ var isMeal=(mode==='byMeal');
+ priceInput.disabled=!isMeal;
+ priceInput.placeholder=isMeal?'金额':'-';
+ priceInput.value=tempCharging[w][m].price||'';
+ unit.style.display=isMeal?'':'none';
+}
+function onPriceChange(inp){
+ var w=parseInt(inp.dataset.w,10), m=parseInt(inp.dataset.m,10);
+ tempCharging[w][m].price=inp.value;
+}
+/* 批量设置 */
+function toggleBatchBar(){
+ var bar=document.getElementById('batchBar');
+ bar.style.display=bar.style.display==='none'?'flex':'none';
+}
+function onBatchModeChange(){
+ var mode=document.getElementById('batchMode').value;
+ var show=(mode==='byMeal');
+ document.getElementById('batchPriceLabel').style.display=show?'':'none';
+ document.getElementById('batchPrice').style.display=show?'':'none';
+ if(!show) document.getElementById('batchPrice').value='';
+}
+function applyBatch(){
+ var mode=document.getElementById('batchMode').value;
+ var price=document.getElementById('batchPrice').value.trim();
+ if(mode==='byMeal' && !price){ alert('按餐计费请填写计费金额'); return; }
+ for(var w=0;w<7;w++){
+ for(var m=0;m<4;m++){
+ tempCharging[w][m].mode=mode;
+ tempCharging[w][m].price=(mode==='byMeal'?price:'');
+ }
+ }
+ renderChargeTable();
+}
+/* 确认保存 */
+function confirmLine(){
+ var name=document.getElementById('lineName').value.trim();
+ var settle=document.getElementById('lineSettle').value;
+ if(!name){ alert('请输入餐线名称'); return; }
+ for(var w=0;w<7;w++){
+ for(var m=0;m<4;m++){
+ var c=tempCharging[w][m];
+ if(c.mode==='byMeal' && !String(c.price).trim()){ alert('请为「'+WEEKDAYS[w]+' '+MEALS[m]+'」的按餐计费填写计费金额'); return; }
+ }
+ }
+ if(editingLineId){
+ var l=lines.find(function(x){return x.id===editingLineId;});
+ if(l){
+ l.name=name; l.settleType=settle; l.status=tempStatus;
+ l.charging=JSON.parse(JSON.stringify(tempCharging));
+ }
+ }else{
+ lines.push({
+ id:'L'+Date.now(),
+ name:name, settleType:settle, status:tempStatus,
+ charging:JSON.parse(JSON.stringify(tempCharging)),
+ devices:[]
+ });
+ }
+ closeLineModal();
+ renderLines();
+}
+
+/* ========== 设备列表概况弹窗 ========== */
+function openDeviceModal(id){
+ var l=lines.find(function(x){return x.id===id;});
+ if(!l) return;
+ document.getElementById('deviceModalTitle').textContent='设备列表 — '+l.name;
+ var body=document.getElementById('deviceModalBody');
+ if(l.devices.length===0){
+ body.innerHTML='
该餐线暂无关联设备
';
+ }else{
+ var rows=l.devices.map(function(d){
+ var onlineTag=d.online?'
在线 ':'
离线 ';
+ return '
'+d.type+' '+d.code+' '+d.name+' '+d.days+' 天 '+onlineTag+' ';
+ }).join('');
+ body.innerHTML='
'+
+ '设备类型 编号 设备名称 运行天数 在线状态 '+
+ ''+rows+' '+
+ '
';
+ }
+ document.getElementById('deviceModal').classList.add('show');
+}
+function closeDeviceModal(e){
+ if(e&&e.target!==e.currentTarget)return;
+ document.getElementById('deviceModal').classList.remove('show');
+}
+
+/* ========== 餐线详情弹窗 ========== */
+var detailLineId=null;
+var detailPage=1;
+var DETAIL_PAGE_SIZE=5;
+function openLineDetail(id){
+ var l=lines.find(function(x){return x.id===id;});
+ if(!l) return;
+ detailLineId=id;
+ detailPage=1;
+ document.getElementById('detailModalTitle').textContent='餐线详情 — '+l.name;
+ renderDetail();
+ document.getElementById('detailModal').classList.add('show');
+}
+function closeDetailModal(e){
+ if(e&&e.target!==e.currentTarget)return;
+ document.getElementById('detailModal').classList.remove('show');
+}
+function renderDetail(){
+ var l=lines.find(function(x){return x.id===detailLineId;});
+ if(!l) return;
+ var settle=l.settleType==='auto'?'自动结算':'手动结算';
+ var statusTag=l.status==='on'?'
启用 ':'
停用 ';
+ /* 基础信息 */
+ var html='
基础信息
'+
+ '
'+
+ '
餐线名称 '+l.name+'
'+
+ '
结算方式 '+settle+'
'+
+ '
状态 '+statusTag+'
'+
+ '
';
+ /* 收费模式只读回显 */
+ html+='
收费模式
';
+ html+='
星期 ';
+ MEALS.forEach(function(m){html+=''+m+' ';});
+ html+='';
+ for(var w=0;w<7;w++){
+ html+=''+WEEKDAYS[w]+' ';
+ for(var m=0;m<4;m++){
+ var c=l.charging[w][m];
+ var txt=c.mode==='byMeal'
+ ? '按餐计费 '+c.price+' 元 '
+ : (c.mode==='byWeight'?'称重计费 ':'免费 ');
+ html+=''+txt+' ';
+ }
+ html+=' ';
+ }
+ html+='
';
+ /* 设备列表(带分页) */
+ html+='
关联设备
';
+ var devices=l.devices;
+ if(devices.length===0){
+ html+='
暂无关联设备
';
+ }else{
+ var totalPages=Math.max(1,Math.ceil(devices.length/DETAIL_PAGE_SIZE));
+ if(detailPage>totalPages) detailPage=totalPages;
+ var start=(detailPage-1)*DETAIL_PAGE_SIZE;
+ var pageDevices=devices.slice(start,start+DETAIL_PAGE_SIZE);
+ var rows=pageDevices.map(function(d){
+ var onlineTag=d.online?'
在线 ':'
离线 ';
+ return '
'+d.type+' '+d.code+' '+d.name+' '+d.days+' 天 '+onlineTag+' ';
+ }).join('');
+ html+='
'+
+ '设备类型 编号 设备名称 运行天数 在线状态 '+
+ ''+rows+'
';
+ var pageBtns='';
+ for(var i=1;i<=totalPages;i++){
+ pageBtns+='
'+i+' ';
+ }
+ html+='';
+ }
+ document.getElementById('detailModalBody').innerHTML=html;
+}
+function detailGoPage(p){
+ detailPage=p;
+ renderDetail();
+}
+
+/* 初始渲染 */
+renderLines();