fix: UiFloat用urlwidget+datawidget:self; dspy对比old_discount跳过无变化
This commit is contained in:
parent
92e1ce6dbb
commit
f14eb4f704
@ -1,6 +1,4 @@
|
|||||||
{% set products = get_discount_setting_products(request) %}
|
{% set products = get_discount_setting_products(request) %}
|
||||||
{% set save_url = entire_url('./save_discount.dspy') %}
|
|
||||||
{% set disc_id = params_kw.discountid %}
|
|
||||||
{
|
{
|
||||||
"widgettype": "VBox",
|
"widgettype": "VBox",
|
||||||
"options": {
|
"options": {
|
||||||
@ -63,23 +61,31 @@
|
|||||||
{"widgettype": "Text", "options": {"text": "{{p.product_name or ''}}", "width": "34%", "padding": "0 12px", "fontSize": "12px", "color": "#F1F5F9"}},
|
{"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": "Text", "options": {"text": "{{p.product_code or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
|
||||||
{
|
{
|
||||||
"widgettype": "VBox",
|
"widgettype": "UiFloat",
|
||||||
"options": {
|
"options": {
|
||||||
"width": "22%",
|
"width": "22%",
|
||||||
"padding": "0 12px",
|
"padding": "0 12px",
|
||||||
"data-pid": "{{p.productid}}",
|
"name": "discount",
|
||||||
"data-did": "{{p.detail_id or ''}}"
|
"value": "{{p.discount or ''}}",
|
||||||
|
"placeholder": "0~1",
|
||||||
|
"dec_len": 2,
|
||||||
|
"fontSize": "12px"
|
||||||
},
|
},
|
||||||
"subwidgets": [
|
"binds": [
|
||||||
{
|
{
|
||||||
"widgettype": "UiFloat",
|
"wid": "self",
|
||||||
|
"event": "blur",
|
||||||
|
"actiontype": "urlwidget",
|
||||||
|
"datawidget": "self",
|
||||||
|
"target": "self",
|
||||||
"options": {
|
"options": {
|
||||||
"width": "100%",
|
"url": "{{entire_url('./save_discount.dspy')}}",
|
||||||
"name": "discount",
|
"params": {
|
||||||
"value": "{{p.discount or ''}}",
|
"discountid": "{{params_kw.discountid}}",
|
||||||
"placeholder": "0~1",
|
"old_discount": "{{p.discount or ''}}",
|
||||||
"dec_len": 2,
|
"productid": "{{p.productid}}",
|
||||||
"fontSize": "12px"
|
"detail_id": "{{p.detail_id or ''}}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -90,14 +96,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
|
||||||
"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)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@ -1,54 +1,60 @@
|
|||||||
# Upsert折扣明细:有detail_id则更新,无则新增
|
# Upsert折扣明细:对比old_discount和discount,不同才更新
|
||||||
# 参数: discountid, productid, category_id, discount, detail_id(可选)
|
# 参数: discountid, productid, discount, old_discount, detail_id(可选)
|
||||||
|
|
||||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
discountid = params_kw.get('discountid')
|
discountid = params_kw.get('discountid')
|
||||||
productid = params_kw.get('productid')
|
productid = params_kw.get('productid')
|
||||||
category_id = params_kw.get('category_id')
|
|
||||||
discount_val = params_kw.get('discount')
|
discount_val = params_kw.get('discount')
|
||||||
|
old_discount = params_kw.get('old_discount')
|
||||||
detail_id = params_kw.get('detail_id')
|
detail_id = params_kw.get('detail_id')
|
||||||
|
|
||||||
if not discountid or not productid:
|
if not discountid or not productid:
|
||||||
raise Exception('缺少必要参数: discountid, productid')
|
raise Exception('缺少必要参数: discountid, productid')
|
||||||
|
|
||||||
|
# 对比新旧值,相同则跳过
|
||||||
|
if discount_val is not None and old_discount is not None:
|
||||||
|
try:
|
||||||
|
if float(discount_val) == float(old_discount):
|
||||||
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣未变化', 'type': 'success'}}
|
||||||
|
return result
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
user_orgid = await get_userorgid()
|
||||||
|
dbname = get_module_dbname('discount')
|
||||||
|
|
||||||
# discount为0或空时,如果已有记录则删除
|
# discount为0或空时,如果已有记录则删除
|
||||||
if not discount_val or float(discount_val) == 0:
|
if not discount_val or float(discount_val) == 0:
|
||||||
if detail_id:
|
if detail_id:
|
||||||
dbname = get_module_dbname('discount')
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
await sor.D('discount_detail', {'id': detail_id})
|
await sor.D('discount_detail', {'id': detail_id})
|
||||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣已清除', 'type': 'success'}}
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣已清除', 'type': 'success'}}
|
||||||
else:
|
else:
|
||||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'ok', 'type': 'success'}}
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'ok', 'type': 'success'}}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
dbname = get_module_dbname('discount')
|
|
||||||
user_orgid = await get_userorgid()
|
|
||||||
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
if detail_id:
|
if detail_id:
|
||||||
# 更新
|
|
||||||
await sor.U('discount_detail', {
|
await sor.U('discount_detail', {
|
||||||
'id': detail_id,
|
'id': detail_id,
|
||||||
'discount': float(discount_val)
|
'discount': float(discount_val)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
# 新增
|
|
||||||
await sor.C('discount_detail', {
|
await sor.C('discount_detail', {
|
||||||
'id': getID(),
|
'id': getID(),
|
||||||
'discountid': discountid,
|
'discountid': discountid,
|
||||||
'resellerid': user_orgid,
|
'resellerid': user_orgid,
|
||||||
'prodtypeid': category_id,
|
'prodtypeid': None,
|
||||||
'productid': productid,
|
'productid': productid,
|
||||||
'discount': float(discount_val)
|
'discount': float(discount_val)
|
||||||
})
|
})
|
||||||
|
|
||||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣保存成功', 'type': 'success'}}
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣保存成功', 'type': 'success'}}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug(f'save_discount error: {e}')
|
debug(f'save_discount error: {format_exc()}')
|
||||||
result['options'] = {'title': 'Error', 'message': f'保存失败: {str(e)}', 'type': 'error'}
|
result['options'] = {'title': 'Error', 'message': f'保存失败: {str(e)}', 'type': 'error'}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user