caterium-app/public/core/order-enhancements-v1775.js
pavlov346346-source a6bd7f911b fix: remove duplicate delivery/total line in order cost summary
order-enhancements-v1775.js appended its own Доставка/Итого
paragraphs to .order-summary even after app-runtime.js's
ensureDiscountUI() already renders a full breakdown (positions,
discount, promo, delivery, total, prepayment, balance) — resulting
in a duplicate Доставка line at the bottom of the order details
cost panel. Now it skips the extra append when the richer summary
UI is present.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 17:32:09 +03:00

20 lines
7.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(()=>{
'use strict';
if(window.__cateriumOrderEnhancementsV1775)return;window.__cateriumOrderEnhancementsV1775=true;
if(!window.CateriumLoginSignatureV1776&&!document.getElementById('cateriumLoginSignatureV1776Script')){const s=document.createElement('script');s.id='cateriumLoginSignatureV1776Script';s.src='core/login-signature-v1776.js?v=20260911-signature-login-v1';s.async=false;document.head.appendChild(s)}
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:6px;padding-top:5px;border-top:1px dashed #e0e4e8}.sun-line-comment-btn-v1775{display:inline-flex;align-items:center;gap:4px;padding:4px 8px;border:1px solid #cfd7df;border-radius:7px;background:#f7f9fb;color:#31516a;font-size:11px;font-weight:700;line-height:1.2;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:6px}.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:5px;padding-top:5px}.sun-line-comment-btn-v1775{width:auto;max-width:100%;justify-content:flex-start;padding:5px 8px;font-size:11px}.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='<button type="button" class="sun-line-comment-btn-v1775">💬 Оставить комментарий</button><div class="sun-line-comment-editor-v1775"><input type="text" maxlength="300" placeholder="Аллергия, убрать ингредиент, изменение состава…"><button type="button" class="sun-line-comment-save-v1775">Готово</button></div>';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 delivery(){return Math.max(0,Number($('#orderDeliveryCost')?.value||draft?.costs?.delivery||draft?.deliveryCost||0))}
function financial(){const p=window.sunOrderPricing?.(draft);let d=p?Number(p.delivery||0):delivery(),positions=p?Number(p.itemsTotal||0):Math.max(0,Number(typeof calcOrderTotal==='function'?calcOrderTotal():0)),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 richUI=!!$('#summaryDelivery');if(!richUI){let d=$('#sunSummaryDeliveryV1775');if(!d){d=document.createElement('p');d.id='sunSummaryDeliveryV1775';h.appendChild(d)}d.innerHTML=`<span>Доставка</span><b>${fmt(f.d)}</b>`;let t=$('#sunSummaryGrandV1775');if(!t){t=document.createElement('p');t.id='sunSummaryGrandV1775';t.className='sun-summary-grand-v1775';h.appendChild(t)}t.innerHTML=`<span>Итого</span><b>${fmt(f.total)}</b>`}else{$('#sunSummaryDeliveryV1775')?.remove();$('#sunSummaryGrandV1775')?.remove()}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 post(){styles();searchBox();comments();summary()}
function wrap(n){let old=window[n];if(typeof old!=='function'||old.__commentsV1775)return;let fn=function(...a){let r=old.apply(this,a);queueMicrotask(post);setTimeout(post,50);return r};fn.__commentsV1775=true;window[n]=fn}
styles();['render','openOrder','resetDraft','updateOrderSummary','saveOrder'].forEach(wrap);post();
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);
})();