Калькулятор металлопроката — АтомСпецмет
Параметры проката
ГОСТ 2590-2006
3D визуализация
ЛКМ · колесо · ПКМ
ЛКМ — вращение · Колесо — масштаб · ПКМ — сдвиг
· +375 44 783-10-10
atomsm.by
`;
}
async function exportPDF(){
const btn = document.getElementById('pdfBtn');
const orig = btn.innerHTML;
btn.innerHTML = 'Формируем…';
btn.disabled = true;
const container = document.getElementById('pdfSpec');
container.innerHTML = buildSpecHTML();
try{
await new Promise(r=>setTimeout(r, 60));
const canvas = await html2canvas(container.firstElementChild, {
scale: 2,
backgroundColor: '#ffffff',
logging: false,
useCORS: true
});
const {jsPDF} = window.jspdf;
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfW = pdf.internal.pageSize.getWidth();
const pdfH = pdf.internal.pageSize.getHeight();
const margin = 8;
const maxW = pdfW - margin*2;
const maxH = pdfH - margin*2;
const ratio = canvas.width / canvas.height;
let drawW = maxW;
let drawH = drawW / ratio;
if(drawH > maxH){
drawH = maxH;
drawW = drawH * ratio;
}
const imgData = canvas.toDataURL('image/jpeg', 0.94);
pdf.addImage(imgData, 'JPEG', (pdfW-drawW)/2, margin, drawW, drawH, undefined, 'FAST');
pdf.save('raschet_metalloprokat_' + Date.now() + '.pdf');
showToast('PDF сохранён', true);
}catch(err){
console.error(err);
showToast('Ошибка при формировании PDF', false);
}finally{
btn.innerHTML = orig;
btn.disabled = false;
container.innerHTML = '';
}
}
function printResult(){
window.print();
}
/* =====================================================================
ФОРМА
===================================================================== */
function submitOrder(e){
e.preventDefault();
const f = e.target;
const d = new FormData(f);
const s = SHAPES[state.shape];
const cat = GRADE_CATEGORIES[state.gradeCategory];
const rho = cat ? cat.rho : 7850;
const {area, dimText, sheet, thickness, w, l} = getArea();
const L = state.length/1000;
const qty = state.qty||1;
let massTotal;
if(sheet){
massTotal = (w/1000)*(l/1000)*(thickness/1000)*rho*qty;
}else{
massTotal = (area/1e6)*L*rho*qty;
}
const subject = encodeURIComponent('Заявка на точный расчёт металлопроката — АтомСпецмет');
const body = encodeURIComponent(
'Заявка на точный расчёт металлопроката\n' +
'────────────────────────────────────\n\n' +
'E-mail: ' + d.get('email') + '\n' +
'Телефон: ' + d.get('phone') + '\n' +
'Комментарий: ' + (d.get('comment') || '—') + '\n\n' +
'ПАРАМЕТРЫ РАСЧЁТА:\n' +
' Тип проката: ' + s.name + '\n' +
' Стандарт: ' + state.gost + '\n' +
' Марка: ' + state.grade + ' (' + state.gradeCategory + ')\n' +
' Размер: ' + dimText + '\n' +
' Длина: ' + state.length + ' мм\n' +
' Количество: ' + qty + ' шт\n\n' +
' Общая масса: ' + massTotal.toFixed(2) + ' кг\n\n' +
'Отправлено с калькулятора atomsm.by'
);
window.location.href = 'mailto:sales@atomsm.by?subject=' + subject + '&body=' + body;
const ok = document.getElementById('orderSuccess');
ok.classList.add('show');
showToast('Письмо сформировано — отправьте его из почтового клиента', true);
setTimeout(()=>ok.classList.remove('show'), 8000);
}
/* =====================================================================
TOAST
===================================================================== */
let toastTimer = null;
function showToast(msg, ok){
const t = document.getElementById('toast');
t.textContent = msg;
t.className = 'toast show' + (ok ? ' ok' : '');
clearTimeout(toastTimer);
toastTimer = setTimeout(()=>{ t.className = 'toast'; }, 3600);
}
/* =====================================================================
INIT
===================================================================== */
(function init(){
buildShapeSelect();
buildGostSelect();
buildGradeSelect();
buildDims();
requestAnimationFrame(()=>{
init3D();
onResize();
recalculate();
setTimeout(onResize, 120);
setTimeout(onResize, 400);
});
})();