//otcformat禁止千分位分组 window.otcformat.options.disableGrouping = true; const umPriceFmt = otcformat.trading.umprice; const unwindPercentFormat = otcformat.fixed2; $(function () { $(".datepicker").datepicker({ changeMonth: true, changeYear: true, showButtonPanel: true, showOtherMonths: true, selectOtherMonths: true }); //SetAceDropDown(295); $(".select").prop("disabled", true); $('#FinalPrice').on('keypress', function (event) { if (event.keyCode === 13) { changeTradePrice(true, false); } }); $("#FinalPrice,#Strike").val(function (index, curVal) { return umPriceFmt(curVal); }); $("#FinalPrice").after(''); if (!g_isUseApproval) { changeUnwindType(); changeExtraAmount(); } else { changeUnwindPrice(); } getUnderlyingPrice(); }); function getUnderlyingPrice() { let date = page.ExerciseDate > page.valueDate ? page.valueDate : page.ExerciseDate; main.post("/underlying_manager/GetUnderlyingPriceByCode", { code: $("#UnderlyingCode").val(), tradeId: $("#TradeId").val(), valuedate: date }).done(function (result) { $("#FinalPrice").val(umPriceFmt(result.obj)); $("#SpotPrice").val(umPriceFmt(result.obj)); //亚式标的现价也显示 changeTradePrice(true, true); }); } function changeExtraAmount() { changeTradePrice(false, false); if (page.isCustomTrade) { $("#InitialAmount").val(otcformat.trading.tradePrice(parseFloat($("#UnwindPrice").val()) * parseFloat($("#Notional").val()))); $("#Amount").val(otcformat.trading.tradePrice(parseFloat($("#InitialAmount").val()) + parseFloat($("#ExtraAmount").val()))); } //额外金额/名义本金 = 行权费率 $("#ExtraAmount").val(otcformat.trading.tradePrice($("#ExtraAmount").val())); var ExtraAmount = $("#ExtraAmount").val(); var StockEqvNotional = otcformat.trading.StockEqvNotional($("#StockEqvNotional").val().replace(/\$|\,/g, '')); var costRatio = otcformat.trading.premiumRatePLeft(parseFloat(ExtraAmount) / parseFloat(StockEqvNotional) * 10000); $("#ExerciseCostRatio").val(costRatio); //这边好像只是显示,没有其它作用 } function changeUnwindPrice() { changeTradePrice(false, false); if (page.isCustomTrade) { $("#InitialAmount").val(otcformat.trading.tradePrice(parseFloat($("#UnwindPrice").val()) * parseFloat($("#Notional").val()))); $("#Amount").val(otcformat.trading.tradePrice(parseFloat($("#InitialAmount").val()) + parseFloat($("#ExtraAmount").val()))); } // changeTradePrice(false, false); //额外金额/名义本金 = 行权费率 $("#ExtraAmount").val(otcformat.trading.tradePrice($("#ExtraAmount").val())); var ExtraAmount = $("#ExtraAmount").val(); var StockEqvNotional = otcformat.trading.StockEqvNotional($("#StockEqvNotional").val().replace(/\$|\,/g, '')); var costRatio = otcformat.trading.premiumRatePLeft(parseFloat(ExtraAmount) / parseFloat(StockEqvNotional) * 10000); $("#ExerciseCostRatio").val(costRatio); } function changeTradePrice(flag, isRefreshFinalPrice) { $("#UnwindPercentRate").val(unwindPercentFormat($("#UnwindPercentRate").val())); $("#UnwindStockEqvNotional").val(otcformat.trading.StockEqvNotional($("#UnwindStockEqvNotional").val())); $("#FinalPrice").val(umPriceFmt($("#FinalPrice").val().replace(/[^0-9.-]/g, ''))); $("#Strike").val(umPriceFmt($("#Strike").val().replace(/[^0-9.-]/g, ''))); $("#ExtraAmount").val(otcformat.trading.tradePrice($("#ExtraAmount").val().replace(/[^0-9.-]/g, ''))); $("#Notional").val(otcformat.trading.notional($("#Notional").val())); //标的价格 var finalPrice = parseFloat($("#FinalPrice").val()) || 0; //额外金额 var extraAmount = parseFloat($("#ExtraAmount").val()) || 0; //初始金额 var initialAmount = parseFloat($("#InitialAmount").val()) || 0; var unwindPrice = parseFloat($("#UnwindPrice").val()) || 0; //行权价 var strike = parseFloat($("#Strike").val()) || 0; //份额 var unwindNotional = $("#UnwindNotional").val(); if (page.IsUsePremiumRate) { if ($("#IsUnwindStockEqvNotional").val() == "true") { unwindNotional = $("#UnwindStockEqvNotional").val() / page.OriginalStockEqvNotional * page.OriginalNotional; } else { unwindNotional = $("#UnwindPercentRate").val() / 100 * page.OriginalNotional; } } var Notional = unwindNotional; //交易类型 var Trade_TradeType = $("#Trade_TradeType").val(); if (flag) { if (Trade_TradeType === "结构化交易") { var option = { url: "/trade_cash/CalcMultyTradeAmount", type: "POST", data: { enid: $("#TradeId").val(), finalPrice: finalPrice, strike: strike }, dataType: "json", success: function (data) { console.log(data); if (data.success) { if (data.obj) { $("#UnwindPrice").val(otcformat.trading.tradeSinglePrice(data.obj.UnwindPrice)); $("#InitialAmount").val(otcformat.trading.tradePrice(data.obj.Amount)); var amount = parseFloat(data.obj.Amount * 1) + parseFloat(extraAmount * 1); $("#Amount").val(otcformat.trading.tradePrice(amount)); } else { $("#UnwindPrice").val(0); $("#InitialAmount").val(0); $("#Amount").val(0); } } }, error: function (msg) { $("#UnwindPrice").val(0); $("#InitialAmount").val(0); $("#Amount").val(0); } }; $.ajax({ url: option.url, type: option.type, data: option.data, dataType: option.dataType, //格式是html success: function (data) { option.success(data); }, error: function (msg) { option.error(msg); } }); } else { let option = { url: "/trade_cash/CalcAmount", type: "POST", data: { enid: $("#TradeId").val(), finalPrice: finalPrice, strike: strike, notional: Notional, isRefreshFinalPrice: isRefreshFinalPrice, unwindType: $("#UnwindType").val() }, dataType: "json", //格式是html success: function (data) { console.log(data); if (data.success) { if (data.obj) { $("#UnwindPrice").val(otcformat.trading.tradeSinglePrice(data.obj.UnwindPrice)); $("#InitialAmount").val(otcformat.trading.tradePrice(data.obj.Amount)); var amount = parseFloat(data.obj.Amount * 1) + parseFloat(extraAmount * 1); $("#Amount").val(otcformat.trading.tradePrice(amount)); if (isRefreshFinalPrice && data.obj.FinalPrice) { $("#FinalPrice").val(umPriceFmt(data.obj.FinalPrice)); } } else { $("#UnwindPrice").val(0); $("#InitialAmount").val(0); $("#Amount").val(0); } } }, error: function (msg) { $("#UnwindPrice").val(0); $("#InitialAmount").val(0); $("#Amount").val(0); } }; //MyAjax(option); $.ajax({ url: option.url, type: option.type, data: option.data, dataType: option.dataType, //格式是html success: function (data) { option.success(data); }, error: function (msg) { option.error(msg); } }); } } else { $("#UnwindPrice").val(otcformat.trading.tradeSinglePrice(unwindPrice)); $("#InitialAmount").val(otcformat.trading.tradePrice(initialAmount)); $("#Amount").val(otcformat.trading.tradePrice(initialAmount + extraAmount * 1)); } } function changeUnwindType() { if ($("#UnwindType").val() === "全部行权") { if (page.IsUsePremiumRate) { $("#UnwindPercentRate").prop("disabled", true); $("#UnwindPercentRate").val(unwindPercentFormat(page.StockEqvNotional / page.OriginalStockEqvNotional * 100)); } else { $("#UnwindNotional").prop("disabled", true); $("#UnwindNotional").val(otcformat.trading.notional(page.Notional)); } } else { $(page.IsUsePremiumRate ? "#UnwindPercentRate" : "#UnwindNotional").prop("disabled", false); } changeTradePrice(true, false); } function exchangeToUnwindStockEqvNotional() { $("#IsUnwindStockEqvNotional").val(true); $("#UnwindPercentRate").parent().hide(); $("#UnwindStockEqvNotional").parent().show(); $("#UnwindStockEqvNotional").val(page.StockEqvNotional); changeTradePrice(true, false); } function exchangeToUnwindPercentRate() { $("#IsUnwindStockEqvNotional").val(false); $("#UnwindPercentRate").parent().show(); $("#UnwindPercentRate").val(unwindPercentFormat(page.StockEqvNotional / page.OriginalStockEqvNotional * 100)); $("#UnwindStockEqvNotional").parent().hide(); changeTradePrice(true, false); } function checkSubmitData() { return $('#trade_cashEditForm').valid(); } function savetrade_cash(recheck) { if (!checkSubmitData()) return false; $("#ValidStrike").prop("disabled", false); $("#Strike").prop("disabled", false); var isVirture = ($("#CallPut").val() === "Call" && parseFloat($("#FinalPrice").val()) < parseFloat($("#ValidStrike").val() || $("#Strike").val())) || ($("#CallPut").val() === "Put" && parseFloat($("#FinalPrice").val()) > parseFloat($("#ValidStrike").val() || $("#Strike").val())); $("#ValidStrike").prop("disabled", true); $("#Strike").prop("disabled", true); var message = "确认执行合约?"; if (recheck) { message = "确认复核?" } else { if (isVirture && !page.isExpire) { message = "虚值行权,确认执行合约?" } } main.confirm(message, function () { $("#TradeType").prop("disabled", false); $("#Strike").prop("disabled", false); $("#Notional").prop("disabled", false); $("#UnwindPrice").prop("disabled", false); $("#InitialAmount").prop("disabled", false); $("#Amount").prop("disabled", false); if ($("#UnwindType").val() === "全部行权") { $("#UnwindNotional").prop("disabled", false); $("#UnwindPercentRate").prop("disabled", false); } if (page.IsUsePremiumRate) { if ($("#IsUnwindStockEqvNotional").val() == "true") { $("#UnwindPercentRate").val($("#UnwindStockEqvNotional").val() / page.OriginalStockEqvNotional * 100); } $("#UnwindNotional").val($("#UnwindPercentRate").val() / 100 * page.OriginalNotional); } else { $("#UnwindPercentRate").val($("#UnwindNotional").val() / page.OriginalNotional * 100); } if ($("#TradePremium").val() != 0) { $("#TradePremium").val($("#TradePremium").val() / 100) } var data = $("#trade_cashEditForm").serialize(); if ($("#UnwindType").prop("disabled") == true) { data = $.param({ "UnwindType": $("#UnwindType").val(), }) + "&" + $("#trade_cashEditForm").serialize(); } $("#TradeType").prop("disabled", true); $("#Strike").prop("disabled", true); $("#Notional").prop("disabled", true); $("#UnwindPrice").prop("disabled", !page.isCustomTrade); $("#InitialAmount").prop("disabled", true); $("#Amount").prop("disabled", true); if ($("#UnwindType").val() === "全部行权") { $("#UnwindNotional").prop("disabled", true); $("#UnwindPercentRate").prop("disabled", true); } let _Version = recheck ? "" : "V2"; main.post("/trade_cash/executionTradeCashJson?_Version=" + _Version, data).done(function (res) { if (recheck) { closetrade_cashWindow(); } else { _Version === "V2" ? previewTradeAbstractV2(res.obj, res.msg) : previewTradeAbstract(res.obj, res.msg); } }); }); } function applyExerciseRecheck() { $("#ValidStrike").prop("disabled", false); $("#Strike").prop("disabled", false); var isVirture = ($("#CallPut").val() === "Call" && parseFloat($("#FinalPrice").val()) < parseFloat($("#ValidStrike").val() || $("#Strike").val())) || ($("#CallPut").val() === "Put" && parseFloat($("#FinalPrice").val()) > parseFloat($("#ValidStrike").val() || $("#Strike").val())); $("#ValidStrike").prop("disabled", true); main.confirm(isVirture && !page.isExpire ? "虚值行权,确认提交行权审核?" : "确认提交行权审核?", function () { $("#TradeType").prop("disabled", false); $("#FinalPrice").prop("disabled", false); $("#Notional").prop("disabled", false); $("#UnwindPrice").prop("disabled", false); $("#InitialAmount").prop("disabled", false); $("#Amount").prop("disabled", false); $("#ExtraAmount").prop("disabled", false); if ($("#UnwindType").val() === "全部行权") { $("#UnwindNotional").prop("disabled", false); $("#UnwindPercentRate").prop("disabled", false); } if (page.IsUsePremiumRate) { if ($("#IsUnwindStockEqvNotional").val() == "true") { $("#UnwindPercentRate").val($("#UnwindStockEqvNotional").val() / page.OriginalStockEqvNotional * 100); } $("#UnwindNotional").val($("#UnwindPercentRate").val() / 100 * page.OriginalNotional); } else { $("#UnwindPercentRate").val($("#UnwindNotional").val() / page.OriginalNotional * 100); } var data = $("#trade_cashEditForm").serialize(); if ($("#UnwindType").prop("disabled") == true) { data = $.param({ "UnwindType": $("#UnwindType").val(), }) + "&" + $("#trade_cashEditForm").serialize(); } $("#Strike").prop("disabled", true); $("#TradeType").prop("disabled", true); $("#FinalPrice").prop("disabled", true); $("#Notional").prop("disabled", true); $("#UnwindPrice").prop("disabled", !page.isCustomTrade); $("#InitialAmount").prop("disabled", true); $("#Amount").prop("disabled", true); $("#ExtraAmount").prop("disabled", true); if ($("#UnwindType").val() === "全部行权") { $("#UnwindNotional").prop("disabled", true); $("#UnwindPercentRate").prop("disabled", true); } let _Version = "V2"; main.post("/trade_cash/applyExerciseRecheck?_Version=" + _Version, data).done(function (res) { _Version === "V2" ? previewTradeAbstractV2(res.obj, res.msg) : previewTradeAbstract(res.obj, res.msg); }); }); } function previewTradeAbstract(trade, msg) { trade.Amount = $("#Amount").val(); trade.UnWindPrice = $("#UnwindPrice").val(); page.Model.FinalPrice = $("#FinalPrice").val(); var rowData = ""; main.post("/trade/TradeterminationAbstract", { tc: page.Model, td: trade, isUnwind: false }, { async: false }).done(function (res) { rowData = res; }) layer.open({ type: 1, title: "行权摘要", shadeClose: false, btn: ['保存', '关闭'], yes: function (index, layero) { var dateTemp = new Date().Format("yyyyMMddhhmmss"); var exKey = "Trade_" + "行权" + "_" + dateTemp; downCsv(exKey, rowData, ".txt"); main.message("导出成功", 50); try { (parent || window).main.message(msg); closetrade_cashWindow(); } catch (e) { // } }, cancel: function (index, layero) { try { (parent || window).main.message(msg); closetrade_cashWindow(); } catch (e) { // } }, shade: 0.4, area: ['380px', '400px'], content: "
" + rowData + "" }); } function previewTradeAbstractV2(abstractText, msg) { eModal.alert({ title: "行权摘要", message: '
' + abstractText + '', buttons: [{ text: '保存', click() { var dateTemp = new Date().Format("yyyyMMddhhmmss"); var exKey = "Trade_" + "行权" + "_" + dateTemp; downCsv(exKey, abstractText, ".txt"); main.message("导出成功", 50); closetrade_cashWindow(); } }, { text: '关闭', close: true, click: closetrade_cashWindow, style: 'secondary' },] }); } function getValidVal(val, defaultVal) { return val || defaultVal || ""; } function getUnwindNotion(obj) { var amountUnit = obj.QuoteUnitSingle; var splitIndex = obj.QuoteUnit.indexOf("/"); var unit = obj.QuoteUnit.substr(splitIndex + 1); if (unit === "500千克") { amountUnit = "半吨"; } return obj.UnderlyingInstrumentType === "Stock" ? otcformat.trading.notional(obj.UnWindNotional) + " 股" : otcformat.trading.notional(obj.UnWindNotional) + " " + amountUnit; } function getRowText(data, rowModel, template) { var rowText = ""; for (var i = 0; i < data.length; i++) { var val = getValidVal(data[i].value, rowModel); if (typeof data[i].visible === "boolean" && !data[i].visible) { continue; } else if (typeof data[i].visible === "function" && !data[i].visible(val, rowModel)) { continue; } if (data[i].func && typeof data[i].func === "function") { val = data[i].func(val, rowModel); } rowText += template.template(data[i].name, val); } return rowText; } function downCsv(fileName, exStrr, fileExtension) { //针对换行符和空格符转换 exStrr = exStrr.replace(/                 /g, " ").replace(/                /g, " ").replace(/权  利  金/g, "权 利 金").replace(/