//otcformat禁止千分位分组 window.otcformat.options.disableGrouping = true; var vue = new Vue({ el: "#vueDiv", data: { tradeCash: model, tradeForward: otcTradeForward, variety: variety, singleOptionValueResult: null, UnwindFee: 0, ForwardProfit: 0, AmountCheck: 0, UnwindPriceCheck: 0, tradeDate: tradeDate, exerciseDate: exerciseDate }, mounted: function () { }, watch: { 'tradeCash.UnwindPrice': function (val) { var valueArray = String(val).split("."); if (valueArray.length > 1 && valueArray[1].length > 2) { this.tradeCash.UnwindPrice = otcformat.trading.tradePrice(val); } }, 'tradeCash.UnwindType': function () { var thisObj = this; if (thisObj.tradeCash.UnwindType === "全部平仓") { thisObj.tradeCash.UnwindTradeAmount = this.tradeCash.TradeAmount; thisObj.changeUnwindTradeAmount(); } } }, methods: { setUnwindDate: function (e) { this.tradeCash.ValueDate = e; this.refreshUnderlyingPrice(); }, changeUnderlyingPrice: function () { this.tradeCash.FinalPriceType = "User"; this.computeForwardProfit(); }, refreshUnderlyingPrice: function () { var thisObj = this; main.post("/underlying_manager/TryGetTradeForwardFinalPrice", { tradeId: thisObj.tradeCash.TradeId, underlyingId: thisObj.tradeCash.UnderlyingId, voltype: "交易", tradeDate: thisObj.tradeCash.ValueDate }) .done(function (res) { thisObj.tradeCash.FinalPrice = otcformat.trading.umprice(res.obj.Price); thisObj.tradeCash.FinalPriceType = "System"; thisObj.computeForwardProfit(); if (res.message && res.message != "") { main.message(res.message); } }); }, changeUnwindTradeAmount: function () { if (parseFloat(this.tradeCash.UnwindTradeAmount) > parseFloat(this.tradeCash.TradeAmount)) { main.message("平仓数量不能超过持仓数量"); this.tradeCash.UnwindTradeAmount = ""; } this.computeForwardProfit(); this.computeExtraAmount(); }, //计算预付金成本 computeExtraAmount: function () { var thisObj = this; var unwindAmount = thisObj.tradeCash.UnwindTradeAmount; var holidayMarginTotal = unwindAmount * holidayMargin; var lastMargin = (lastMarginRecord.MarginSum - lastMarginRecord.CloseMarginSum) * ((unwindAmount) / lastMarginRecord.Notional) + lastMarginRecord.CloseMarginSum; thisObj.tradeCash.ExtraAmount = otcformat.trading.notional(lastMargin + holidayMarginTotal, 2); }, //计算平仓总费用 //平仓的总费用 =远期收益+每手平仓费用×平仓手数+补充远期价值×平仓比例+预付金成本 computeUnwindTotalFee: function () { var thisObj = this; var tradeCash = thisObj.tradeCash; var tradeForward = this.tradeForward; if (g_isReCheckConfirm && !g_isUseApproval) { tradeCash.UnwindPrice = thisObj.UnwindPriceCheck; } thisObj.computeExtraAmount(); var unwindRatio = tradeCash.UnwindTradeAmount / tradeCash.TradeOriginalAmount; var unwindPrice = parseFloat(tradeCash.UnwindPrice == "" ? 0 : tradeCash.UnwindPrice) * tradeForward.Lots * unwindRatio; var supplyPrice = tradeForward.MetaDic["IsSupplyForwardValue"] == "1" ? tradeForward.ForwardValue : tradeForward.MetaDic["IsSupplyForwardValue"] == "-1" ? -tradeForward.ForwardValue : 0; var unwindTotalFee = Number(thisObj.ForwardProfit) + unwindPrice - (supplyPrice * unwindRatio) + Number(thisObj.tradeCash.ExtraAmount); thisObj.UnwindFee = otcformat.trading.tradePrice(unwindTotalFee); thisObj.AmountCheck = thisObj.UnwindFee; }, //计算平仓费用 //平仓费用 = (补充远期价值* 平仓比例)- 平仓远期价值 )/ (平仓比例 *手数) computeUnwindPrice: function () { var thisObj = this; var tradeCash = thisObj.tradeCash; var tradeForward = this.tradeForward; thisObj.computeExtraAmount(); thisObj.computeForwardPrice(); //复核页面 平仓总费用 if (g_isReCheckConfirm) { thisObj.UnwindFee = thisObj.AmountCheck; } var unwindRatio = tradeCash.UnwindTradeAmount / tradeCash.TradeOriginalAmount; var supplyPrice = tradeForward.MetaDic["IsSupplyForwardValue"] == "1" ? tradeForward.ForwardValue : tradeForward.MetaDic["IsSupplyForwardValue"] == "-1" ? -tradeForward.ForwardValue : 0; var unwindPrice = (parseFloat(thisObj.UnwindFee) + (supplyPrice * unwindRatio) - Number(thisObj.ForwardProfit)) / (unwindRatio * tradeForward.Lots); thisObj.tradeCash.UnwindPrice = otcformat.trading.tradePrice(unwindPrice); thisObj.UnwindPriceCheck = thisObj.tradeCash.UnwindPrice; }, //计算远期价值 //(交割价格-平仓价格)*成交数量 * CountRatio*(多-1,空1)*(买入1,卖出-1) //这里的交易方向为开仓时的交易方向 computeForwardPrice: function () { var thisObj = this; var tradeForward = this.tradeForward; thisObj.tradeCash.FinalPrice = otcformat.trading.umprice(thisObj.tradeCash.FinalPrice); var strikePrice = parseFloat(thisObj.tradeCash.Strike); var underlringPrice = parseFloat(thisObj.tradeCash.FinalPrice); var tradeAmount = parseFloat(thisObj.tradeCash.UnwindTradeAmount); thisObj.ForwardProfit = otcformat.trading.umprice((strikePrice - underlringPrice) * tradeAmount * thisObj.variety.CountRatio * (thisObj.tradeCash.CallPutDesc == "看涨" ? -1 : 1) * (tradeForward.BuySell == "买入" ? 1 : -1)); }, computeForwardProfit: function () { var thisObj = this; thisObj.computeForwardPrice(); if (!g_isUseApproval) { thisObj.computeUnwindTotalFee(); } else { this.UnwindFee = this.tradeCash.Amount; } }, getSumbitText: function () { return g_isShowReCheckClose ? "平仓审核提交" : "平仓"; }, previewTradeAbstract: function (tradeCash, trade) { var textContent = ""; var htmlContent = ""; var thisObj = this; var rowData = [ { name: "交易编号", value: trade.TradeNumber, func: function (colVal, rowModel) { return main.isEmpty(rowModel.TradeNumber) ? "" : colVal; } }, { name: "开仓日期", value: trade.TradeDate, func: function (colVal) { return colVal.substring(0, 10); } }, { name: "开仓方向", value: this.getValidVal(trade.ClientName) + "
                " + (this.getValidVal(trade.BuySell) === "买入" ? " 卖出" : " 买入") }, { name: "结构类型", value: this.getValidVal(trade.ExerciseModeCn) + this.getValidVal(trade.TradeType).replace("期权", "") + this.getValidVal(trade.OptionType) + "期权", func: function (colVal, rowModel) { if (rowModel.TradeType == "远期") { return trade.TradeType + (trade.OptionType == "看涨" ? "多头" : "空头"); } return colVal; } }, { name: "标的代码", value: trade.UnderlyingCode, func: function (colVal, rowModel) { if (rowModel.TradeType == "合成价差期权") { return rowModel.SyntheticUnderlyingTipsInfo; } return colVal; } }, { name: "执行价格", value: this.getValidVal(trade.Strike, 0), func: function (colVal, rowModel) { if (rowModel.IsMoneynessOption == "是") { return otcformat.trading.premiumRateP(colVal); } return otcformat.trading.tradePrice(colVal); } }, { name: "到期日期", value: trade.ExerciseDate, func: function (colVal) { return colVal.substring(0, 10); } }, { name: "平仓日期", value: tradeCash.ValueDate }, { name: "标的价格", value: main.toNumberExcludingNaN(trade.SpotPrice), func: function (colVal, rowModel) { if (rowModel.UnderlyingInstrumentType == "CommodityFutures") { return colVal + "(开仓)" + "
                " + otcformat.trading.umprice(tradeCash.FinalPrice) + "(平仓)"; } return otcformat.trading.umprice(trade.InitialSpotPrice) + "(开仓)" + "
                " + otcformat.trading.umprice(tradeCash.FinalPrice) + "(平仓)"; } }, { name: "平仓数量", value: trade.UnderlyingInstrumentType == "Stock" ? tradeCash.UnwindNotional + " 股" : tradeCash.UnwindTradeAmount + " " + this.getValidVal(trade.QuoteUnitSingle) }, { name: "平仓总额", value: otcformat.trading.tradePrice(thisObj.UnwindFee * (-1), 3) + " 元" //客户角度,故为相反金额 }, { name: "实现盈亏", value: otcformat.trading.tradePrice((trade.BuySell === "卖出" ? 1 : -1) * (tradeCash.Amount - tradeCash.UnwindNotional * trade.TradeSinglePrice)) + " 元", func: function (colVal, rowModel) { var notional = (tradeCash.UnwindNotional); var amount = thisObj.UnwindFee; return otcformat.trading.tradePrice((-1) * amount - (trade.BuySell === "卖出" ? 1 : -1) * (trade.TradePrice) * (notional / trade.OriginalNotional)) + " 元"; } } ]; textContent += this.getRowText(rowData, trade, '{0}:{1}\r\n') + "\r\n\r\n"; htmlContent += this.getRowText(rowData, trade, '{0}:{1}
') + "

"; layer.open({ type: 1, title: "平仓摘要", shadeClose: false, btn: ['保存', '关闭'], yes: function (index, layero) { var dateTemp = new Date().Format("yyyyMMddhhmmss"); var exKey = "Trade_" + "平仓" + "_" + dateTemp; thisObj.downCsv(exKey, textContent, ".txt"); main.message("导出成功", 50); thisObj.closeLayer(); }, cancel: function (index, layero) { thisObj.closeLayer(); }, shade: 0.4, area: ['380px', '400px'], content: "
" + htmlContent + "
" }); }, previewTradeAbstractV2(abstractText) { var thisObj = this; eModal.alert({ title: "平仓摘要", message: '
' + abstractText + '
', buttons: [{ text: '保存', click() { var dateTemp = new Date().Format("yyyyMMddhhmmss"); var exKey = "Trade_" + "平仓" + "_" + dateTemp; thisObj.downCsv(exKey, abstractText, ".txt"); main.message("导出成功", 50); thisObj.closeLayer(); } }, { text: '关闭', style: 'secondary', close: true, click: thisObj.closeLayer }], onHide: thisObj.closeLayer }); }, getValidVal: function (val, defaultVal) { if (val == null || val === "undefined") { return defaultVal || ""; } return val; }, getRowText: function (data, rowModel, template) { var rowText = ""; for (var i = 0; i < data.length; i++) { var val = this.getValidVal(data[i].value, rowModel); if (data[i].visible != undefined && data[i].visible != null) { if (typeof data[i].visible == "boolean" && !data[i].visible) { continue; } if (typeof data[i].visible == "function" && !data[i].visible(val, rowModel)) { continue; } } if (val !== "" && data[i].func && typeof data[i].func == "function") { val = data[i].func(val, rowModel); } rowText += template.template(data[i].name, val); } return rowText; }, downCsv: function (fileName, exStrr, fileExtension) { //针对换行符和空格符转换 exStrr = exStrr.replace(/                 /g, " ").replace(/                /g, " ").replace(/权  利  金/g, "权 利 金").replace(//g, "\r\n"); //exStrr = exStrr.replace(/             /g," "); if (!fileExtension) { fileExtension = ".csv"; } var isIE = (navigator.userAgent.indexOf('MSIE') >= 0); if (isIE) { var strHTML = exStrr; var winSave = window.open(); winSave.document.open("text", "utf-8"); winSave.document.write(strHTML); winSave.document.execCommand("SaveAs", true, fileName + fileExtension); winSave.close(); } else { var mimeType = 'text/plain'; $('#createInvote').attr('download', fileName + fileExtension); //\uFEFF bom $('#createInvote').attr('href', 'data:' + mimeType + ';charset=utf-8,\uFEFF' + encodeURIComponent(exStrr)); document.getElementById('createInvote').click(); } }, submit: function () { var thisObj = this; if (main.isEmpty(thisObj.tradeCash.ValueDate)) { main.message("请输入平仓日期"); return; } if (thisObj.tradeCash.ValueDate > thisObj.exerciseDate || thisObj.tradeCash.ValueDate < thisObj.tradeDate) { main.message("平仓日期不能小于成交日期,并且不能大于到期日期"); return; } if (thisObj.tradeCash.ValueDate > systemValueDate) { main.message("平仓日期不能大于系统日期"); return; } if (main.isEmpty(thisObj.tradeCash.FinalPrice)) { main.message("请输入标的价格"); return; } if (main.isEmpty(thisObj.ForwardProfit)) { main.message("请输入远期收益"); return; } if (main.isEmpty(thisObj.UnwindFee)) { main.message("请输入平仓总费用"); return; } if (main.isEmpty(thisObj.tradeCash.UnwindTradeAmount) || parseFloat(thisObj.tradeCash.UnwindTradeAmount) == 0) { main.message("请输入平仓数量"); return; } //计算一下平仓份额和平仓总额 if (thisObj.tradeCash.UnwindType == "全部平仓") { thisObj.tradeCash.UnwindTradeAmount = thisObj.tradeCash.TradeAmount } thisObj.tradeCash.UnwindNotional = thisObj.tradeCash.UnwindTradeAmount * (thisObj.variety.CountRatio || 1); thisObj.tradeCash.Amount = thisObj.UnwindFee;// thisObj.tradeCash.UnwindNotional * thisObj.tradeCash.UnwindPrice; thisObj.tradeCash.Notional = thisObj.tradeCash.TradeAmount * (thisObj.variety.CountRatio || 1); thisObj.tradeCash.UnwindFee = thisObj.UnwindFee; thisObj.tradeCash.QuoteUnwindFee = thisObj.UnwindFee; thisObj.tradeCash.TradePrice = thisObj.tradeCash.FinalPrice; thisObj.tradeCash.VolType = "交易"; let _Version = 'V2'; if (g_isShowReCheckClose) { main.confirm("确认提交平仓审核?", function () { var postData = jQuery.extend(true, {}, thisObj.tradeCash); main.post("/trade_cash/CloseReCheck?_Version=" + _Version, postData).done(function (res) { _Version === 'V2' ? thisObj.previewTradeAbstractV2(res.obj) : thisObj.previewTradeAbstract(postData, res.obj); }); }); } else { main.confirm("确认提交平仓?", function () { var postData = jQuery.extend(true, {}, thisObj.tradeCash); main.post("/trade_cash/UnwindTradeJson?_Version=" + _Version, postData).done(function (res) { _Version === 'V2' ? thisObj.previewTradeAbstractV2(res.obj) : thisObj.previewTradeAbstract(postData, res.obj); }); }); } }, review: function () { var thisObj = this; main.confirm("确认复核平仓?", function () { thisObj.tradeCash.AmountCheck = thisObj.AmountCheck; thisObj.tradeCash.UnwindPriceCheck = thisObj.UnwindPriceCheck; var postData = jQuery.extend(true, {}, thisObj.tradeCash); main.post("/trade_cash/UnwindTradeJson", postData).done(function (res) { (parent || window).layer.closeAll(); }); }); }, reject: function () { var thisObj = this; main.confirm("确认拒绝平仓?", function () { var postData = jQuery.extend(true, {}, thisObj.tradeCash); main.post("/trade_cash/DenyReCheck", postData).done(function (res) { thisObj.closeLayer(); }); }); }, doubleFormat: function (tradeCash) { tradeCash.TradeAmount = otcformat.trading.notional(tradeCash.TradeAmount); // tradeCash.UnwindTradeAmount = otcformat.trading.notional(tradeCash.UnwindTradeAmount); return tradeCash; }, closeLayer(isCancel) { layer.closeMe(isCancel === true ? '' : 'reload'); }, //交易审批 submitApproval(status) { var pop = ''; if (status === 'pass') { pop = "确认通过审批?"; } if (status === 'reject') { pop = "确认拒绝?"; } var confirmFunc = function (additionalProcessing) { var pData = { tradeId: model.TradeId, status: status, text: "" }; if (!main.isEmpty(additionalProcessing)) { pData.additionalProcessing = additionalProcessing; } main.post("/processtradelog/UpdateTradeProcessLog", pData).done( function (data) { if (data.obj && data.obj.proccessType == "AdditionalProcessing") { if (data.obj.type == "LackOfMoney") { var htmlContent = `
${data.obj.message}
`; var lackMoneyConfirmLayer = main.open2("提示", htmlContent, { area: ["430px", "175px"], btn: ['交易特批', '取消'], yes: function (index, layero) { var layerIndex = lackMoneyConfirmLayer; main.confirm("客户资金或授信不足,强制成交会导致本机构产生风险!要继续审批通过?", function () { layer.close(layerIndex); confirmFunc("LackOfMoney"); }); }, cancel: function (index, layero) { if (window.parent && window.parent.reloadtrade) { window.parent.reloadtrade(); } (parent || window).layer.closeAll(); } }); console.log("lackMoneyConfirmLayer:" + lackMoneyConfirmLayer); } return; } (parent || window).main.message(data.msg); try { window.parent.reloadtrade(); } catch (e) { } if (parent) { parent.layer.closeAll(); } }); } main.confirm(pop, confirmFunc); }, } , created() { this.computeForwardProfit(); this.computeExtraAmount(); if (!g_isUseApproval) { this.refreshUnderlyingPrice(); } }, });