This commit is contained in:
xman 2025-06-18 11:21:48 +08:00
parent c1d6259bc9
commit 70b1ff8ce7
2 changed files with 34 additions and 0 deletions

View File

@ -263,6 +263,15 @@
</div>
-->
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('预计利润')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-performance" readonly class="form-control" type="number" value="{$row.performance|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">

View File

@ -113,6 +113,31 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
edit: function () {
Controller.api.bindevent();
// 浮点数转两位小数(避免精度问题)
function toFixedNum(num) {
return (Math.round((num + Number.EPSILON) * 100) / 100).toFixed(2);
}
// 利润计算函数
function calcProfit() {
var online = parseFloat($('#c-online_amount_last').val()) || 0;
var offline = parseFloat($('#c-offline_amount').val()) || 0;
var cost = parseFloat($('#c-cost').val()) || 0;
var material = parseFloat($('#c-material_cost').val()) || 0;
var profit = online + offline - cost - material;
$('#c-performance').val(toFixedNum(profit));
}
// 监听字段变化,实时计算利润
$('#c-online_amount_last, #c-offline_amount, #c-cost, #c-material_cost').on('input', function () {
calcProfit();
});
// 页面加载时自动计算一次利润,避免空白
calcProfit();
},
api: {
bindevent: function () {