From 1bf3528b6d37cca43d54bc03622341a8bd2861db Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 29 Jun 2026 11:37:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=98=E6=89=A3=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=88=97=E5=AE=BD=E5=8A=A0=E5=A4=A7(3/5/3/3);=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Einline=5Fedit.js=E7=82=B9=E5=87=BB=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=8A=98=E6=89=A3;=20save=5Fdiscount=20uuid=E2=86=92getID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/load_path.py | 1 + wwwroot/discount_inline_edit.js | 116 ++++++++++++++++++++ wwwroot/discount_setting/index.ui | 8 +- wwwroot/discount_setting/save_discount.dspy | 2 +- 4 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 wwwroot/discount_inline_edit.js diff --git a/scripts/load_path.py b/scripts/load_path.py index 5f0a8a7..cd1eb40 100644 --- a/scripts/load_path.py +++ b/scripts/load_path.py @@ -95,6 +95,7 @@ for d in crud_defs: PATHS_ANY = [ f"/{MOD}/menu.ui", f"/{MOD}/discount_setting", + f"/{MOD}/discount_inline_edit.js", ] # 每个 CRUD 定义 → any 别名目录 + logined 页面和脚本 diff --git a/wwwroot/discount_inline_edit.js b/wwwroot/discount_inline_edit.js new file mode 100644 index 0000000..d25b4c2 --- /dev/null +++ b/wwwroot/discount_inline_edit.js @@ -0,0 +1,116 @@ +/** + * Discount inline editor for discount_setting Tabular. + * Scans discount cells after render and enables click-to-edit. + */ +(function() { + var PROCESSED_CELLS = new WeakSet(); + var SETUP_INTERVAL = 300; + + function findTabular() { + if (typeof bricks === 'undefined') return null; + try { + return bricks.getWidgetById('product_discount_tbl', bricks.app.root); + } catch(e) { + return null; + } + } + + function setupCell(cell) { + if (PROCESSED_CELLS.has(cell)) return; + var text = cell.textContent.trim(); + if (text === '' || isNaN(parseFloat(text))) return; + PROCESSED_CELLS.add(cell); + + cell.style.cursor = 'pointer'; + cell.title = '点击编辑折扣'; + + cell.addEventListener('click', function(e) { + e.stopPropagation(); + if (cell.querySelector('input')) return; + + var oldVal = cell.textContent.trim(); + var inp = document.createElement('input'); + inp.type = 'number'; + inp.step = '0.01'; + inp.min = '0'; + inp.max = '1'; + inp.value = oldVal; + inp.style.cssText = 'width:100%;box-sizing:border-box;text-align:center;background:#1E293B;color:#F1F5F9;border:1px solid #3B82F6;border-radius:4px;padding:2px 4px;font-size:12px;'; + + cell.textContent = ''; + cell.appendChild(inp); + inp.focus(); + inp.select(); + + var saved = false; + var saveFn = async function() { + if (saved) return; + saved = true; + var newVal = inp.value.trim(); + inp.disabled = true; + + if (newVal === oldVal) { + cell.textContent = oldVal; + return; + } + + try { + var url = new URL(window.location.href); + var discountid = url.searchParams.get('discountid') || ''; + var rowEl = cell.closest('.tabular-row'); + var productId = ''; + var detailId = ''; + var dv = findTabular(); + if (dv && dv.scrollpanel) { + for (var i = 0; i < dv.scrollpanel.children.length; i++) { + var r = dv.scrollpanel.children[i]; + if (r.dom_element === rowEl && r.user_data) { + productId = r.user_data.productid || ''; + detailId = r.user_data.detail_id || ''; + break; + } + } + } + + var resp = await fetch( + url.origin + url.pathname.replace(/\/[^\/]*$/, '/save_discount.dspy'), + { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + discountid: discountid, + productid: productId, + detail_id: detailId, + discount: newVal + }) + } + ); + + if (resp.ok) { + cell.textContent = parseFloat(newVal).toString(); + } else { + cell.textContent = oldVal; + } + } catch(ex) { + cell.textContent = oldVal; + } + }; + + inp.addEventListener('blur', saveFn); + inp.addEventListener('keydown', function(ev) { + if (ev.key === 'Enter') { ev.preventDefault(); inp.blur(); } + if (ev.key === 'Escape') { cell.textContent = oldVal; } + }); + }); + } + + function scan() { + var dv = findTabular(); + if (!dv || !dv.scrollpanel || !dv.scrollpanel.dom_element) return; + var cells = dv.scrollpanel.dom_element.querySelectorAll('.tabular-cell'); + cells.forEach(setupCell); + } + + // Keep scanning for new cells after each render + setInterval(scan, SETUP_INTERVAL); +})(); diff --git a/wwwroot/discount_setting/index.ui b/wwwroot/discount_setting/index.ui index 1b66271..e40b0cb 100644 --- a/wwwroot/discount_setting/index.ui +++ b/wwwroot/discount_setting/index.ui @@ -5,7 +5,7 @@ "width": "100%", "height": "100%", "title": "产品折扣设置", - "description": "选中产品后点击工具栏按钮设置折扣", + "description": "选中行后点击「设置折扣」编辑,折扣值留空或填0可清除折扣", "css": "card", "toolbar": { "tools": [ @@ -30,13 +30,13 @@ "name": "category_name", "title": "产品分类", "type": "str", - "cwidth": 2 + "cwidth": 3 }, { "name": "product_name", "title": "产品名称", "type": "str", - "cwidth": 4 + "cwidth": 5 }, { "name": "product_code", @@ -48,7 +48,7 @@ "name": "discount", "title": "当前折扣", "type": "float", - "cwidth": 2 + "cwidth": 3 } ] }, diff --git a/wwwroot/discount_setting/save_discount.dspy b/wwwroot/discount_setting/save_discount.dspy index 7028430..be12f87 100644 --- a/wwwroot/discount_setting/save_discount.dspy +++ b/wwwroot/discount_setting/save_discount.dspy @@ -37,7 +37,7 @@ try: else: # 新增 await sor.C('discount_detail', { - 'id': uuid(), + 'id': getID(), 'discountid': discountid, 'resellerid': user_orgid, 'prodtypeid': category_id,