fix: focusin触发setup, setInterval扫描input挂DOM blur

This commit is contained in:
yumoqing 2026-06-29 16:39:52 +08:00
parent 817cb354da
commit 92e1ce6dbb

View File

@ -63,23 +63,24 @@
{"widgettype": "Text", "options": {"text": "{{p.product_name or ''}}", "width": "34%", "padding": "0 12px", "fontSize": "12px", "color": "#F1F5F9"}},
{"widgettype": "Text", "options": {"text": "{{p.product_code or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
{
"widgettype": "UiFloat",
"widgettype": "VBox",
"options": {
"width": "22%",
"padding": "0 12px",
"name": "discount",
"value": "{{p.discount or ''}}",
"placeholder": "0~1",
"dec_len": 2,
"fontSize": "12px"
"data-pid": "{{p.productid}}",
"data-did": "{{p.detail_id or ''}}"
},
"binds": [
"subwidgets": [
{
"wid": "self",
"event": "blur",
"actiontype": "script",
"target": "self",
"script": "var inp=this.target.dom_element.querySelector('input');if(!inp)return;var nv=inp.value;fetch('{{save_url}}',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({discountid:'{{disc_id}}',productid:'{{p.productid}}',detail_id:'{{p.detail_id or ""}}',discount:nv})}).then(function(r){return r.json()}).then(function(r){if(r.widgettype==='Error')bricks.show_error(r.options)}).catch(function(e){console.error(e)})"
"widgettype": "UiFloat",
"options": {
"width": "100%",
"name": "discount",
"value": "{{p.discount or ''}}",
"placeholder": "0~1",
"dec_len": 2,
"fontSize": "12px"
}
}
]
}
@ -89,6 +90,14 @@
]
}
]
],
"binds": [
{
"wid": "self",
"event": "focusin",
"actiontype": "script",
"target": "self",
"script": "if(window._discSetupDone)return;window._discSetupDone=true;setInterval(function(){document.querySelectorAll('[data-pid] input[type=number]').forEach(function(inp){if(inp._db)return;inp._db=true;inp.addEventListener('blur',function(){var nv=inp.value;var w=inp.closest('[data-pid]');fetch('{{save_url}}',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({discountid:'{{disc_id}}',productid:w.getAttribute('data-pid'),detail_id:w.getAttribute('data-did')||'',discount:nv})}).then(function(r){return r.json()}).then(function(r){if(r.widgettype==='Error')bricks.show_error(r.options)}).catch(function(e){console.error(e)})})})},500)"
}
]
}
]
}