fix: 折扣设置列宽加大(3/5/3/3); 新增inline_edit.js点击编辑折扣; save_discount uuid→getID
This commit is contained in:
parent
3a91d0091c
commit
1bf3528b6d
@ -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 页面和脚本
|
||||
|
||||
116
wwwroot/discount_inline_edit.js
Normal file
116
wwwroot/discount_inline_edit.js
Normal file
@ -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);
|
||||
})();
|
||||
@ -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
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@ -37,7 +37,7 @@ try:
|
||||
else:
|
||||
# 新增
|
||||
await sor.C('discount_detail', {
|
||||
'id': uuid(),
|
||||
'id': getID(),
|
||||
'discountid': discountid,
|
||||
'resellerid': user_orgid,
|
||||
'prodtypeid': category_id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user