销售管理系统

// ZSB-AIMATCHUI-20261128 AI识别本店商品→收银加商品 (function(){ function zsbAiMatchUI(){ try{ var row=document.getElementById('aiCamShot'); if(!row) return; if(document.getElementById('aiMatchBtn')) return; var b=document.createElement('button'); b.id='aiMatchBtn'; b.className='btn btn-p'; b.style.cssText='margin-left:8px;padding:9px 16px'; b.innerHTML='🛒 识别本店商品'; b.onclick=function(){ shot(function(dataUrl){ zsbAiMatchStore(dataUrl); }); }; row.parentNode.insertBefore(b,row.nextSibling); var box=document.createElement('div'); box.id='aiMatchResult'; box.style.cssText='margin-top:12px'; row.parentNode.insertBefore(box,b.nextSibling); }catch(e){} } window.zsbAiMatchStore=function(dataUrl){ var box=document.getElementById('aiMatchResult'); if(box) box.innerHTML='
🔍 AI 正在识别本店商品…
'; call('/ai/match-store-product','POST',{store_id:(window.user&&user.store_id)||0,image:dataUrl}).then(function(r){ var d=(r&&r.data)||{}; var matched=d.matched||[]; if(!box) return; if(!matched.length){ box.innerHTML='
🤖 识别为:'+(d.identified||'未知')+'
⚠️ 本店商品库没找到匹配商品。
'; return; } var h='
🤖 识别为:'+(d.identified||'')+' · 匹配到 '+matched.length+' 个本店商品:
'; matched.forEach(function(p){ h+='
'+(p.image?'':'')+''+esc(p.name)+'
¥'+p.retail_price+'
'; }); box.innerHTML=h+'
'; }).catch(function(){ if(box) box.innerHTML='
识别失败
'; }); }; window.zsbAiAddCart=function(id,name,price){ try{ if(window.addToCart){ addToCart({id:id,name:decodeURIComponent(name),retail_price:price,quantity:1}); alert('已加入收银'); return; } }catch(e){} // 兜底:存到 localStorage 供收银台读取 try{ var cart=JSON.parse(localStorage.getItem('zsb_ai_cart')||'[]'); cart.push({id:id,name:decodeURIComponent(name),price:price,quantity:1}); localStorage.setItem('zsb_ai_cart',JSON.stringify(cart)); alert('已加入收银购物车(收银台可查看)'); }catch(e){ alert('已记录'); } }; window.zsbAiAddNew=function(name){ try{ show('products'); setTimeout(function(){ if(window.quickAddProduct) quickAddProduct(); var n=document.getElementById('fN'); if(n) n.value=decodeURIComponent(name); },300);}catch(e){} }; setTimeout(zsbAiMatchUI,600); try{ zsbAiMatchUI(); }catch(e){} })();