//otcformat禁止千分位分组 window.otcformat.options.disableGrouping = true; const inputFormatEqvNotional = swapPricePrecision.getCommonInputFormat('amount', { append: '' }); const swapInstrumentType = (model.FlowEvents || []).find(item => item && item.UnderlyingInstrumentType)?.UnderlyingInstrumentType || model.UnderlyingInstrumentType || ''; const formatSwapAmount = value => swapPricePrecision.normalizeCommon('amount', value); const formatSwapQuantity = value => swapPricePrecision.normalizeCommon('quantity', value, swapInstrumentType); let ValueDate = model.ValueDate; const vue = new Vue({ el: '#vueDiv', data: { deal: model, interestList: [], marginList: [], }, computed: { maxUnwindDate() { return ValueDate; }, minStartDate() { return this.deal.StartDate; } }, created() { this.initDeal(); this.setValueDate(); }, methods: { formatAmount(value) { return swapPricePrecision.formatCommon('amount', value); }, formatQuantity(value) { return swapPricePrecision.formatCommon('quantity', value, swapInstrumentType); }, initDeal() { this.interestList = model.FlowEvents.filter((item) => { return item.InterestMode == 1 || item.InterestMode == 2 || item.InterestMode == 7 || item.InterestMode == 8 || item.InterestMode == 9; }); this.marginList = model.FlowEvents.filter((item) => { return item.InterestMode == 5 || item.InterestMode == 6; }); }, setValueDate(e) {//修改平仓日期 if (e) { this.deal.ValueDate = e; this.deal.UnwindDate = e; } if (!isUseApproval) { this.getInterestList(); } else { this.dataFormat(); } }, dataFormat() { this.deal.NotionalValue = formatSwapAmount(this.deal.NotionalValue); this.deal.PosiNotionalValue = formatSwapAmount(this.deal.PosiNotionalValue); this.deal.NotionalQty = formatSwapQuantity(this.deal.NotionalQty); this.deal.PositionQty = formatSwapQuantity(this.deal.PositionQty); this.deal.SwapCloseAmount = formatSwapAmount(this.deal.SwapCloseAmount); this.interestList.forEach(x => { //x.Principal = formatSwapAmount(x.Principal); //x.Rate = otcformat.fixed6(x.Rate); x.InterestFee = formatSwapAmount(x.InterestFee); x.InterestAmount = formatSwapAmount(x.InterestAmount); x.InterestClosePnL = formatSwapAmount(x.InterestClosePnL); //x.InterestStartDate = x.InterestStartDate ? x.InterestStartDate.substr(0, 10) : ""; //x.InterestEndDate = x.InterestEndDate ? x.InterestEndDate.substr(0, 10) : ""; }); this.marginList.forEach(x => { x.InterestFee = formatSwapAmount(x.InterestFee); x.InterestAmount = formatSwapAmount(x.InterestAmount); x.InterestClosePnL = formatSwapAmount(x.InterestClosePnL); }); }, changeInterestAmount(item) {//修改利息金额 let interestRatio = item.InterestDirection == 1 ? 1 : -1; item.InterestClosePnL = formatSwapAmount(parseFloat(item.InterestAmount) * interestRatio + parseFloat(item.InterestFee)); this.calcCloseAmount(); }, calcCloseAmount() {//计算平仓总额=浮动收取+利息收取-浮动支付-利息支付 let thisObj = this; thisObj.deal.SwapCloseAmount = 0; thisObj.deal.SwapRealizedPnL = 0; thisObj.deal.SwapMarginRebatePnl = 0; thisObj.deal.SwapMarginAmount = 0; this.interestList.forEach(x => { /*let interestRatio = x.InterestDirection == 1 ? 1 : -1;*/ let interestAmount = parseFloat(x.InterestClosePnL); thisObj.deal.SwapCloseAmount = parseFloat(thisObj.deal.SwapCloseAmount) + interestAmount; thisObj.deal.SwapRealizedPnL = parseFloat(thisObj.deal.SwapRealizedPnL) + interestAmount; }); this.marginList.forEach(x => { let interestAmount = parseFloat(x.InterestClosePnL); thisObj.deal.SwapCloseAmount = parseFloat(thisObj.deal.SwapCloseAmount) + interestAmount; thisObj.deal.SwapMarginRebatePnl = parseFloat(thisObj.deal.SwapMarginRebatePnl) + interestAmount; thisObj.deal.SwapRealizedPnL = parseFloat(thisObj.deal.SwapRealizedPnL) + interestAmount; thisObj.deal.SwapMarginAmount = parseFloat(thisObj.deal.SwapMarginAmount) + parseFloat(x.InterestPrincipal); }); thisObj.deal.SwapCloseAmount = formatSwapAmount(thisObj.deal.SwapCloseAmount); thisObj.deal.SwapRealizedPnL = formatSwapAmount(thisObj.deal.SwapRealizedPnL); thisObj.deal.SwapMarginRebatePnl = formatSwapAmount(thisObj.deal.SwapMarginRebatePnl); thisObj.deal.SwapMarginAmount = formatSwapAmount(thisObj.deal.SwapMarginAmount); }, getInterestList() {//根据平仓日期获取利息腿信息 var thisObj = this; var postData = { valueDate: thisObj.deal.ValueDate, unwindDate: thisObj.deal.UnwindDate, tradeId: thisObj.deal.SwapTradeId, closePercent: 1, eventType: 3 } main.post("/swaptrade2/GetUnwindInterestList", postData, { async: true }).done(function (resp) { thisObj.interestList = resp.obj.filter((item) => { return item.InterestMode == 1 || item.InterestMode == 2 || item.InterestMode == 7 || item.InterestMode == 8 || item.InterestMode == 9; }); thisObj.marginList = resp.obj.filter((item) => { return item.InterestMode == 5 || item.InterestMode == 6; }); thisObj.calcCloseAmount(); thisObj.dataFormat(); }); }, incomeTrade() {//互换 var thisObj = this; if (main.isEmpty(thisObj.deal.ValueDate)) { main.message("请输入平仓日期"); return; } let reqObj = _.cloneDeep(thisObj.deal); let marginCloneList = _.cloneDeep(thisObj.marginList); reqObj.FlowEvents = _.cloneDeep(thisObj.interestList); marginCloneList.forEach((item) => { reqObj.FlowEvents.push(item); }) var postData = { unwindData: reqObj }; var msg = "确认提交收益结算?"; var postUrl = "/swaptrade2/SwapLongShortJson"; if (g_isShowReCheckClose) { msg = "确认提交收益结算审核?"; postUrl = "/swaptrade2/ApplyUnwind"; postData.eventType = 3;//互换3,平仓2 } main.confirm(msg, function () { //重新计算百分比 var thisObj2 = thisObj; main.post(postUrl, { unwindData: reqObj }).done(function (res) { if (res.success) { thisObj2.closetrade_cashWindow(); } else { try { thisObj2.closetrade_cashWindow(); } catch (e) { } } }); }); }, getSumbitText: function () { return g_isShowReCheckClose ? "审核提交" : "保存"; }, submitApproval(status) { var pop = ''; if (status === 'pass') { pop = "确认通过审批?"; } if (status === 'reject') { pop = "确认拒绝?"; } var confirmFunc = function (additionalProcessing) { var pData = { tradeId: trade.id, status: status, text: "" }; if (!main.isEmpty(additionalProcessing)) { pData.additionalProcessing = additionalProcessing; } var thisObj2 = thisObj; main.post("/processtradelog/UpdateTradeProcessLog", pData).done( function (data) { if (data.obj && data.obj.proccessType == "AdditionalProcessing") { if (data.obj.type == "LackOfMoney") { var htmlContent = `