Spaces:
Running
Running
v15: replace inline doAISearch with context-aware version using showDetail(index)
Browse files- index.html +58 -61
index.html
CHANGED
|
@@ -2741,68 +2741,65 @@ Miễn phí giao hàng trong TPHCM. | Giá đã bao gồm VAT.
|
|
| 2741 |
</div>
|
| 2742 |
<script src="search-plus-boot.js?v=15"></script>
|
| 2743 |
|
| 2744 |
-
<script>
|
| 2745 |
-
|
| 2746 |
-
|
| 2747 |
-
|
| 2748 |
-
|
| 2749 |
-
|
| 2750 |
-
|
| 2751 |
-
|
| 2752 |
-
|
| 2753 |
-
|
| 2754 |
-
|
| 2755 |
-
|
| 2756 |
-
|
| 2757 |
-
|
| 2758 |
-
|
| 2759 |
-
|
| 2760 |
-
|
| 2761 |
-
|
| 2762 |
-
|
| 2763 |
-
|
| 2764 |
-
|
| 2765 |
-
|
| 2766 |
-
|
| 2767 |
-
|
| 2768 |
-
|
| 2769 |
-
|
| 2770 |
-
|
| 2771 |
-
|
| 2772 |
-
|
| 2773 |
-
|
| 2774 |
-
|
| 2775 |
-
|
| 2776 |
-
|
| 2777 |
-
|
| 2778 |
-
|
| 2779 |
-
|
| 2780 |
-
|
| 2781 |
-
|
| 2782 |
-
|
| 2783 |
-
|
| 2784 |
-
|
| 2785 |
-
|
| 2786 |
-
|
| 2787 |
-
|
| 2788 |
-
|
| 2789 |
-
|
| 2790 |
-
|
| 2791 |
-
|
| 2792 |
-
|
| 2793 |
-
h+='<div style="background:#
|
| 2794 |
-
|
| 2795 |
-
h+='<div style="font-size:
|
| 2796 |
-
h+='<div style="font-size:
|
| 2797 |
-
|
| 2798 |
-
if(sk.length){h+='<div style="margin-top:
|
| 2799 |
-
h+='<
|
| 2800 |
-
|
| 2801 |
-
h+='<button onclick="event.stopPropagation();saveToOrder('+D.indexOf(p)+')" style="margin-top:5px;width:100%;padding:4px;background:var(--p,#003f62);color:#fff;border:none;border-radius:5px;font-size:.68rem;cursor:pointer">+ Them don</button>';
|
| 2802 |
-
h+='</div>';
|
| 2803 |
});
|
| 2804 |
-
h+='</div>';
|
| 2805 |
-
res.innerHTML=h;
|
| 2806 |
}
|
| 2807 |
function doAIQuote(){
|
| 2808 |
const q=document.getElementById('aiSearch').value.trim()||'bếp từ + máy hút mùi + chậu rửa khoảng 50 triệu';
|
|
|
|
| 2741 |
</div>
|
| 2742 |
<script src="search-plus-boot.js?v=15"></script>
|
| 2743 |
|
| 2744 |
+
<script>function doAISearch(){
|
| 2745 |
+
// Delegated to search-plus-boot.js v15 (ALL-IN-ONE)
|
| 2746 |
+
if(window._vaiSearchContext && typeof D!=='undefined' && D.length>0){
|
| 2747 |
+
var input=document.getElementById('aiSearch');var resultsDiv=document.getElementById('aiResults');
|
| 2748 |
+
if(!input||!resultsDiv)return;var query=input.value.trim();
|
| 2749 |
+
if(!query||query.length<2){resultsDiv.style.display='block';resultsDiv.innerHTML='💡 Nhập mã SP hoặc mô tả: "bếp từ Grob dưới 10tr", "máy hút mùi Malloca"';return;}
|
| 2750 |
+
resultsDiv.style.display='block';resultsDiv.innerHTML='⏳ Đang tìm...';
|
| 2751 |
+
// Multi-code search: nếu có dấu phẩy thì tìm theo mã
|
| 2752 |
+
var queries=query.split(/[,;]+/).map(function(c){return c.trim()}).filter(function(c){return c.length>=2});
|
| 2753 |
+
if(queries.length>1){
|
| 2754 |
+
var allResults=[];
|
| 2755 |
+
queries.forEach(function(q2){
|
| 2756 |
+
var qLow=q2.toLowerCase().replace(/[.\-_ \/]/g,'');
|
| 2757 |
+
for(var i=0;i<D.length&&allResults.length<20;i++){
|
| 2758 |
+
var p=D[i];if(!p)continue;
|
| 2759 |
+
var fields=[(p.sku||''),(p.mod||''),(p.slug||'')].map(function(f){return f.toLowerCase().replace(/[.\-_ \/]/g,'')});
|
| 2760 |
+
if(fields.some(function(f){return f===qLow||(f&&qLow.length>=3&&(f.indexOf(qLow)!==-1||qLow.indexOf(f)!==-1))})){allResults.push(p);}
|
| 2761 |
+
}
|
| 2762 |
+
});
|
| 2763 |
+
if(allResults.length){_renderAIResults(allResults,resultsDiv);return;}
|
| 2764 |
+
}
|
| 2765 |
+
// Context search (category + brand + price + keywords)
|
| 2766 |
+
var results=window._vaiSearchContext(query,24);
|
| 2767 |
+
if(!results.length){resultsDiv.innerHTML='❌ Không tìm thấy "'+query+'". Thử: "bếp từ Malloca", "máy hút mùi dưới 15tr"';return;}
|
| 2768 |
+
var prods=results.map(function(r){return r.p;});
|
| 2769 |
+
_renderAIResults(prods,resultsDiv);
|
| 2770 |
+
return;
|
| 2771 |
+
}
|
| 2772 |
+
// Fallback: basic
|
| 2773 |
+
var q2=document.getElementById('aiSearch').value.trim();
|
| 2774 |
+
if(!q2){document.getElementById('aiResults').innerHTML='💡 Nhập mã hoặc tên SP';document.getElementById('aiResults').style.display='block';return;}
|
| 2775 |
+
document.getElementById('aiResults').innerHTML='⏳ Đang tải dữ liệu...';document.getElementById('aiResults').style.display='block';
|
| 2776 |
+
}
|
| 2777 |
+
function _renderAIResults(prods,res){
|
| 2778 |
+
var norm=window._vaiSearchContext?function(s){return(s||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/[Đđ]/g,'d').toLowerCase()}:function(s){return(s||'').toLowerCase()};
|
| 2779 |
+
var cat=window._vaiDetectCategory?window._vaiDetectCategory(document.getElementById('aiSearch').value):'';
|
| 2780 |
+
var brand=window._vaiDetectBrand?window._vaiDetectBrand(document.getElementById('aiSearch').value):'';
|
| 2781 |
+
var fmt=function(n){if(!n||isNaN(n))return'LH';return Number(n).toLocaleString('vi-VN')+'đ'};
|
| 2782 |
+
var parts=[];
|
| 2783 |
+
if(cat)parts.push('📂 '+cat);if(brand)parts.push('🏷 '+brand);
|
| 2784 |
+
parts.push('🔍 '+prods.length+' SP');
|
| 2785 |
+
var h='<div style="margin-bottom:10px;display:flex;gap:6px;flex-wrap:wrap">'+parts.map(function(p){return'<span style="background:#eff6ff;padding:3px 8px;border-radius:20px;font-size:11px;font-weight:600;color:#1e40af;border:1px solid #bfdbfe">'+p+'</span>'}).join('')+'</div>';
|
| 2786 |
+
h+='<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:10px">';
|
| 2787 |
+
prods.slice(0,24).forEach(function(p){
|
| 2788 |
+
var idx=D.indexOf(p);
|
| 2789 |
+
var name=p.name||p.n||'';var price=p.price||p.p||'LH';var img=p.image||p.img||p.i||'';var sku=p.sku||p.model||p.mod||'';var brand2=p.brand||'';
|
| 2790 |
+
var feats=(p.feats||[]).slice(0,2).join(' • ');
|
| 2791 |
+
var specs=p.specs||{};var sk=Object.entries(specs).slice(0,3);
|
| 2792 |
+
h+='<div style="background:#fff;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden;transition:all .2s;cursor:pointer" onclick="showDetail('+idx+')" onmouseover="this.style.transform=\'translateY(-2px)\';this.style.boxShadow=\'0 4px 12px rgba(0,0,0,.1)\'" onmouseout="this.style.transform=\'\';this.style.boxShadow=\'\'">';
|
| 2793 |
+
if(img)h+='<div style="height:90px;background:#f8fafc;display:flex;align-items:center;justify-content:center"><img src="'+img+'" style="max-width:100%;max-height:85px;object-fit:contain" onerror="this.parentElement.style.display=\'none\'"></div>';
|
| 2794 |
+
h+='<div style="padding:8px"><div style="font-size:11px;font-weight:600;color:#003f62;line-height:1.3;height:30px;overflow:hidden">'+name.substring(0,55)+'</div>';
|
| 2795 |
+
if(sku)h+='<div style="font-size:9px;color:#94a3b8;margin-top:2px">'+sku+'</div>';
|
| 2796 |
+
if(brand2)h+='<div style="font-size:9px;color:#64748b;margin-top:1px">'+brand2+'</div>';
|
| 2797 |
+
if(feats)h+='<div style="font-size:8.5px;color:#64748b;margin-top:2px;height:12px;overflow:hidden">'+feats+'</div>';
|
| 2798 |
+
if(sk.length){h+='<div style="margin-top:3px;font-size:8px;color:#555;border-top:1px solid #f0f0f0;padding-top:3px">';sk.forEach(function(kv){h+=kv[0]+': <b>'+kv[1]+'</b><br>'});h+='</div>'}
|
| 2799 |
+
h+='<div style="font-size:13px;font-weight:800;color:#059669;margin-top:4px">'+price+'</div>';
|
| 2800 |
+
h+='</div></div>';
|
|
|
|
|
|
|
| 2801 |
});
|
| 2802 |
+
h+='</div>';res.innerHTML=h;
|
|
|
|
| 2803 |
}
|
| 2804 |
function doAIQuote(){
|
| 2805 |
const q=document.getElementById('aiSearch').value.trim()||'bếp từ + máy hút mùi + chậu rửa khoảng 50 triệu';
|