打印状态移至备注后并在点击打印时自动记录
This commit is contained in:
1 parent
846a30cded
commit
c12f2157b4
6 files changed
+80
-40
No files matched your search
@@ -358,3 +358,9 @@ button.order-copy-button:focus-visible{outline:3px solid var(--gold);outline-off
|
||||
.private-ops-summary{min-width:980px}.private-ops-summary th.number{text-align:right}.private-ops-summary tbody th{background:var(--white);color:var(--ink);font-size:13px;font-weight:650;vertical-align:middle}.private-ops-summary td{vertical-align:middle;padding:11px 12px;font-variant-numeric:tabular-nums}.private-ops-summary td .small{margin-top:4px;font-size:11px}.private-ops-summary td:last-child{white-space:nowrap}.private-ops-summary tbody tr:hover td,.private-ops-summary tbody tr:hover th{background:#f5f7f2}.private-ops-summary th:first-child{position:sticky;left:0;z-index:1;min-width:90px;border-right:1px solid var(--border)}.private-ops-summary-wrap:focus-visible{outline:2px solid var(--green);outline-offset:2px}
|
||||
|
||||
.private-people-history{min-width:520px}.private-people-history th[colspan]{text-align:center;border-left:1px solid var(--border)}.private-people-history th.number{text-align:right}.private-people-history tbody th{color:var(--ink);font-size:13px;font-weight:500;background:var(--white);vertical-align:middle}.private-people-history td{vertical-align:middle;font-variant-numeric:tabular-nums}.private-people-history td:nth-child(2n){border-left:1px solid var(--border)}.private-people-history .link-button{font-weight:600;padding:6px 0}.private-people-history .small{margin-top:4px;font-size:11px}.private-people-history th:first-child[rowspan],.private-people-history tbody th{position:sticky;left:0;z-index:1}.private-people-history tbody tr:hover td,.private-people-history tbody tr:hover th{background:#f5f7f2}
|
||||
|
||||
/* 打印状态放备注后,避免撑高客户名称区域。 */
|
||||
.order-book-table .order-print-status{width:76px;min-width:76px;white-space:nowrap;text-align:center}
|
||||
.order-book-table .document-print-badge{padding:1px 5px;margin:0;font-size:11px;font-weight:500}
|
||||
.order-book-table .document-print-badge.is-unprinted{color:var(--muted);background:transparent}
|
||||
.order-mobile-print-status{margin-top:6px}
|
||||
+6
-15
@@ -1052,18 +1052,19 @@ function renderOrderBook(book,range){
|
||||
$('#order-book-scope').textContent=orderBookScope();$('#order-book-count').textContent=`${range.name} · 汇总 ${s.orderCount} 单${recoveryCount?' · 回收 '+recoveryCount+' 笔':''}${s.afterSaleCount?' · 售后 '+s.afterSaleCount+' 笔':''}${cancelledCount?',另有 '+cancelledCount+' 单取消未计':''}${orderBookFilters.q||orderBookFilters.status||orderBookFilters.pocket||orderBookFilters.member?'(已筛选)':''}`;$('#order-list').setAttribute('aria-busy','false');
|
||||
const rows=book.displayRows??book.rows;
|
||||
if(!rows.length){$('#order-list').innerHTML='<div class="empty"><strong>这个日期没有符合条件的订单、回收或售后</strong>可以切换日期,或调整搜索和状态筛选。</div>';return;}
|
||||
$('#order-list').innerHTML=`<div class="table-wrap order-book-table-wrap"><table class="order-book-table" aria-label="${e(range.name)}订单账本"><thead><tr><th class="order-index">序号</th><th>客户/销售、回收或售后</th><th>类型</th><th class="number">克重/件数</th><th class="number">售价</th><th class="number">料成本</th><th class="number">工费及附加成本</th><th class="number">成本合计</th><th class="number">利润</th><th>备注</th></tr></thead><tbody>${rows.map((row,i)=>`<tr class="${['afterSale','orderAfterSale'].includes(row.kind)?'order-after-sale':row.kind==='recovery'?'order-recovery':row.status==='draft'?'order-draft':row.status==='returned'||row.status==='cancelled'?'order-reversed':''}"><td class="order-index">${i+1}</td><td class="order-customer">${orderBookIdentity(row,detailList.version)}<div class="small muted">业务日期 ${e(row.date)} · ${row.kind==='recovery'?'<span class="order-status muted">已记录</span>':badge(row)}${orderReviewBadge(row)} ${printStatusBadge(row)}</div>${!['afterSale','orderAfterSale','recovery'].includes(row.kind)?orderEntryTimeHTML(row):''}${showOrderCopyEntry&&!['afterSale','orderAfterSale','recovery'].includes(row.kind)?button('<span aria-hidden="true">+</span>复制新增','copy-order','order-copy-button',`data-id="${e(row.id)}" aria-label="复制 ${e(row.paper_number||row.number)} 为新订单"`):''}${row.status==='cancelled'?'<div class="small muted">未计入汇总</div>':''}${row.balance<0?'<div class="small danger-text">退款待处理</div>':''}</td><td class="order-type">${row.types.map(e).join('<br>')||'—'}</td><td class="number">${orderBookQuantity(row)}${row.kind==='recovery'?'<div class="small muted">折后克重</div>':''}</td><td class="number">${orderBookMoney(row,'sale')}</td><td class="number">${orderBookMoney(row,'material')}</td><td class="number order-fees">${orderBookMoney(row,'laborAndFees')}${orderBookFeeParts(row)}</td><td class="number">${orderBookMoney(row,'totalCost')}${row.unallocated?`<div class="small muted">含未分项 ¥${yuan(row.unallocated)}</div>`:''}${row.pendingCosts?'<div class="small danger-text">另有 '+row.pendingCosts+' 项费用未入账</div>':''}</td><td class="number order-profit">${orderBookMoney(row,'profit')}</td><td class="order-notes">${row.kind==='afterSale'?e(afterSalePayerName(row)+'支付'):e(row.note)||'<span class="muted">—</span>'}${row.costHint?`<div class="small ${row.incomplete?'danger-text':'muted'}">${e(row.costHint)}</div>`:''}</td></tr>`).join('')}</tbody><tfoot><tr><td colspan="2">汇总 ${s.orderCount} 单${recoveryCount?'<br>回收 '+recoveryCount+' 笔':''}${s.afterSaleCount?'<br>售后 '+s.afterSaleCount+' 笔':''}</td><td></td><td class="number">${orderBookSummaryQuantity(s)}</td><td class="number">${orderBookSummaryAmount(s,'sale')}</td><td class="number">${orderBookSummaryAmount(s,'material')}</td><td class="number">${orderBookSummaryAmount(s,'laborAndFees')}</td><td class="number">${costPartial?'已知 ':''}¥${yuan(s.totalCost)}${s.unallocated?`<div class="small muted">含未分项 ¥${yuan(s.unallocated)}</div>`:''}</td><td class="number">${orderBookSummaryAmount(s,'profit')}</td><td class="small order-notes">${[cancelledCount?cancelledCount+' 单取消未计汇总':'',s.draftCount?s.draftCount+' 单草稿未计金额':'',s.unknownCostCount?s.unknownCostCount+' 单成本未补齐':'',profitMissing?profitMissing+' 单利润待补齐':''].filter(Boolean).join(';')||'账本金额'}</td></tr></tfoot></table></div>`;
|
||||
$('#order-list').innerHTML=`<div class="table-wrap order-book-table-wrap"><table class="order-book-table" aria-label="${e(range.name)}订单账本"><thead><tr><th class="order-index">序号</th><th>客户/销售、回收或售后</th><th>类型</th><th class="number">克重/件数</th><th class="number">售价</th><th class="number">料成本</th><th class="number">工费及附加成本</th><th class="number">成本合计</th><th class="number">利润</th><th>备注</th><th class="order-print-status">打印状态</th></tr></thead><tbody>${rows.map((row,i)=>`<tr class="${['afterSale','orderAfterSale'].includes(row.kind)?'order-after-sale':row.kind==='recovery'?'order-recovery':row.status==='draft'?'order-draft':row.status==='returned'||row.status==='cancelled'?'order-reversed':''}"><td class="order-index">${i+1}</td><td class="order-customer">${orderBookIdentity(row,detailList.version)}<div class="small muted">业务日期 ${e(row.date)} · ${row.kind==='recovery'?'<span class="order-status muted">已记录</span>':badge(row)}${orderReviewBadge(row)}</div>${!['afterSale','orderAfterSale','recovery'].includes(row.kind)?orderEntryTimeHTML(row):''}${showOrderCopyEntry&&!['afterSale','orderAfterSale','recovery'].includes(row.kind)?button('<span aria-hidden="true">+</span>复制新增','copy-order','order-copy-button',`data-id="${e(row.id)}" aria-label="复制 ${e(row.paper_number||row.number)} 为新订单"`):''}${row.status==='cancelled'?'<div class="small muted">未计入汇总</div>':''}${row.balance<0?'<div class="small danger-text">退款待处理</div>':''}</td><td class="order-type">${row.types.map(e).join('<br>')||'—'}</td><td class="number">${orderBookQuantity(row)}${row.kind==='recovery'?'<div class="small muted">折后克重</div>':''}</td><td class="number">${orderBookMoney(row,'sale')}</td><td class="number">${orderBookMoney(row,'material')}</td><td class="number order-fees">${orderBookMoney(row,'laborAndFees')}${orderBookFeeParts(row)}</td><td class="number">${orderBookMoney(row,'totalCost')}${row.unallocated?`<div class="small muted">含未分项 ¥${yuan(row.unallocated)}</div>`:''}${row.pendingCosts?'<div class="small danger-text">另有 '+row.pendingCosts+' 项费用未入账</div>':''}</td><td class="number order-profit">${orderBookMoney(row,'profit')}</td><td class="order-notes">${row.kind==='afterSale'?e(afterSalePayerName(row)+'支付'):e(row.note)||'<span class="muted">—</span>'}${row.costHint?`<div class="small ${row.incomplete?'danger-text':'muted'}">${e(row.costHint)}</div>`:''}</td><td class="order-print-status">${printStatusBadge(row)||'—'}</td></tr>`).join('')}</tbody><tfoot><tr><td colspan="2">汇总 ${s.orderCount} 单${recoveryCount?'<br>回收 '+recoveryCount+' 笔':''}${s.afterSaleCount?'<br>售后 '+s.afterSaleCount+' 笔':''}</td><td></td><td class="number">${orderBookSummaryQuantity(s)}</td><td class="number">${orderBookSummaryAmount(s,'sale')}</td><td class="number">${orderBookSummaryAmount(s,'material')}</td><td class="number">${orderBookSummaryAmount(s,'laborAndFees')}</td><td class="number">${costPartial?'已知 ':''}¥${yuan(s.totalCost)}${s.unallocated?`<div class="small muted">含未分项 ¥${yuan(s.unallocated)}</div>`:''}</td><td class="number">${orderBookSummaryAmount(s,'profit')}</td><td class="small order-notes">${[cancelledCount?cancelledCount+' 单取消未计汇总':'',s.draftCount?s.draftCount+' 单草稿未计金额':'',s.unknownCostCount?s.unknownCostCount+' 单成本未补齐':'',profitMissing?profitMissing+' 单利润待补齐':''].filter(Boolean).join(';')||'账本金额'}</td><td></td></tr></tfoot></table></div>`;
|
||||
$('#order-list').insertAdjacentHTML?.('beforeend',orderBookMobileCards(rows,detailList.version,showOrderCopyEntry));
|
||||
}
|
||||
function orderBookMobileCards(rows,version,showCopy){
|
||||
return `<div class="order-mobile-list">${rows.map(row=>`<article class="order-mobile-card ${row.status==='cancelled'||row.status==='returned'?'order-reversed':''}">
|
||||
<div class="order-mobile-heading">${orderBookIdentity(row,version)}</div>
|
||||
<div class="order-mobile-meta">${e(row.date)} · ${row.kind==='recovery'?'已记录':badge(row)} ${orderReviewBadge(row)} ${printStatusBadge(row)}</div>
|
||||
<div class="order-mobile-meta">${e(row.date)} · ${row.kind==='recovery'?'已记录':badge(row)} ${orderReviewBadge(row)}</div>
|
||||
<div class="order-mobile-amounts"><div><span>克重/件数${row.kind==='recovery'?'(折后)':''}</span><strong>${orderBookQuantity(row)}</strong></div><div><span>售价</span><strong>${orderBookMoney(row,'sale')}</strong></div></div>
|
||||
${row.status==='cancelled'?'<p class="small muted">已取消,未计入汇总</p>':''}${row.balance<0?'<p class="small danger-text">退款待处理</p>':''}
|
||||
<details class="order-mobile-breakdown"><summary>成本、利润与备注</summary>
|
||||
<dl><div><dt>货盘/类型</dt><dd>${row.types.map(e).join('、')||'—'}</dd></div><div><dt>料成本</dt><dd>${orderBookMoney(row,'material')}</dd></div><div><dt>工费及附加成本</dt><dd>${orderBookMoney(row,'laborAndFees')}${orderBookFeeParts(row)}</dd></div><div><dt>成本合计</dt><dd>${orderBookMoney(row,'totalCost')}${row.unallocated?'<div class="small muted">含未分项 ¥'+yuan(row.unallocated)+'</div>':''}${row.pendingCosts?'<div class="small danger-text">另有 '+row.pendingCosts+' 项费用未入账</div>':''}</dd></div><div><dt>利润</dt><dd>${orderBookMoney(row,'profit')}</dd></div></dl>
|
||||
<div class="order-mobile-note">${row.kind==='afterSale'?e(afterSalePayerName(row)+'支付'):e(row.note)||'暂无备注'}</div>
|
||||
<div class="order-mobile-print-status">${printStatusBadge(row)}</div>
|
||||
${row.costHint?`<p class="small ${row.incomplete?'danger-text':'muted'}">${e(row.costHint)}</p>`:''}
|
||||
${!['afterSale','orderAfterSale','recovery'].includes(row.kind)?orderEntryTimeHTML(row):''}
|
||||
${showCopy&&!['afterSale','orderAfterSale','recovery'].includes(row.kind)?button('复制新增','copy-order','order-copy-button',`data-id="${e(row.id)}"`):''}
|
||||
@@ -1320,18 +1321,10 @@ function readReturnCounts(form,pockets){return pockets.map((pocket,index)=>{if(!
|
||||
function printStatusBadge(value){
|
||||
if(['afterSale','orderAfterSale'].includes(value.kind))return '';
|
||||
const printed=value.printStatus?.printed;
|
||||
return `<span data-print-kind="${e(value.printStatus?.kind||(value.kind==='recovery'?'recovery':'order'))}" data-print-id="${e(value.printStatus?.id||value.id)}" class="document-print-badge ${printed?'is-printed':'is-unprinted'}" title="${printed?'已人工确认打印':'没有打印确认记录,旧单可补标记'}">${printed?'✓ 已打印':'未打印'}</span>`;
|
||||
return `<span data-print-kind="${e(value.printStatus?.kind||(value.kind==='recovery'?'recovery':'order'))}" data-print-id="${e(value.printStatus?.id||value.id)}" class="document-print-badge ${printed?'is-printed':'is-unprinted'}" title="${printed?'已记录打印操作':'尚未记录打印操作'}">${printed?'✓ 已打印':'未打印'}</span>`;
|
||||
}
|
||||
function printStatusControls(value,kind='order'){
|
||||
return `<div class="document-print-controls">${printStatusBadge(value)}${button(value.printStatus?.printed?'改为未打印':'确认已打印','document-print-toggle','quiet',`data-kind="${kind}" data-id="${e(value.id)}" data-printed="${!value.printStatus?.printed}"`)}<small class="muted">打印后确认;仅打开预览不算已打印。</small></div>`;
|
||||
}
|
||||
async function changeDocumentPrint(kind,id,printed){
|
||||
const url='/api/print-status/'+kind+'/'+encodeURIComponent(id),user=state.user.id;
|
||||
const value=await api(url);if(state.user?.id!==user)return;
|
||||
if(value.printed!==printed)await mutate(url,{printed,revision:value.revision,sourceRevision:value.sourceRevision});
|
||||
toast(printed?'已确认打印':'已改为未打印');
|
||||
await refresh();
|
||||
if(kind==='recovery')await openRecovery(id);else await openOrder(id);
|
||||
return `<div class="document-print-controls">${printStatusBadge(value)}<small class="muted">点击客户预览里的“打印”后自动记录。</small></div>`;
|
||||
}
|
||||
function renderDetail(){
|
||||
if(typeof invalidateOrderAfterSaleForm==='function')invalidateOrderAfterSaleForm();
|
||||
@@ -2146,7 +2139,6 @@ document.addEventListener('click',async ev=>{
|
||||
if(a==='edit'){if(state.user.role!=='owner')throw new Error('已有草稿由店主继续填写并开单;资料更正请从原单申请修改。');createMode='direct';orderTemplateSelection='';editDraft=draftInputs(currentOrder);$('#order-dialog').close();tab='create';return render();}
|
||||
if(a.startsWith('show-'))return showAction(a.slice(5));
|
||||
if(a==='hide-action'){$('#detail-form').innerHTML='';orderDetailSwitchError='';updateOrderDetailNavigation();return;}
|
||||
if(a==='document-print-toggle')return await changeDocumentPrint(b.dataset.kind,b.dataset.id,b.dataset.printed==='true');
|
||||
if(a==='print'){
|
||||
if(b.closest('#print-settings')){
|
||||
if(typeof shopSettingsDirty==='function'&&shopSettingsDirty())throw new Error('店铺配置尚未保存,请先保存再打开预览。');
|
||||
@@ -2248,8 +2240,7 @@ if(typeof window!=='undefined')window.addEventListener?.('storage',async event=>
|
||||
document.querySelectorAll('[data-print-kind][data-print-id]').forEach(node=>{
|
||||
if(node.dataset.printKind!==status.kind||node.dataset.printId!==status.id)return;
|
||||
node.textContent=status.printed?'✓ 已打印':'未打印';node.classList.toggle('is-printed',status.printed);node.classList.toggle('is-unprinted',!status.printed);
|
||||
node.title=status.printed?'已人工确认打印':'没有打印确认记录,旧单可补标记';
|
||||
const button=node.parentElement?.querySelector('[data-action="document-print-toggle"]');if(button){button.textContent=status.printed?'改为未打印':'确认已打印';button.dataset.printed=String(!status.printed);}
|
||||
node.title=status.printed?'已记录打印操作':'尚未记录打印操作';
|
||||
});
|
||||
if(currentOrder?.printStatus?.id===status.id)currentOrder.printStatus=status;
|
||||
if(typeof recoveryDetail!=='undefined'&&recoveryDetail?.printStatus?.id===status.id)recoveryDetail.printStatus=status;
|
||||
|
||||
+36
-19
@@ -53,27 +53,44 @@
|
||||
window.addEventListener('beforeprint',()=>{printing=true;try{preparePrint();document.body.classList.remove('fit-error');}catch{failed();}});
|
||||
window.addEventListener('afterprint',()=>{printing=false;fit();});
|
||||
printMedia.addEventListener('change',event=>{if(!event.matches){printing=false;fit();}});
|
||||
button.addEventListener('click',async()=>{await ready();if(fit())window.print();});
|
||||
button.addEventListener('click',async()=>{await ready();if(fit()){window.recordDocumentPrint?.();window.print();}});
|
||||
})();
|
||||
|
||||
// 浏览器不能确认纸张是否输出,必须由操作人确认,不监听 afterprint 写入。
|
||||
// 以点击页面“打印”为已打印依据;仅预览、加载或关闭系统打印窗口不写状态。
|
||||
(()=>{
|
||||
const label=document.getElementById('document-print-state'),button=document.getElementById('confirm-document-print'),error=document.getElementById('document-print-error');
|
||||
if(!label?.dataset?.state||!button)return;
|
||||
let state=JSON.parse(label.dataset.state),pending=null;
|
||||
const render=()=>{label.textContent=state.printed?'✓ 已打印':'未打印(未登记)';button.textContent=state.printed?'改为未打印':'确认已打印';};
|
||||
button.addEventListener('click',async()=>{
|
||||
button.disabled=true;error.textContent='';
|
||||
const url='/api/print-status/'+state.kind+'/'+state.id;
|
||||
if(!pending)pending={key:crypto.randomUUID(),body:JSON.stringify({printed:!state.printed,revision:state.revision,sourceRevision:state.sourceRevision})};
|
||||
const label=document.getElementById('document-print-state'),retry=document.getElementById('retry-document-print'),error=document.getElementById('document-print-error');
|
||||
if(!label?.dataset?.state||!retry||!error)return;
|
||||
let state=JSON.parse(label.dataset.state),pending=null,saving=false;
|
||||
const url='/api/print-status/'+state.kind+'/'+state.id;
|
||||
function render(){label.textContent=state.printed?'✓ 已打印':'未打印';}
|
||||
function notify(){try{localStorage.setItem('ledger-print-status-changed',JSON.stringify({user:state.user,kind:state.kind,id:state.id,time:Date.now()}));}catch{}}
|
||||
async function save(){
|
||||
if(saving)return;
|
||||
if(state.printed&&!pending){notify();return;}
|
||||
saving=true;retry.hidden=true;retry.disabled=true;error.textContent='正在保存打印记录…';
|
||||
if(!pending)pending={key:crypto.randomUUID(),body:JSON.stringify({printed:true,revision:state.revision,sourceRevision:state.sourceRevision})};
|
||||
try{
|
||||
const response=await fetch(url,{method:'POST',headers:{'Content-Type':'application/json','X-Requested-With':'maimai-ledger','X-Ledger-User':state.user,'Idempotency-Key':pending.key},body:pending.body,signal:AbortSignal.timeout(15000)});
|
||||
const result=await response.json();
|
||||
if(!response.ok){if(response.status===409){pending=null;button.hidden=true;error.textContent=(result.error||'状态已变化')+',请刷新打印页。';return;}throw new Error(result.error||'保存失败,请重试');}
|
||||
state={...state,...result,kind:state.kind,id:state.id};pending=null;render();
|
||||
// 同源内部页面收到通知后只刷新状态,不触碰正在填写的表单。
|
||||
try{localStorage.setItem('ledger-print-status-changed',JSON.stringify({user:state.user,kind:state.kind,id:state.id,time:Date.now()}));}catch{}
|
||||
}catch(err){error.textContent=(err.name==='TimeoutError'?'网络超时':err.message)+';请重试确认,不会重复记账。';}
|
||||
finally{button.disabled=false;}
|
||||
});
|
||||
for(let attempt=0;attempt<2;attempt++){
|
||||
try{
|
||||
const response=await fetch(url,{method:'POST',headers:{'Content-Type':'application/json','X-Requested-With':'maimai-ledger','X-Ledger-User':state.user,'Idempotency-Key':pending.key},body:pending.body,signal:AbortSignal.timeout(15000)});
|
||||
const result=await response.json();
|
||||
if(!response.ok){
|
||||
if(response.status===409){
|
||||
if(result.code!=='ACCOUNT_CHANGED'){
|
||||
const latestResponse=await fetch(url,{headers:{'X-Ledger-User':state.user},signal:AbortSignal.timeout(15000)});
|
||||
const latest=await latestResponse.json();
|
||||
if(latestResponse.ok&&latest.sourceRevision===state.sourceRevision&&latest.printed){state={...state,...latest};pending=null;render();notify();error.textContent='';return;}
|
||||
}
|
||||
pending=null;error.textContent=(result.error||'单据或账号已变化')+',请刷新打印页后重新打印。';return;
|
||||
}
|
||||
throw Object.assign(new Error(result.error||'保存失败'),{status:response.status});
|
||||
}
|
||||
state={...state,...result};pending=null;render();notify();error.textContent='';return;
|
||||
}catch(err){if(attempt===1||err.status&&err.status<500)throw err;}
|
||||
}
|
||||
}catch(err){error.textContent=(err.name==='TimeoutError'?'网络超时':err.message)+';打印记录尚未确认,请重试保存。';retry.hidden=false;}
|
||||
finally{saving=false;retry.disabled=false;}
|
||||
}
|
||||
window.recordDocumentPrint=save;
|
||||
retry.addEventListener('click',()=>{if(pending)save();});
|
||||
})();
|
||||
Reference in new issue
Block a user