bep40 commited on
Commit
a1d707b
·
verified ·
1 Parent(s): 0ff44d4

Fix: CK prompt (local calc), Eurogold img retry, function name match

Browse files
Files changed (1) hide show
  1. index.html +43 -19
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><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>
@@ -858,7 +858,7 @@ let g=document.getElementById('grid');
858
  g.className='pg'+(S.view==='l'?' lv':'');
859
  if(!items.length){g.innerHTML=`<div class="empty" style="grid-column:1/-1"><i class="fas fa-search"></i><h3>Không tìm thấy</h3><p>Thử thay đổi bộ lọc hoặc từ khóa</p><button class="reset-btn" onclick="resetAll()">Xóa bộ lọc</button></div>`;
860
  }else{
861
- g.innerHTML=items.map((p,i)=>{let idx=D.indexOf(p);let brandColor=p.brand==='Eurogold'?'#c8102e':p.brand==='Grob'?'#2e7d32':'var(--p)';let href='/san-pham/'+p.slug+'/index.html';return`<a class="pc fade" href="${href}" onclick="event.preventDefault();showDetail(${idx})" style="transition-delay:${Math.min(i*25,400)}ms;display:block"><div class="pi"><img src="${p.image}" alt="${p.name}" loading="lazy" onerror="this.style.display='none'"><span class="pi-badge"><i class="fas ${p.catIcon}"></i> ${p.cat}</span><span style="position:absolute;top:8px;right:8px;background:${brandColor};color:#fff;padding:3px 8px;border-radius:5px;font-size:.58rem;font-weight:700">${p.brand}</span></div><div class="pb"><div style="font-size:.65rem;font-weight:700;color:${brandColor};letter-spacing:.5px;margin-bottom:4px">${p.model||p.brand}</div><div class="pn">${p.name}</div><div class="pf"><span class="pp">${p.price||'Liên hệ'}</span><i class="fas fa-chevron-right"></i></div></div></a>`}).join('');
862
  }
863
  requestAnimationFrame(()=>document.querySelectorAll('.fade').forEach(e=>e.classList.add('vis')));
864
  renderPag(tp);
@@ -2032,31 +2032,55 @@ document.querySelectorAll('.qt-disc').forEach(el=>{el.disabled=true;el.style.bac
2032
  }
2033
  }
2034
 
2035
- async function applyDiscount(){
2036
  let inp=document.querySelector('.quote-section textarea, .quote-section input[type="text"]');
2037
  let txt=inp?inp.value.trim():'';
2038
  let btn=document.getElementById('aiDiscBtn');
2039
  let statusEl=document.getElementById('aiDiscStatus');
 
2040
 
2041
- // Parse CK percentage from text: "30%", "ck 30", "giảm 30%", etc.
2042
- let match=txt.match(/(\d+)\s*%?/);
2043
- let ckPercent=match?parseFloat(match[1]):0;
2044
-
2045
- if(!ckPercent||ckPercent<=0||ckPercent>90){
2046
- if(statusEl)statusEl.textContent='Nhập % chiết khấu (VD: 30%)';
2047
- return;
 
 
 
 
 
 
 
 
 
2048
  }
2049
-
2050
- // Apply CK to all items locally - NO API needed
2051
- cart.forEach((c,i)=>{
2052
- if(c.priceNum>0){
2053
- let discPrice=Math.round(c.priceNum*(1-ckPercent/100));
2054
- let discInput=document.querySelector('.qt-disc[data-idx="'+i+'"]');
2055
- if(discInput)discInput.value=discPrice.toLocaleString('vi-VN');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2056
  }
2057
- });
2058
  updateQuoteTotal();
2059
- if(statusEl)statusEl.textContent='\u2705 Đã áp dụng CK '+ckPercent+'% cho '+cart.length+' SP';
2060
  }
2061
 
2062
  function renderQuoteTable(){
 
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><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>
 
858
  g.className='pg'+(S.view==='l'?' lv':'');
859
  if(!items.length){g.innerHTML=`<div class="empty" style="grid-column:1/-1"><i class="fas fa-search"></i><h3>Không tìm thấy</h3><p>Thử thay đổi bộ lọc hoặc từ khóa</p><button class="reset-btn" onclick="resetAll()">Xóa bộ lọc</button></div>`;
860
  }else{
861
+ g.innerHTML=items.map((p,i)=>{let idx=D.indexOf(p);let brandColor=p.brand==='Eurogold'?'#c8102e':p.brand==='Grob'?'#2e7d32':'var(--p)';let href='/san-pham/'+p.slug+'/index.html';return`<a class="pc fade" href="${href}" onclick="event.preventDefault();showDetail(${idx})" style="transition-delay:${Math.min(i*25,400)}ms;display:block"><div class="pi"><img src="${p.image}" alt="${p.name}" loading="lazy" onerror="if(!this.dataset.retry){this.dataset.retry=1;this.referrerPolicy='no-referrer';this.src=this.src}else{this.style.display='none'}"><span class="pi-badge"><i class="fas ${p.catIcon}"></i> ${p.cat}</span><span style="position:absolute;top:8px;right:8px;background:${brandColor};color:#fff;padding:3px 8px;border-radius:5px;font-size:.58rem;font-weight:700">${p.brand}</span></div><div class="pb"><div style="font-size:.65rem;font-weight:700;color:${brandColor};letter-spacing:.5px;margin-bottom:4px">${p.model||p.brand}</div><div class="pn">${p.name}</div><div class="pf"><span class="pp">${p.price||'Liên hệ'}</span><i class="fas fa-chevron-right"></i></div></div></a>`}).join('');
862
  }
863
  requestAnimationFrame(()=>document.querySelectorAll('.fade').forEach(e=>e.classList.add('vis')));
864
  renderPag(tp);
 
2032
  }
2033
  }
2034
 
2035
+ async function applyAiDiscount(){
2036
  let inp=document.querySelector('.quote-section textarea, .quote-section input[type="text"]');
2037
  let txt=inp?inp.value.trim():'';
2038
  let btn=document.getElementById('aiDiscBtn');
2039
  let statusEl=document.getElementById('aiDiscStatus');
2040
+ if(!txt){if(statusEl)statusEl.textContent='VD: CK 30%, phụ phí 500k, cọc 5tr';return}
2041
 
2042
+ // Parse multiple commands from prompt
2043
+ let results=[];
2044
+ // CK percentage: "ck 30%", "giảm 30", "chiết khấu 25%"
2045
+ let ckMatch=txt.match(/(?:ck|chiết khấu|giảm|discount)\s*(\d+)\s*%?/i);
2046
+ if(ckMatch){
2047
+ let pct=parseFloat(ckMatch[1]);
2048
+ if(pct>0&&pct<=90){
2049
+ cart.forEach((c,i)=>{
2050
+ if(c.priceNum>0){
2051
+ let dp=Math.round(c.priceNum*(1-pct/100));
2052
+ let el=document.querySelector('.qt-disc[data-idx="'+i+'"]');
2053
+ if(el)el.value=dp.toLocaleString('vi-VN');
2054
+ }
2055
+ });
2056
+ results.push('CK '+pct+'%');
2057
+ }
2058
  }
2059
+ // Phụ phí: "phụ phí 500k", "phí vận chuyển 1tr"
2060
+ let feeMatch=txt.match(/(?:phụ phí|phí|fee)\s*(\d+)\s*(k|tr|triệu|ngàn|nghìn)?/i);
2061
+ if(feeMatch){
2062
+ let fee=parseFloat(feeMatch[1]);
2063
+ let unit=(feeMatch[2]||'').toLowerCase();
2064
+ if(unit==='k'||unit==='ngàn'||unit==='nghìn')fee*=1000;
2065
+ else if(unit==='tr'||unit==='triệu')fee*=1000000;
2066
+ // Add fee note to status
2067
+ results.push('Phụ phí: '+fee.toLocaleString('vi-VN')+'đ');
2068
+ }
2069
+ // Cọc: "cọc 5tr", "đặt cọc 30%"
2070
+ let cocMatch=txt.match(/(?:cọc|đặt cọc|deposit)\s*(\d+)\s*(k|tr|triệu|%)?/i);
2071
+ if(cocMatch){
2072
+ let cocVal=parseFloat(cocMatch[1]);
2073
+ let cocUnit=(cocMatch[2]||'').toLowerCase();
2074
+ if(cocUnit==='%'){
2075
+ results.push('Cọc: '+cocVal+'% tổng');
2076
+ }else{
2077
+ if(cocUnit==='k')cocVal*=1000;
2078
+ else if(cocUnit==='tr'||cocUnit==='triệu')cocVal*=1000000;
2079
+ results.push('Cọc: '+cocVal.toLocaleString('vi-VN')+'đ');
2080
  }
2081
+ }
2082
  updateQuoteTotal();
2083
+ if(statusEl)statusEl.textContent=results.length?'\u2705 '+results.join(' | '):'Không nhận diện. VD: ck 30%, phụ phí 500k';
2084
  }
2085
 
2086
  function renderQuoteTable(){