Spaces:
Running
Running
Fix AI Search: exact SKU/mod match + Chat AI uses same search + specs display
Browse files- index.html +101 -58
index.html
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="vi">
|
| 3 |
-
<head><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
<title>V.AI STUDIO | Niềm tin khách hàng là tài sản của chúng tôi</title>
|
|
@@ -2730,67 +2730,62 @@ Miễn phí giao hàng trong TPHCM. | Giá đã bao gồm VAT.
|
|
| 2730 |
<script>
|
| 2731 |
function doAISearch(){
|
| 2732 |
const q=document.getElementById('aiSearch').value.trim();
|
| 2733 |
-
if(!q){document.getElementById('aiResults').style.display='block';document.getElementById('aiResults').innerHTML='💡 Nhập mã SP
|
| 2734 |
const res=document.getElementById('aiResults');
|
| 2735 |
-
res.style.display='block';res.innerHTML='
|
| 2736 |
-
if(typeof D==='undefined'||!D.length){res.innerHTML='⏳ Đang tải...';return}
|
| 2737 |
-
|
| 2738 |
-
|
| 2739 |
-
|
| 2740 |
-
|
| 2741 |
-
|
| 2742 |
-
|
| 2743 |
-
|
| 2744 |
-
|
| 2745 |
-
|
| 2746 |
-
|
| 2747 |
-
const mod=(p.mod||'').toLowerCase().replace(/[.\-_ /]/g,'');
|
| 2748 |
-
return sku===codeClean||mod===codeClean;
|
| 2749 |
-
});
|
| 2750 |
-
if(exact.length){allFound.push(...exact);return}
|
| 2751 |
-
// Method 2: Partial SKU match (code is contained in sku or vice versa)
|
| 2752 |
-
let partial=D.filter(p=>{
|
| 2753 |
-
const sku=(p.sku||'').toLowerCase().replace(/[.\-_ /]/g,'');
|
| 2754 |
-
const mod=(p.mod||'').toLowerCase().replace(/[.\-_ /]/g,'');
|
| 2755 |
-
return (codeClean.length>=3&&(sku.includes(codeClean)||mod.includes(codeClean)||codeClean.includes(sku)||codeClean.includes(mod)));
|
| 2756 |
-
});
|
| 2757 |
-
if(partial.length){allFound.push(...partial.slice(0,3));return}
|
| 2758 |
-
// Method 3: Name/category keyword search
|
| 2759 |
-
const qn=code.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/đ/g,'d');
|
| 2760 |
-
const words=qn.split(/\s+/).filter(w=>w.length>=2);
|
| 2761 |
-
if(!words.length)return;
|
| 2762 |
-
let scored=D.map(p=>{
|
| 2763 |
-
const pn=((p.name||'')+(p.cat||'')+(p.brand||'')).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/đ/g,'d');
|
| 2764 |
-
let sc=0;words.forEach(w=>{if(pn.includes(w))sc+=10});
|
| 2765 |
-
if(/malloca/i.test(p.brand))sc+=3;
|
| 2766 |
-
if(/grob/i.test(p.brand))sc+=2;
|
| 2767 |
-
// Budget filter from text
|
| 2768 |
-
const bm=code.match(/(\d+)\s*(tr|triệu|m)/i);
|
| 2769 |
-
if(bm){const b=parseInt(bm[1])*1e6;if(p.priceNum>0&&p.priceNum<=b*1.2)sc+=5;else if(p.priceNum>b*1.5)sc-=10}
|
| 2770 |
-
return{p,sc};
|
| 2771 |
-
}).filter(x=>x.sc>10).sort((a,b)=>b.sc-a.sc);
|
| 2772 |
-
allFound.push(...scored.slice(0,5).map(x=>x.p));
|
| 2773 |
});
|
| 2774 |
-
|
| 2775 |
-
|
| 2776 |
-
|
| 2777 |
-
|
| 2778 |
-
|
| 2779 |
-
h+='<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:10px">';
|
| 2780 |
-
unique.slice(0,12).forEach(p=>{
|
| 2781 |
-
h+='<div style="background:#fff;border-radius:8px;padding:10px;box-shadow:0 1px 3px rgba(0,0,0,.08);cursor:pointer;transition:.2s" onclick="if(typeof showDetail===\'function\')showDetail('+D.indexOf(p)+')" onmouseover="this.style.boxShadow=\'0 4px 12px rgba(0,0,0,.15)\'" onmouseout="this.style.boxShadow=\'0 1px 3px rgba(0,0,0,.08)\'">';
|
| 2782 |
-
if(p.image)h+='<img src="'+p.image+'" style="width:100%;height:100px;object-fit:contain;border-radius:4px;margin-bottom:6px" loading="lazy">';
|
| 2783 |
-
h+='<div style="font-size:.72rem;font-weight:700;color:#003f62">'+p.sku+'</div>';
|
| 2784 |
-
h+='<div style="font-size:.7rem;line-height:1.3;margin:3px 0;height:2.6em;overflow:hidden">'+p.name.substring(0,50)+'</div>';
|
| 2785 |
-
h+='<div style="font-size:.85rem;font-weight:800;color:#003f62">'+(p.price||'LH')+'</div>';
|
| 2786 |
-
h+='<div style="font-size:.6rem;color:#64748b">'+p.brand+'</div>';
|
| 2787 |
-
const specs=p.specs||{};const skeys=Object.keys(specs).slice(0,3);
|
| 2788 |
-
if(skeys.length){h+='<div style="margin-top:3px;font-size:.58rem;color:#666;border-top:1px solid #eee;padding-top:3px">';skeys.forEach(k=>{h+='• '+k+': '+specs[k]+'<br>'});h+='</div>'}
|
| 2789 |
-
h+='</div>';
|
| 2790 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2791 |
h+='</div>';
|
| 2792 |
-
|
| 2793 |
-
|
|
|
|
| 2794 |
}
|
| 2795 |
function doAIQuote(){
|
| 2796 |
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';
|
|
@@ -2935,5 +2930,53 @@ function _handleChatAI(msg){
|
|
| 2935 |
return false;
|
| 2936 |
}
|
| 2937 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2938 |
</body>
|
| 2939 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="vi">
|
| 3 |
+
<head><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":""}};</script>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
<title>V.AI STUDIO | Niềm tin khách hàng là tài sản của chúng tôi</title>
|
|
|
|
| 2730 |
<script>
|
| 2731 |
function doAISearch(){
|
| 2732 |
const q=document.getElementById('aiSearch').value.trim();
|
| 2733 |
+
if(!q){document.getElementById('aiResults').style.display='block';document.getElementById('aiResults').innerHTML='💡 Nhập mã SP (VD: MDI702) hoặc nhiều mã: MDI702, MC9086HS';return}
|
| 2734 |
const res=document.getElementById('aiResults');
|
| 2735 |
+
res.style.display='block';res.innerHTML='⏳ Đang tìm...';
|
| 2736 |
+
if(typeof D==='undefined'||!D.length){res.innerHTML='⏳ Đang tải SP...';return}
|
| 2737 |
+
// Split by comma/semicolon for multi-code
|
| 2738 |
+
let queries=q.split(/[,;]+/).map(c=>c.trim()).filter(c=>c.length>=2);
|
| 2739 |
+
if(queries.length===0)queries=[q];
|
| 2740 |
+
let allResults=[];
|
| 2741 |
+
queries.forEach(query=>{
|
| 2742 |
+
const qLow=query.toLowerCase().replace(/[.\-_ \/]/g,'');
|
| 2743 |
+
// Priority 1: EXACT match on any identifier field
|
| 2744 |
+
let exact=D.filter(p=>{
|
| 2745 |
+
const fields=[(p.sku||''),(p.mod||''),(p.slug||'')].map(f=>f.toLowerCase().replace(/[.\-_ \/]/g,''));
|
| 2746 |
+
return fields.some(f=>f===qLow);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2747 |
});
|
| 2748 |
+
if(exact.length){allResults.push(...exact);return}
|
| 2749 |
+
// Priority 2: Identifier CONTAINS query or query CONTAINS identifier
|
| 2750 |
+
let partial=D.filter(p=>{
|
| 2751 |
+
const fields=[(p.sku||''),(p.mod||''),(p.name||'').split('|')[0]].map(f=>f.toLowerCase().replace(/[.\-_ \/]/g,''));
|
| 2752 |
+
return fields.some(f=>f&&qLow.length>=3&&(f.includes(qLow)||qLow.includes(f)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2753 |
});
|
| 2754 |
+
if(partial.length){allResults.push(...partial.slice(0,5));return}
|
| 2755 |
+
// Priority 3: Keyword search in name+category
|
| 2756 |
+
const qNorm=query.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/đ/g,'d');
|
| 2757 |
+
const words=qNorm.split(/\s+/).filter(w=>w.length>=2&&!['cua','cai','cho','cac','nhung','voi','duoi','tren','khoang'].includes(w));
|
| 2758 |
+
const bm=query.match(/(\d+)\s*(tr|triệu|m)/i);
|
| 2759 |
+
const budget=bm?parseInt(bm[1])*1e6:0;
|
| 2760 |
+
let scored=D.map(p=>{
|
| 2761 |
+
const pText=((p.name||'')+(p.cat||'')).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/đ/g,'d');
|
| 2762 |
+
let sc=0;
|
| 2763 |
+
words.forEach(w=>{if(pText.includes(w))sc+=10});
|
| 2764 |
+
if(/malloca/i.test(p.brand))sc+=3;
|
| 2765 |
+
if(/grob/i.test(p.brand))sc+=2;
|
| 2766 |
+
if(budget&&p.priceNum>0){if(p.priceNum<=budget*1.2)sc+=5;else if(p.priceNum>budget*1.5)sc-=10}
|
| 2767 |
+
return{p,sc};
|
| 2768 |
+
}).filter(x=>x.sc>=10).sort((a,b)=>b.sc-a.sc);
|
| 2769 |
+
allResults.push(...scored.slice(0,6).map(x=>x.p));
|
| 2770 |
+
});
|
| 2771 |
+
// Deduplicate by sku
|
| 2772 |
+
let seen=new Set();let unique=[];
|
| 2773 |
+
allResults.forEach(p=>{const id=p.sku||p.name;if(!seen.has(id)){seen.add(id);unique.push(p)}});
|
| 2774 |
+
if(!unique.length){res.innerHTML='❌ Không tìm thấy "'+q+'". Thử nhập chính xác mã SP.';return}
|
| 2775 |
+
// Render results with specs
|
| 2776 |
+
let h='<div style="font-weight:700;margin-bottom:8px;font-size:.9rem">🔍 '+unique.length+' sản phẩm:</div>';
|
| 2777 |
+
h+='<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:10px">';
|
| 2778 |
+
unique.slice(0,12).forEach(p=>{
|
| 2779 |
+
h+='<div style="background:#fff;border-radius:10px;padding:10px;box-shadow:0 2px 6px rgba(0,0,0,.08);cursor:pointer;transition:.2s" onclick="if(typeof showDetail===\'function\')showDetail('+D.indexOf(p)+')" onmouseover="this.style.transform=\'translateY(-2px)\'" onmouseout="this.style.transform=\'\'"><div style="display:flex;align-items:center;gap:4px;margin-bottom:4px"><span style="font-size:.72rem;font-weight:700;color:#003f62">'+(p.sku||p.mod||'')+'</span><span style="font-size:.58rem;color:#888;background:#f0f0f0;padding:1px 4px;border-radius:3px">'+p.brand+'</span></div>';
|
| 2780 |
+
if(p.image)h+='<img src="'+p.image+'" style="width:100%;height:90px;object-fit:contain;border-radius:6px;margin-bottom:6px;background:#f8f8f8" loading="lazy">';
|
| 2781 |
+
h+='<div style="font-size:.7rem;line-height:1.3;height:2.5em;overflow:hidden;color:#333">'+((p.name||'').split('|').pop()||'').trim().substring(0,50)+'</div>';
|
| 2782 |
+
h+='<div style="font-size:.88rem;font-weight:800;color:#003f62;margin-top:4px">'+(p.price||'Liên hệ')+'</div>';
|
| 2783 |
+
const specs=p.specs||{};const sk=Object.entries(specs).slice(0,3);
|
| 2784 |
+
if(sk.length){h+='<div style="margin-top:4px;padding-top:4px;border-top:1px solid #eee;font-size:.58rem;color:#555">';sk.forEach(([k,v])=>{h+='<div>'+k+': <b>'+v+'</b></div>'});h+='</div>'}
|
| 2785 |
h+='</div>';
|
| 2786 |
+
});
|
| 2787 |
+
h+='</div>';
|
| 2788 |
+
res.innerHTML=h;
|
| 2789 |
}
|
| 2790 |
function doAIQuote(){
|
| 2791 |
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';
|
|
|
|
| 2930 |
return false;
|
| 2931 |
}
|
| 2932 |
</script>
|
| 2933 |
+
<script>
|
| 2934 |
+
// Intercept chat AI messages to use AI Search/Quote
|
| 2935 |
+
document.addEventListener('DOMContentLoaded',function(){
|
| 2936 |
+
// Find chat send button and input
|
| 2937 |
+
const chatInput=document.querySelector('.chat-input');
|
| 2938 |
+
const chatSend=document.querySelector('.chat-send');
|
| 2939 |
+
if(chatInput&&chatSend){
|
| 2940 |
+
const origClick=chatSend.onclick;
|
| 2941 |
+
chatSend.addEventListener('click',function(e){
|
| 2942 |
+
const msg=chatInput.value.trim();
|
| 2943 |
+
if(msg&&_tryChatAI(msg)){chatInput.value='';e.stopPropagation();e.preventDefault();return false}
|
| 2944 |
+
},true);
|
| 2945 |
+
chatInput.addEventListener('keypress',function(e){
|
| 2946 |
+
if(e.key==='Enter'){
|
| 2947 |
+
const msg=chatInput.value.trim();
|
| 2948 |
+
if(msg&&_tryChatAI(msg)){chatInput.value='';e.stopPropagation();e.preventDefault();return false}
|
| 2949 |
+
}
|
| 2950 |
+
},true);
|
| 2951 |
+
}
|
| 2952 |
+
});
|
| 2953 |
+
function _tryChatAI(msg){
|
| 2954 |
+
const lo=msg.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/đ/g,'d');
|
| 2955 |
+
// Detect: search intent, quote intent, or product code
|
| 2956 |
+
const isCode=/^[A-Z]{2,}[\-]?[A-Z0-9]{2,}/i.test(msg.trim());
|
| 2957 |
+
const hasComma=/[,;]/.test(msg);
|
| 2958 |
+
const isQuote=lo.includes('bao gia')||lo.includes('combo')||lo.includes('du toan');
|
| 2959 |
+
const isSearch=lo.includes('tim')||lo.includes('kiem')||lo.includes('goi y')||isCode||hasComma;
|
| 2960 |
+
if(isQuote||isSearch||isCode){
|
| 2961 |
+
// Put query in AI search box
|
| 2962 |
+
document.getElementById('aiSearch').value=msg;
|
| 2963 |
+
// Trigger appropriate function
|
| 2964 |
+
if(isQuote){doAIQuote()}else{doAISearch()}
|
| 2965 |
+
// Show chat response
|
| 2966 |
+
const chatBody=document.querySelector('.chat-body');
|
| 2967 |
+
if(chatBody){
|
| 2968 |
+
const bubble=document.createElement('div');
|
| 2969 |
+
bubble.className='chat-msg bot';
|
| 2970 |
+
bubble.innerHTML=isQuote?'📋 Em đã lên báo giá bên dưới ↓':'🔍 Em đã tìm SP bên dưới ↓';
|
| 2971 |
+
chatBody.appendChild(bubble);
|
| 2972 |
+
chatBody.scrollTop=chatBody.scrollHeight;
|
| 2973 |
+
}
|
| 2974 |
+
// Scroll to results
|
| 2975 |
+
setTimeout(()=>{document.getElementById('aiResults').scrollIntoView({behavior:'smooth',block:'center'})},300);
|
| 2976 |
+
return true;
|
| 2977 |
+
}
|
| 2978 |
+
return false;
|
| 2979 |
+
}
|
| 2980 |
+
</script>
|
| 2981 |
</body>
|
| 2982 |
</html>
|