feat: the customer picks Agrupado or Misturado and sees free copies that fit the same metres (Rodada 5, C1, C2)

C2: encaixar takes an optional mode ('linhas', 'forma'; the Montar keeps
the automatic one); the buy box shows both billed lengths and the
difference in cm and R$ when they differ, marking the packing on screen.
C1: up to 5 arts are tried with up to 30 more copies, by binary search
with the packing in use, and up to 3 '+k file' buttons add the copies
that keep the billed metres. Both run after the order check, never
before it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-30 15:03:02 -03:00
parent 28c10aabf6
commit 030b66c697
7 changed files with 189 additions and 13 deletions

View File

@@ -4,10 +4,53 @@
price of its own, so the box and the cart always agree. */
(function(){
const vals=$('compraVals'), add=$('bAdd');
const nomeCurto=n=>{ n=n||''; return n.length>24 ? n.slice(0,23)+'…' : n; };
// C2 · o cliente escolhe entre Agrupado (linhas) e Misturado (pela forma).
function pintaEncaixe(it){
const box=$('cEncaixe'); if(!box) return;
const alt=encaixeAlt;
if(!it || !alt || ehFolha(it.modo) ||
Math.abs(alt.linhas-alt.forma)<1e-9){
box.hidden=true; box.innerHTML=''; return;
}
const efetivo = modoEncaixeEmUso();
const maior=Math.max(alt.linhas,alt.forma), menor=Math.min(alt.linhas,alt.forma);
const nCm=Math.round((maior-menor)*100);
const y=nCm/100*(it.unit||0);
const vence=alt.forma<=alt.linhas ? 'Misturado' : 'Agrupado';
const bt=(m,rot,sub)=>'<button type="button" class="cEncBt'+
(efetivo===m?' on':'')+'" data-enc="'+m+'" aria-pressed="'+(efetivo===m)+'">'+
'<b>'+rot+'</b><small>'+sub+'</small></button>';
box.hidden=false;
box.innerHTML='<div class="cEncBts" role="group" aria-label="Modo de encaixe">'+
bt('linhas','Agrupado','Mais fácil de cortar · '+fmtM(alt.linhas)+' m')+
bt('forma','Misturado','Menos filme · '+fmtM(alt.forma)+' m')+
'</div>'+
'<p class="cEncDif">'+vence+' usa '+nCm+' cm a menos ('+rs(y)+' a menos).</p>';
}
// C1 · o que ainda cabe na metragem já cobrada, sem aumentar o filme.
function pintaVao(it){
const box=$('cVao'); if(!box) return;
const lista=encaixeVao;
if(!it || ehFolha(it.modo) || !lista.length){
box.hidden=true; box.innerHTML=''; return;
}
const bts=lista.map(v=>{
const i=artes.indexOf(v.a);
return i<0?'':'<button type="button" class="cVaoBt" data-vao="'+i+'" data-k="'+v.k+'">+'+
v.k+' '+escapeHTML(nomeCurto(v.a.f.name))+'</button>';
}).join('');
if(!bts){ box.hidden=true; box.innerHTML=''; return; }
box.hidden=false;
box.innerHTML='<p class="cVaoT">Sem custo: cabem mais cópias nesta metragem.</p>'+
'<div class="cVaoBts">'+bts+'</div>';
}
function pintaCompra(){
const it=itemAtual;
if(!modo || !artes.length) modoEncaixe='auto';
vals.hidden=!it;
add.disabled=!it || !itemPodeEnviar(it);
pintaEncaixe(it); pintaVao(it);
if(!it) return;
$('cMetroLbl').textContent = it.extra ? 'Metro · com '+rs(it.extra)+' de arquivo manual' : 'Metro';
$('cMetro').textContent=rs(it.unit);
@@ -33,7 +76,22 @@
: '';
$('cTotal').textContent=rs(it.total);
}
$('cEncaixe')?.addEventListener('click',e=>{
const b=e.target.closest('[data-enc]'); if(!b) return;
modoEncaixe=b.dataset.enc;
pintaCompra();
previaAoVivo();
});
$('cVao')?.addEventListener('click',e=>{
const b=e.target.closest('[data-vao]'); if(!b) return;
const a=artes[+b.dataset.vao]; if(!a) return;
a.q=Math.min(200,(a.q||1)+(+b.dataset.k||0));
encaixeVao=[];
const box=$('cVao'); box.hidden=true; box.innerHTML='';
pintaArtes();
});
add.addEventListener('click',()=>adicionaAoCarrinho());
addEventListener('dtf-cart-changed',pintaCompra);
window.pintaCompra=pintaCompra;
pintaCompra();
})();