订单增加打印登记,支持多商品销售公式识别预填
This commit is contained in:
1 parent
6cde5e6999
commit
718dbfde2c
13 files changed
+339
-15
No files matched your search
@@ -55,3 +55,25 @@
|
||||
printMedia.addEventListener('change',event=>{if(!event.matches){printing=false;fit();}});
|
||||
button.addEventListener('click',async()=>{await ready();if(fit())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})};
|
||||
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;}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user