diff --git a/public/core/order-enhancements-v1775.js b/public/core/order-enhancements-v1775.js index 40c97ca..abfb936 100644 --- a/public/core/order-enhancements-v1775.js +++ b/public/core/order-enhancements-v1775.js @@ -2,20 +2,17 @@ 'use strict'; if(window.__cateriumOrderEnhancementsV1775)return;window.__cateriumOrderEnhancementsV1775=true; const $=(s,r=document)=>r.querySelector(s),$$=(s,r=document)=>[...r.querySelectorAll(s)],safe=v=>String(v??'').trim(),fmt=v=>typeof money==='function'?money(v):`${Math.round(Number(v||0)).toLocaleString('ru-RU')} ₽`; -function styles(){if($('#caterium-order-enhancements-v1775-style'))return;let s=document.createElement('style');s.id='caterium-order-enhancements-v1775-style';s.textContent=`#sunCatalogSearchV1775{width:100%;margin:10px 0 4px;padding:10px 12px;border:1px solid #d6dbe0;border-radius:9px;background:#fff}.sun-line-comment-v1775{display:block;width:100%;margin-top:8px;padding-top:7px;border-top:1px dashed #e0e4e8}.sun-line-comment-btn-v1775{display:inline-flex;align-items:center;gap:6px;padding:6px 10px;border:1px solid #cfd7df;border-radius:8px;background:#f7f9fb;color:#31516a;font-size:12px;font-weight:700;cursor:pointer}.sun-line-comment-btn-v1775:hover{background:#eef4f8}.sun-line-comment-btn-v1775.has-comment{background:#fff7d7;border-color:#e4ca72;color:#6d5708}.sun-line-comment-editor-v1775{display:none;margin-top:7px}.sun-line-comment-editor-v1775.on{display:flex;gap:7px;align-items:center}.sun-line-comment-editor-v1775 input{flex:1;min-width:120px;height:34px;padding:6px 8px;border:1px solid #d6dbe0;border-radius:7px;background:#fff}.sun-line-comment-save-v1775{height:34px;padding:0 10px;border:0;border-radius:7px;background:#31516a;color:#fff;font-size:12px;font-weight:700;cursor:pointer}.sun-order-reminders-v1775{margin:8px 0 10px;padding:10px 12px;border:1px solid #e1e5e9;border-radius:10px;background:#fafbfc}.sun-order-reminders-v1775>strong{display:block;margin-bottom:7px}.sun-order-reminders-v1775 .opts{display:flex;gap:14px;flex-wrap:wrap}.sun-order-reminders-v1775 label{display:flex!important;align-items:center!important;gap:7px!important}.sun-calendar-reminder-v1775{display:inline-flex;margin-top:5px;padding:3px 6px;border-radius:999px;background:#fff7d7;color:#795c00;font-size:10px;font-weight:800}.sun-toast-v1775{position:fixed;right:18px;bottom:18px;z-index:99999;max-width:390px;padding:13px 15px;border-radius:12px;background:#15364c;color:#fff;box-shadow:0 10px 30px #0003}.order-summary .sun-summary-grand-v1775{margin-top:7px;padding-top:9px;border-top:2px solid #c99a32;font-size:18px;font-weight:800;color:#15364c}@media(max-width:760px){#sunCatalogSearchV1775,.sun-line-comment-editor-v1775 input{font-size:16px!important}.sun-line-comment-v1775{margin-top:7px}.sun-line-comment-btn-v1775{width:100%;justify-content:center;padding:8px 10px}.sun-line-comment-editor-v1775.on{display:grid;grid-template-columns:1fr auto}.sun-line-comment-editor-v1775 input{width:100%;height:40px}.sun-line-comment-save-v1775{height:40px}}`;document.head.appendChild(s)} +function styles(){if($('#caterium-order-enhancements-v1775-style'))return;let s=document.createElement('style');s.id='caterium-order-enhancements-v1775-style';s.textContent=`#sunCatalogSearchV1775{width:100%;margin:10px 0 4px;padding:10px 12px;border:1px solid #d6dbe0;border-radius:9px;background:#fff}.sun-line-comment-v1775{display:block;width:100%;margin-top:8px;padding-top:7px;border-top:1px dashed #e0e4e8}.sun-line-comment-btn-v1775{display:inline-flex;align-items:center;gap:6px;padding:6px 10px;border:1px solid #cfd7df;border-radius:8px;background:#f7f9fb;color:#31516a;font-size:12px;font-weight:700;cursor:pointer}.sun-line-comment-btn-v1775:hover{background:#eef4f8}.sun-line-comment-btn-v1775.has-comment{background:#fff7d7;border-color:#e4ca72;color:#6d5708}.sun-line-comment-editor-v1775{display:none;margin-top:7px}.sun-line-comment-editor-v1775.on{display:flex;gap:7px;align-items:center}.sun-line-comment-editor-v1775 input{flex:1;min-width:120px;height:34px;padding:6px 8px;border:1px solid #d6dbe0;border-radius:7px;background:#fff}.sun-line-comment-save-v1775{height:34px;padding:0 10px;border:0;border-radius:7px;background:#31516a;color:#fff;font-size:12px;font-weight:700;cursor:pointer}.order-summary .sun-summary-grand-v1775{margin-top:7px;padding-top:9px;border-top:2px solid #c99a32;font-size:18px;font-weight:800;color:#15364c}@media(max-width:760px){#sunCatalogSearchV1775,.sun-line-comment-editor-v1775 input{font-size:16px!important}.sun-line-comment-v1775{margin-top:7px}.sun-line-comment-btn-v1775{width:100%;justify-content:center;padding:8px 10px}.sun-line-comment-editor-v1775.on{display:grid;grid-template-columns:1fr auto}.sun-line-comment-editor-v1775 input{width:100%;height:40px}.sun-line-comment-save-v1775{height:40px}}`;document.head.appendChild(s)} function lineRows(){let root=$('#lines')||$('#orderLines')||$('#orderForm');if(!root)return[];let rows=$$('.sun-order-line-row,.line',root);return rows.filter(r=>!r.classList.contains('sun-line-comment-v1775'))} function activeLines(){return Array.isArray(draft?.lines)?draft.lines.filter(l=>boxes?.some?.(b=>String(b.id)===String(l.id))):[]} function comments(){let rows=lineRows(),ls=activeLines();rows.forEach((row,i)=>{let l=ls[i];if(!l)return;let w=$('.sun-line-comment-v1775',row);if(!w){w=document.createElement('div');w.className='sun-line-comment-v1775';w.innerHTML='
';row.appendChild(w)}let btn=$('.sun-line-comment-btn-v1775',w),editor=$('.sun-line-comment-editor-v1775',w),input=$('input',w),save=$('.sun-line-comment-save-v1775',w);let current=safe(l.comment);btn.classList.toggle('has-comment',!!current);btn.textContent=current?'💬 Комментарий добавлен':'💬 Оставить комментарий';if(document.activeElement!==input&&input.value!==current)input.value=current;if(!btn.dataset.bound){btn.dataset.bound='1';btn.addEventListener('click',()=>{editor.classList.toggle('on');if(editor.classList.contains('on')){input.value=safe(l.comment);setTimeout(()=>input.focus(),0)}});input.addEventListener('input',()=>{l.comment=input.value.slice(0,300)});input.addEventListener('keydown',e=>{if(e.key==='Enter'){e.preventDefault();save.click()}});save.addEventListener('click',()=>{l.comment=input.value.trim().slice(0,300);btn.classList.toggle('has-comment',!!l.comment);btn.textContent=l.comment?'💬 Комментарий добавлен':'💬 Оставить комментарий';editor.classList.remove('on')})}})} function searchBox(){let catalog=$('#new .catalog');if(!catalog||$('#sunCatalogSearchV1775'))return;let i=document.createElement('input');i.id='sunCatalogSearchV1775';i.type='search';i.placeholder='Поиск по № бокса или названию';($('.catalog-head',catalog)||catalog.firstElementChild)?.insertAdjacentElement('afterend',i);i.addEventListener('input',()=>{let q=safe(i.value).toLowerCase().replace(/ё/g,'е');$$('#tiles .tile').forEach(t=>{let text=safe(t.textContent).toLowerCase().replace(/ё/g,'е');t.hidden=t.classList.contains('add')?!!q:!!(q&&!text.includes(q))})})} -function reminders(){let schedule=$('#details .sun-order-schedule');if(!schedule||$('#sunOrderRemindersV1775'))return;let b=document.createElement('div');b.id='sunOrderRemindersV1775';b.className='sun-order-reminders-v1775';b.innerHTML='Напоминание по заказу
';schedule.insertAdjacentElement('afterend',b);$$('input',b).forEach(x=>x.addEventListener('change',()=>{draft.reminders={day:!!$('[data-reminder="day"]',b)?.checked,hour:!!$('[data-reminder="hour"]',b)?.checked};try{if('Notification'in window&&Notification.permission==='default')Notification.requestPermission()}catch(_){}}));syncReminders()} -function syncReminders(){let b=$('#sunOrderRemindersV1775');if(!b)return;let r=draft?.reminders||{};$('[data-reminder="day"]',b).checked=!!r.day;$('[data-reminder="hour"]',b).checked=!!r.hour} function delivery(){return Math.max(0,Number($('#orderDeliveryCost')?.value||draft?.costs?.delivery||draft?.deliveryCost||0))} function financial(){let positions=Math.max(0,Number(typeof calcOrderTotal==='function'?calcOrderTotal():0)),d=delivery(),paid=Math.max(0,Number($('#prepayment')?.value||draft?.prepayment||0)),total=positions+d;return{positions,d,total,paid,balance:Math.max(0,total-paid)}} function summary(){let h=$('.order-summary');if(!h)return;let f=financial();if($('#summaryTotal'))$('#summaryTotal').textContent=fmt(f.positions);let d=$('#sunSummaryDeliveryV1775');if(!d){d=document.createElement('p');d.id='sunSummaryDeliveryV1775';h.appendChild(d)}d.innerHTML=`Доставка${fmt(f.d)}`;let t=$('#sunSummaryGrandV1775');if(!t){t=document.createElement('p');t.id='sunSummaryGrandV1775';t.className='sun-summary-grand-v1775';h.appendChild(t)}t.innerHTML=`Итого${fmt(f.total)}`;if($('#orderTotal'))$('#orderTotal').value=Math.round(f.total);if($('#balance'))$('#balance').value=Math.round(f.balance);if($('#summaryBalance'))$('#summaryBalance').textContent=fmt(f.balance);draft.total=f.total;draft.balance=f.balance} -function scanReminders(){if(!Array.isArray(orders))return;let now=Date.now();orders.forEach(o=>{if(!o.date||!o.time)return;let due=new Date(`${o.date}T${o.time}:00`).getTime();[['day',864e5],['hour',36e5]].forEach(([k,lead])=>{if(!o.reminders?.[k])return;let trigger=due-lead,key=`caterium.reminder.${o.id}.${k}.${due}`;if(now>=trigger&&now{if(!ms.some(m=>m.addedNodes.length||m.removedNodes.length))return;clearTimeout(timer);timer=setTimeout(()=>{comments();searchBox();reminders()},30)}).observe(document.body,{childList:true,subtree:true}); -document.addEventListener('input',e=>{if(e.target?.id==='orderDeliveryCost'||e.target?.id==='prepayment')summary()},true);scanReminders();setInterval(scanReminders,30000); +let timer=0;new MutationObserver(ms=>{if(!ms.some(m=>m.addedNodes.length||m.removedNodes.length))return;clearTimeout(timer);timer=setTimeout(()=>{comments();searchBox()},30)}).observe(document.body,{childList:true,subtree:true}); +document.addEventListener('input',e=>{if(e.target?.id==='orderDeliveryCost'||e.target?.id==='prepayment')summary()},true); })(); \ No newline at end of file