Files
zszq-trs/YLErpWeb/Views/Pricing/_SyntheticPrice.cshtml
T
2024-05-09 14:06:26 +08:00

91 lines
3.7 KiB
Plaintext

<style>
.popover { font-family: inherit; }
.synthetic-pop { width: 200px; color: #000; font-size: .96rem; font-weight: 700; }
.synthetic-pop > div { padding: 6px 0; }
.synthetic-pop .col-auto { width: 80px; position: relative; }
.synthetic-pop .col-auto > span { position: absolute; bottom: 0px; right: 6px; }
.synthetic-pop input { width: 100%; color: #000; border: none; border-bottom: solid 1px #000; padding: 0; font-size: 1rem; font-weight: 700; border-radius: 0; }
</style>
<script type="text/html" id="synthenticPriceCtrlTpl">
<div style="width:200px" class="synthetic-pop">
<% _.each(SuList,function(item){ %>
<div class="row no-gutters">
<div class="col-auto"><span><%- item.Coefficient %>*<%- item.UnderlyingCode %></span></div>
<div class="col">
<input type="number" class="" value="<%- item.Price %>" oninput="synthenticPriceCtrl.oninput(this)" />
</div>
</div>
<% }); %>
</div>
</script>
<script>
(function (global) {
const _inputRegex = /^\d*\.?\d{0,4}$/;
//使用的是静态处理方式,多个组合标的价格时参考组合报价的处理
function synthenticPriceCtrl() {
}
var _synthetic, _syntheticInput, _debounceUpdate, _setSynthetic;
function setSynthetic(input, synthetic) {
synthetic.Price = synthetic.Constant + synthetic.SuList.reduce((acc, cur) => acc + cur.Price * cur.Coefficient, 0);
if ($("#BasisUnderlyingCode") && $("#BasisGap") && $("#BasisUnderlyingCode").val()) {
synthetic.Price = Number(synthetic.Price) + Number($("#BasisGap").val())
}
synthetic.Price = otcformat.trading.umprice(synthetic.Price);
_setSynthetic(input, synthetic);
}
synthenticPriceCtrl.oninput = function (input) {
debugger;
if (input.value && !_inputRegex.test(input.value)) {
input.value = input.value.substring(0, input.value.length - 1);
}
let index = $(input).closest('.row').prevAll().length;
_synthetic.SuList[index].Price = parseFloat(input.value) || 0;
_debounceUpdate(_syntheticInput, _synthetic);
};
//opts:{getSynthetic(input),setSynthetic(input, synthetic)}
synthenticPriceCtrl.init = function (opts) {
_setSynthetic = opts.setSynthetic || $.noop;
var compile = _.template($('#synthenticPriceCtrlTpl').html());
_debounceUpdate = _.debounce(setSynthetic, 500);
$('body').popover({
selector: "[readonly].has-popover-syn", placement: 'bottom', html: true, sanitize: false,
content: function () {
$(_syntheticInput).popover('hide');
_syntheticInput = this;
_synthetic = opts.getSynthetic(_syntheticInput);
return _synthetic ? compile(_synthetic) : '';
},
template: '<div class="popover popover-syn"><div class="arrow"></div><div class="popover-body"></div></div>'
}).on('hide.bs.popover', function (e) {
if ($(e.target).is(_syntheticInput)) {
_syntheticInput = null;
}
});
$(document).on('click touchend', function (e) {
if (!_syntheticInput) return;
var target = $(e.target);
if (target.hasClass('popover-syn') || target.closest('.popover-syn').length) return;
if (!target.is(_syntheticInput)) $(_syntheticInput).popover('hide');
});
};
global.synthenticPriceCtrl = synthenticPriceCtrl;
}(window));
</script>