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>
98 lines
4.5 KiB
JavaScript
98 lines
4.5 KiB
JavaScript
/* Site DTF — the product page's buy box: the grade, price per metre, billed length,
|
|
total and the add-to-cart button, beside the live sheet. It shows the item
|
|
the other site-*.js files already priced (itemAtual) and never computes a
|
|
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);
|
|
$('cMetragem').textContent=fmtM(it.cob)+' m';
|
|
// Partes de até 10 m (Marcus, 18/11/2026): o FlexiPRINT não abre mais que isso.
|
|
const partes=ehFolha(it.modo) ? Math.ceil(it.metros/10) : 1;
|
|
$('cPartes').textContent = partes>1 ? ' Sai em '+partes+' partes de até 10 m.' : '';
|
|
const sobraCm=Math.round((it.cob-it.metros)*100);
|
|
// A metragem cobrada explicada como vantagem (Marcus, 27/11/2026): a cada
|
|
// 10 cm, e até 8 mm a mais ficam por nossa conta.
|
|
const exata=n1(it.metros*100)+' cm';
|
|
const aMais=Math.round((it.metros-it.cob)*1000);
|
|
$('cObs').textContent =
|
|
it.cob===MINIMO_M && it.metros<MINIMO_M
|
|
? (ehFolha(it.modo) ? 'Pedido mínimo de 1 m.'
|
|
: 'Pedido mínimo de 1 m: ainda cabem '+sobraCm+' cm de artes sem custo.')
|
|
: it.cob<it.metros-1e-6
|
|
? 'A folha tem '+exata+': cobramos a cada 10 cm e '+
|
|
(aMais>1?'os '+aMais+' mm a mais ficam':aMais===1?'o 1 mm a mais fica':'o que passou fica')+' por nossa conta.'
|
|
: it.cob>it.metros+1e-6
|
|
? 'A folha tem '+exata+'. Cobramos a cada 10 cm, então fica '+fmtM(it.cob)+' m. '+
|
|
'Se passar até 8 mm de uma faixa, esse pedaço fica por nossa conta.'
|
|
: '';
|
|
$('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();
|
|
})();
|