fix: JS直接new bricks.UiFloat+blur事件,去Form

This commit is contained in:
yumoqing 2026-06-29 16:21:21 +08:00
parent c126ca9021
commit 18eea5b5f9

View File

@ -56,30 +56,28 @@
{"widgettype": "Text", "options": {"text": "{{p.product_code or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
{
"widgettype": "VBox",
"id": "disc_cell_{{loop.index}}",
"options": {
"width": "22%",
"padding": "0 12px",
"uitype": "float",
"value": "{{p.discount or ''}}",
"placeholder": "0~1",
"dec_len": 2,
"data-productid": "{{p.productid}}",
"data-detail_id": "{{p.detail_id or ''}}"
},
"binds": [
{
"wid": "self",
"event": "blur",
"actiontype": "script",
"target": "self",
"script": "var el=this.target.dom_element;var v=el.querySelector('input');if(!v)return;var nv=v.value;var ov=el._lv;if(nv===ov)return;el._lv=nv;fetch('{{entire_url(\"./save_discount.dspy\")}}',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({discountid:'{{params_kw.discountid}}',productid:el.getAttribute('data-productid'),detail_id:el.getAttribute('data-detail_id'),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)})"
"data-pid": "{{p.productid}}",
"data-did": "{{p.detail_id or ''}}",
"data-discount": "{{p.discount or ''}}"
}
]
}
]
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
],
"binds": [
{
"wid": "self",
"event": "show",
"actiontype": "script",
"target": "self",
"script": "setTimeout(function(){for(var i=1;;i++){var cell=bricks.getWidgetById('disc_cell_'+i,bricks.app.root);if(!cell)break;(function(c,idx){var el=c.dom_element;var pid=el.getAttribute('data-pid');var did=el.getAttribute('data-did')||'';var val=el.getAttribute('data-discount')||'';var uf=new bricks.UiFloat({value:val,dec_len:2,placeholder:'0~1',fontSize:'12px',width:'100%'});uf._lv=val;uf.dom_element.addEventListener('blur',function(){var nv=String(uf.getValue()||'');if(nv===uf._lv)return;uf._lv=nv;fetch('{{entire_url(\"./save_discount.dspy\")}}',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({discountid:'{{params_kw.discountid}}',productid:pid,detail_id: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)})});c.add_widget(uf)})(cell,i)}},300)"
}
]
}