327 lines
18 KiB
JavaScript
327 lines
18 KiB
JavaScript
//otcformat禁止千分位分组
|
|
window.otcformat.options.disableGrouping = true;
|
|
|
|
const inputFormatSwapRate = Object.freeze({ precision: otcformat.trading.premiumRateP.precision, append: '%' });
|
|
const inputFormatTradePrice = Object.freeze({ precision: otcformat.trading.tradePrice.precision, append: '' });
|
|
const inputFormatTradeAmount = Object.freeze({ precision: otcformat.trading.notional.precision, append: '' });
|
|
const inputFormatEqvNotional = Object.freeze({ precision: otcformat.trading.StockEqvNotional.precision, append: '', negative: true });
|
|
const inputFormatDividend = Object.freeze({ precision: 2, append: '', negative: true });
|
|
const inputFormatMarginRate = Object.freeze({ precision: otcformat.trading.marginRateP.precision, append: '%' });
|
|
const inputFormatMarginRateNoPercent = Object.freeze({ precision: otcformat.trading.umpriceP.precision, append: '', percent: true });
|
|
let ValueDate = model.ValueDate;
|
|
const vue = new Vue({
|
|
el: '#vueDiv',
|
|
data: {
|
|
deal: model,
|
|
floatPosition: null,
|
|
interestList: [],
|
|
marginList: [],
|
|
multiplier: 1,
|
|
initPosiNetPrice: 0
|
|
},
|
|
computed: {
|
|
maxUnwindDate() {
|
|
return ValueDate;
|
|
},
|
|
minStartDate() {
|
|
return this.deal.StartDate;
|
|
}
|
|
},
|
|
created() {
|
|
this.multiplier = this.deal.StructureType == '普通债券类收益互换' ? 100 : 1;
|
|
this.initDeal();
|
|
this.setValueDate();
|
|
},
|
|
methods: {
|
|
getPriceScale() {
|
|
return this.multiplier == 100 ? 0.01 : 1;
|
|
},
|
|
initDeal() {
|
|
var positions = model.FlowEvents.filter((item) => {
|
|
return item.UnderlyingCode;
|
|
});
|
|
this.floatPosition = positions[0];
|
|
this.initPosiNetPrice = this.floatPosition.PosiNetPrice;
|
|
// 互换标的价格固定为期初净价,与平仓不同不需要用户填写
|
|
// 期初净价入库为相对价(如1.02),需转换为界面百分比形态(102),与平仓页保持一致
|
|
this.floatPosition.TradingAmountAvg = this.initPosiNetPrice * this.multiplier;
|
|
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;
|
|
});
|
|
this.TradeStartDate = model.TradeStartDate;
|
|
},
|
|
IsBond(instType) {
|
|
return tradeHelper.IsBond(instType);
|
|
},
|
|
priceFormat(price) {
|
|
price = price * this.multiplier;
|
|
var pricef = otcformat.trading.umprice(price);
|
|
return pricef;
|
|
},
|
|
dataFormat() {
|
|
this.deal.NotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.NotionalValue));
|
|
this.deal.PosiNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.PosiNotionalValue));
|
|
this.deal.NotionalQty = otcformat.trading.notional(this.deal.NotionalQty);
|
|
this.deal.PositionQty2 = otcformat.trading.notional(this.deal.PositionQty);
|
|
this.floatPosition.Quantity = otcformat.trading.notional(this.floatPosition.Quantity);
|
|
this.floatPosition.PositionQty = otcformat.trading.notional(this.floatPosition.PositionQty);
|
|
this.deal.SwapCloseAmount = otcformat.trading.StockEqvNotional(this.deal.SwapCloseAmount);
|
|
//this.floatPosition.PosiNetPrice = otcformat.trading.umprice(this.floatPosition.PosiNetPrice);
|
|
//this.floatPosition.PosiGrossPrice = otcformat.trading.umprice(this.floatPosition.PosiGrossPrice);
|
|
this.floatPosition.TradingFee = otcformat.trading.StockEqvNotional(this.floatPosition.TradingFee);
|
|
this.floatPosition.DividendIn = parseFloat(this.floatPosition.DividendIn).toFixed(2);
|
|
this.floatPosition.MarkClosePnl = otcformat.trading.StockEqvNotional(this.floatPosition.MarkClosePnl);
|
|
this.interestList.forEach(x => {
|
|
//x.Principal = otcformat.trading.StockEqvNotional(x.Principal);
|
|
//x.Rate = otcformat.fixed6(x.Rate);
|
|
x.InterestFee = otcformat.trading.StockEqvNotional(x.InterestFee);
|
|
x.InterestAmount = otcformat.trading.StockEqvNotional(x.InterestAmount);
|
|
x.InterestClosePnL = otcformat.trading.StockEqvNotional(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 = otcformat.trading.StockEqvNotional(x.InterestFee);
|
|
x.InterestAmount = otcformat.trading.StockEqvNotional(x.InterestAmount);
|
|
x.InterestClosePnL = otcformat.trading.StockEqvNotional(x.InterestClosePnL);
|
|
});
|
|
},
|
|
setValueDate(e) {//修改平仓日期
|
|
if (e) {
|
|
this.deal.ValueDate = e;
|
|
this.deal.UnwindDate = e;
|
|
this.floatPosition.UnwindDate = e;
|
|
}
|
|
if (!isUseApproval) {
|
|
this.getInterestList();
|
|
} else {
|
|
this.dataFormat();
|
|
}
|
|
},
|
|
changeUnderlyingPrice() {//修改标的价格
|
|
this.calcFloatClosePnl();
|
|
},
|
|
refreshUnderlyingPrice() {//刷新标的价格
|
|
var thisObj = this;
|
|
main.post("/underlying_manager/GetUnderlyingPriceByCode",
|
|
{ code: thisObj.floatPosition.UnderlyingCode, valuedate: thisObj.deal.ValueDate })
|
|
.done(function (res) {
|
|
res.obj = res.obj * thisObj.multiplier;
|
|
thisObj.floatPosition.TradingAmountAvg = otcformat.trading.tradeSinglePrice(res.obj);
|
|
thisObj.calcFloatClosePnl();
|
|
});
|
|
},
|
|
changeTradingFee() {//修改交易费用
|
|
this.calcFloatClosePnl();
|
|
},
|
|
changeInterestAmount(item) {//修改利息金额
|
|
let InterestFee = item.InterestFee == "" ? 0 : parseFloat(item.InterestFee);
|
|
let interestRatio = item.InterestDirection == 1 ? 1 : -1;
|
|
item.InterestClosePnL = otcformat.trading.StockEqvNotional(parseFloat(item.InterestAmount) * interestRatio + InterestFee * interestRatio);
|
|
this.calcCloseAmount();
|
|
},
|
|
calcFloatClosePnl() {//计算浮动端平仓盈亏
|
|
var thisObj = this;
|
|
let floatRatio = thisObj.floatPosition.PayDirection == 1 ? 1 : -1;
|
|
let TradingFee = thisObj.floatPosition.TradingFee == "" ? 0 : parseFloat(thisObj.floatPosition.TradingFee);
|
|
let TradingFeePending = thisObj.floatPosition.TradingFeePending == "" ? 0 : parseFloat(thisObj.floatPosition.TradingFeePending);
|
|
let DividendIn = thisObj.floatPosition.DividendIn == "" ? 0 : parseFloat(thisObj.floatPosition.DividendIn ?? 0);
|
|
let scale = thisObj.getPriceScale();
|
|
thisObj.floatPosition.MarkClosePnl = thisObj.deal.CloseNotionalValue * (thisObj.floatPosition.TradingAmountAvg * scale - thisObj.initPosiNetPrice) * floatRatio;
|
|
thisObj.floatPosition.MarkClosePnl = thisObj.floatPosition.MarkClosePnl + TradingFee + TradingFeePending;//当日盯市不要计算分红
|
|
thisObj.floatPosition.MarkClosePnl = otcformat.trading.StockEqvNotional(thisObj.floatPosition.MarkClosePnl);
|
|
thisObj.calcCloseAmount();
|
|
},
|
|
//calcClosePnL() {//计算浮动端平仓盈亏
|
|
// let pnl = parseFloat(this.floatPosition.ClosePnL) - parseFloat(this.floatPosition.TradingFee);
|
|
// this.floatPosition.ClosePnL = otcformat.trading.StockEqvNotional(pnl);
|
|
// this.calcCloseAmount();
|
|
//},
|
|
calcCloseAmount() {//计算平仓总额=浮动收取+利息收取-浮动支付-利息支付
|
|
var floatRatio = this.floatPosition.PayDirection == 1 ? 1 : -1;
|
|
var thisObj = this;
|
|
let pnl = parseFloat(this.floatPosition.MarkClosePnl);
|
|
let TradingFee = thisObj.floatPosition.TradingFee == "" ? 0 : parseFloat(thisObj.floatPosition.TradingFee);
|
|
thisObj.deal.SwapCloseAmount = pnl;
|
|
thisObj.deal.SwapRealizedPnL = pnl;
|
|
thisObj.deal.SwapMarginRebatePnl = 0;
|
|
thisObj.deal.SwapMarginAmount = 0;
|
|
let scale = thisObj.getPriceScale();
|
|
thisObj.floatPosition.TradingAmount = parseFloat(thisObj.floatPosition.TradingAmountAvg) * parseFloat(thisObj.deal.CloseNotionalValue) * scale;
|
|
thisObj.floatPosition.CloseFee = TradingFee;
|
|
if (thisObj.deal.CloseQty > 0) {
|
|
thisObj.floatPosition.TradingAmountFeeAvg = parseFloat(thisObj.floatPosition.TradingAmountAvg) * scale + (TradingFee / thisObj.deal.CloseQty) * floatRatio;
|
|
} else {
|
|
thisObj.floatPosition.TradingAmountFeeAvg = parseFloat(thisObj.floatPosition.TradingAmountAvg) * scale;
|
|
}
|
|
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.SwapCloseAmount = otcformat.trading.StockEqvNotional(thisObj.deal.SwapCloseAmount);
|
|
thisObj.deal.SwapRealizedPnL = otcformat.trading.StockEqvNotional(thisObj.deal.SwapRealizedPnL);
|
|
thisObj.deal.SwapMarginRebatePnl = otcformat.trading.StockEqvNotional(thisObj.deal.SwapMarginRebatePnl);
|
|
},
|
|
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();
|
|
thisObj.getDivindIn();
|
|
});
|
|
},
|
|
getDivindIn() {
|
|
var thisObj = this;
|
|
let ratio = this.floatPosition.PositionType == 1 ? 1 : -1;
|
|
let floatRatio = this.floatPosition.PayDirection == 1 ? 1 : -1;
|
|
var postData = { startDate: thisObj.TradeStartDate, endDate: thisObj.deal.UnwindDate, underlyingCode: thisObj.floatPosition.UnderlyingCode, tradeId: thisObj.deal.SwapTradeId, unwindDate: thisObj.deal.UnwindDate }
|
|
main.post("/BondPayment/GetBondPayMentInterest", postData, { async: false }).done(function (resp) {
|
|
let totalDividend = parseFloat(thisObj.deal.PositionQty) * resp.obj.totalInterest * ratio * floatRatio;
|
|
let consumedDividend = Math.abs(parseFloat(resp.obj.consumedDividend ?? 0));
|
|
// 互换是全量消费,consumedDividend>0 表示分红已被当天互换消费,归0
|
|
thisObj.floatPosition.DividendIn = Math.abs(consumedDividend) > 0 ? parseFloat((totalDividend - consumedDividend).toFixed(2)) : parseFloat(totalDividend.toFixed(2));
|
|
thisObj.floatPosition.DividendPending = 0;
|
|
thisObj.calcFloatClosePnl();
|
|
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);
|
|
})
|
|
thisObj.floatPosition.EventDate = thisObj.deal.ValueDate;
|
|
let floatPosition = _.cloneDeep(thisObj.floatPosition);
|
|
floatPosition.Quantity = 0;
|
|
floatPosition.TradingAmountAvg = floatPosition.TradingAmountAvg * thisObj.getPriceScale();
|
|
reqObj.FlowEvents.push(floatPosition);
|
|
var postData = { unwindData: reqObj };
|
|
var msg = "确认提交收益结算?";
|
|
var postUrl = "/swaptrade2/SwapIncomeJson";
|
|
if (g_isShowReCheckClose) {
|
|
msg = "确认提交收益结算审核?";
|
|
postUrl = "/swaptrade2/ApplyUnwind";
|
|
postData.eventType = 3;//互换3,平仓2
|
|
}
|
|
main.confirm(msg,
|
|
function () {
|
|
//重新计算百分比
|
|
var thisObj2 = thisObj;
|
|
main.post(postUrl, postData).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 = "确认拒绝?";
|
|
}
|
|
let thisObj = this;
|
|
var confirmFunc = function (additionalProcessing) {
|
|
var pData = { tradeId: thisObj.deal.SwapTradeId, 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 = `<div style="padding:10px">${data.obj.message}</div>`;
|
|
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) {
|
|
thisObj2.closetrade_cashWindow();
|
|
}
|
|
(parent || window).layer.closeAll();
|
|
}
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
(parent || window).main.message(data.msg);
|
|
try { thisObj2.closetrade_cashWindow(); }
|
|
catch (e) { }
|
|
if (parent) {
|
|
parent.layer.closeAll();
|
|
}
|
|
});
|
|
}
|
|
main.confirm(pop, confirmFunc);
|
|
},
|
|
closetrade_cashWindow: function () {
|
|
layer.closeMe('reloadData');
|
|
},
|
|
closeCurrentWindow: function () {
|
|
try {
|
|
if (window.parent && window.parent.reload) window.parent.reload();
|
|
} catch (e) {
|
|
}
|
|
try {
|
|
var layer = window.parent.layer;
|
|
layer.close(layer.getFrameIndex(window.name));
|
|
} catch (e) {
|
|
}
|
|
}
|
|
},
|
|
components: {
|
|
'vue-datepicker': FastVue.vueDatePicker(),
|
|
'vue-number-input': FastVue.vueNumberInput(),
|
|
}
|
|
});
|
|
|
|
$(function () {
|
|
$("#baseTable").width($("#floatTable").width());
|
|
});
|