feat: Minhas folhas on the Site: save a cart item to the account, order it again with the files already on the server, edit it without sending them again (Rodada 5, B9)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -190,6 +190,29 @@ function aplicaTratamento(aPagar){
|
||||
check.checked=ajusteTudo;check.disabled=false;mostraAvisoTratamento('');
|
||||
}
|
||||
}
|
||||
// Minhas folhas: the files of an item, and whether they are all already on
|
||||
// the server (or the item came back from Minhas folhas with its own ids).
|
||||
function arquivosDoItem(it){
|
||||
return [...(it.localFiles||[]),...(it.partes||[]).flatMap(p=>p.localFiles||[])];
|
||||
}
|
||||
function podeSalvarFolha(it){
|
||||
if((it.savedFiles||[]).length || (it.partes||[]).some(p=>(p.savedFiles||[]).length)) return true;
|
||||
return arquivosDoItem(it).every(f=>!!window.dtfEnvio?.idDe(f));
|
||||
}
|
||||
// The cart item as Minhas folhas keeps it: files become their upload ids,
|
||||
// without the pictures and without the cart's own marks.
|
||||
function itemParaSalvar(it){
|
||||
const copia=JSON.parse(JSON.stringify(it));
|
||||
const pares=[{orig:it,dest:copia}];
|
||||
(it.partes||[]).forEach((p,i)=>pares.push({orig:p,dest:copia.partes[i]}));
|
||||
for(const {orig,dest} of pares){
|
||||
dest.savedFiles=(orig.savedFiles||[]).length ? orig.savedFiles : (orig.localFiles||[]).map(f=>({
|
||||
upload_id:window.dtfEnvio?.idDe(f),name:f.name,size:f.size,lastModified:f.lastModified,type:f.type
|
||||
}));
|
||||
delete dest.localFiles; delete dest.fotos; delete dest.marcado;
|
||||
}
|
||||
return copia;
|
||||
}
|
||||
// O carrinho junta itens de produtos diferentes e cobra uma vez só.
|
||||
function pintaPedido(){
|
||||
const aPagar = itensAPagar();
|
||||
@@ -221,6 +244,9 @@ function pintaPedido(){
|
||||
'<div class="nm2"><b>'+escapeHTML(it.tit)+'</b><span>'+escapeHTML(it.desc)+'</span>'+
|
||||
(semMargem(it)?'<span class="avisoF">O espaço entre as cópias passou a ser de 8 mm. Remova este item e adicione a folha de novo.</span>':'')+'</div>'+
|
||||
'<div class="vl2">'+rs(it.total)+'</div>'+
|
||||
(window.dtfContaAberta?'<button type="button" class="salvaBt" data-salvai="'+i+'"'+
|
||||
(podeSalvarFolha(it)?'':' disabled title="Espere os arquivos terminarem de enviar."')+
|
||||
'>Salvar em Minhas folhas</button>':'')+
|
||||
'<button type="button" class="x" data-rmi="'+i+'" aria-label="Remover '+escapeHTML(it.tit)+'">'+icone('lixeira')+'<span>Remover</span></button></div>').join('');
|
||||
$('itens').querySelectorAll('[data-sel]').forEach(c=>c.addEventListener('change',()=>{
|
||||
pedido[+c.dataset.sel].marcado=c.checked; pintaPedido();
|
||||
@@ -232,6 +258,20 @@ function pintaPedido(){
|
||||
pedido.splice(Math.min(i,pedido.length),0,item); pintaPedido();
|
||||
});
|
||||
}));
|
||||
$('itens').querySelectorAll('[data-salvai]').forEach(b=>b.addEventListener('click',async()=>{
|
||||
const it=pedido[+b.dataset.salvai]; if(!it || b.disabled) return;
|
||||
const picture=typeof it.mini==='string' && /^data:/.test(it.mini) && it.mini.length<=300000 ? it.mini : null;
|
||||
b.disabled=true;
|
||||
try{
|
||||
await window.dtfApi('/account/sheets',{name:it.tit+' · '+fmtM(it.cob)+' m',mode:it.modo,
|
||||
metres:it.cob,item:itemParaSalvar(it),picture});
|
||||
window.dtfMensagem?.('Folha salva em Minhas folhas.','ok');
|
||||
}catch(error){
|
||||
window.dtfMensagem?.(error.message,'error');
|
||||
}finally{
|
||||
b.disabled=!podeSalvarFolha(it);
|
||||
}
|
||||
}));
|
||||
$('bEsvaziar').hidden = pedido.length+(itemAtual?1:0) < 2;
|
||||
const itens = aPagar.reduce((t,it)=>t+it.total,0);
|
||||
const frete = entrega.tipo==='frete' && entrega.cotado ? entrega.valor : 0;
|
||||
|
||||
Reference in New Issue
Block a user