sth
This commit is contained in:
parent
c1d6259bc9
commit
70b1ff8ce7
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user