Files
zszq-trs/YLErpWeb/wwwroot/Scripts/app/trade/tradeUnwind.js
T
2024-05-09 14:06:26 +08:00

854 lines
54 KiB
JavaScript

//otcformat禁止千分位分组
window.otcformat.options.disableGrouping = true;
const premiumRateFormat = otcformat.trading.premiumRatePLeft;
const unwindPercentFormat = otcformat.fixed2;
const hasMinusValueOptions = ["凤凰期权", "雪球期权", "自定义交易", "累计期权"];
var vue = new Vue({
el: "#vueDiv",
data: {
trade: pageObj.trade,
tradeCash: model,
variety: pageObj.variety,
pairTrade: pageObj.pairTrade,
singleOptionValueResult: null,
IsPercentage: pageObj.trade.IsUsePremiumRate ? "是" : "否",
IsVolSurface: pageObj.IsTradeVol ? false : true,
IsGetVolSurface: pageObj.IsTradeVol ? false : true,
Midvol: 0, /*东证独有,从曲面取的Mid波动率*/
cashTip: "",
deltaTip: "",
//平仓单价和资金是否一致
UnwindpriceAndMoneyIsAgreement: pageObj.trade.BuySell == "买入" || pageObj.UnwindSinglePriceAngle == 1 || pageObj.trade.TradeType == "收益互换" ? 1 : -1,
//平仓总额和资金是否一致
UnwindAmountAndMoneyIsAgreement: pageObj.trade.BuySell == "买入" || pageObj.UnwindAmountAngle == 1 || pageObj.trade.TradeType == "收益互换" ? 1 : -1,
//平仓单价和期权价值方向是否一致
UnwindpriceAndSinglePVIsAgreement: pageObj.trade.BuySell == "买入" || pageObj.UnwindSinglePriceAngle == 0 || pageObj.trade.TradeType == "收益互换" ? 1 : -1,
//平仓单价和平仓总额方向是否一致
UnwindpriceAndamountIsAgreement: pageObj.trade.BuySell == "买入" || pageObj.UnwindSinglePriceAngle == pageObj.UnwindAmountAngle || pageObj.trade.TradeType == "收益互换" ? 1 : -1,
},
created: function () {
this.tradeCash.TradeAmount = otcformat.trading.notional(this.tradeCash.TradeAmount);
this.tradeCash.TradeOriginalAmount = otcformat.trading.notional(this.tradeCash.TradeOriginalAmount);
this.tradeCash.StockEqvNotional = otcformat.trading.StockEqvNotional(this.tradeCash.StockEqvNotional);
this.tradeCash.OriginalStockEqvNotional = otcformat.trading.StockEqvNotional(this.tradeCash.OriginalStockEqvNotional);
this.tradeCash.UnwindTradeAmount = otcformat.trading.notional(this.tradeCash.UnwindTradeAmount);
//复合时,防止影响比例精度,当名义本金成交方式用名义本金方式平仓时,UnwindPercentRate可能是无限小数
//UnwindPercentRateRecheck只用来复合时展示,后台逻辑还会保持UnwindPercentRate不变
this.tradeCash.UnwindPercentRateRecheck = unwindPercentFormat(this.tradeCash.UnwindPercentRate);
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.UnwindPercentRate);
this.tradeCash.UnwindStockEqvNotional = otcformat.trading.StockEqvNotional(this.tradeCash.UnwindStockEqvNotional);
this.tradeCash.FinalPrice = otcformat.trading.umprice(this.tradeCash.FinalPrice);
this.tradeCash.Strike = otcformat.trading.umprice(this.tradeCash.Strike);
this.tradeCash.InitialSpotPrice = otcformat.trading.umprice(this.tradeCash.InitialSpotPrice);
if (this.trade.TradeStatus !== "平仓待复核" && this.trade.TradeType === "现金流交易" && !g_isUseApproval) {
this.getCashflowUnwindPart();
}
if (g_isUseApproval) {
this.tradeCash.UnwindPricePercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRate);
this.tradeCash.UnwindPrice = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPrice);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.SinglePVPercentRate);
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.SinglePV);
}
if (pageObj.is东证) {
this.Midvol = this.tradeCash.UnwindVol;
}
if (pageObj.g_precisionOfMinuteInQuote) {
this.trade.TTMDays = parseFloat(numeral(this.trade.TTMDays).format("0.00000"));
} else {
this.trade.TTMDays = parseFloat(numeral(this.trade.TTMDays).format("0.0000"));
}
},
mounted: function () {
main.setTradeDatePicker(model.ValueDate, "#unwindDate", null, this.setUnwindDate);
$("#unwindDate").datepicker("option", "minDate", pageObj.tradeDate);
$("#unwindDate").datepicker("option", "maxDate", pageObj.systemValueDate);
$("#unwindDate").val(model.ValueDate);
//格式化小数位
$("#InitialSpotPrice,#Strike,#FinalPrice").change(function () {
this.value = otcformat.trading.umprice(this.value);
});
},
computed: {
RemainingStockEqvNotional: {
get: function () {
if (this.tradeCash.UnwindType == "全部平仓") {
this.tradeCash.UnwindTradeAmount = otcformat.trading.notional(this.tradeCash.TradeAmount);
}
if (main.isEmpty(this.tradeCash.UnwindTradeAmount) ||
main.isEmpty(this.tradeCash.InitialSpotPrice) ||
main.isEmpty(this.tradeCash.TradeAmount)) {
return "";
}
var remainingNotional = (this.tradeCash.TradeAmount - this.tradeCash.UnwindTradeAmount) *
(this.variety.CountRatio || 1);
return otcformat.trading.StockEqvNotional(this.tradeCash.InitialSpotPrice * remainingNotional);
}
},
DeltaInLots: {
get: function () {
if (main.isEmpty(this.singleOptionValueResult)) {
return "";
}
return otcformat.trading.notional(-this.singleOptionValueResult.DeltaInLots * this.tradeCash.UnwindNotional);
}
}
},
watch: {
"tradeCash.Amount": {
handler(newValue, oldValue) {
if (newValue < 0) {
this.cashTip = "我方支付" + Math.abs(newValue);
} else {
this.cashTip = "我方收取" + Math.abs(newValue);
}
},
immediate: true,
deep: true
},
"DeltaInLots": {
handler(newValue, oldValue) {
if (newValue < 0) {
this.deltaTip = "买入" + Math.abs(newValue) + "手";
} else {
this.deltaTip = "卖出" + Math.abs(newValue) + "手";
}
},
immediate: true,
deep: true
}
},
methods: {
showAbStrike: function (is) {
if (is) {
this.IsPercentage = "否";
}
else {
this.IsPercentage = "是";
}
},
getUnwindPrice: function () {
var thisObj = this;
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
main.message("请输入平仓日期");
return;
}
if (main.isEmpty(thisObj.tradeCash.FinalPrice)) {
main.message("请输入合理的标的价格");
return;
}
if (thisObj.trade.TradeType !== "自定义交易" && (main.isEmpty(thisObj.tradeCash.UnwindVol) || parseFloat(thisObj.tradeCash.UnwindVol) == 0)) {
main.message("请输入平仓波动率");
return;
}
if (thisObj.tradeCash.UnwindType == "全部平仓") {
thisObj.tradeCash.UnwindTradeAmount = otcformat.trading.notional(this.tradeCash.TradeAmount);
}
if (main.isEmpty(thisObj.tradeCash.UnwindTradeAmount) ||
parseFloat(thisObj.tradeCash.UnwindTradeAmount) == 0) {
main.message("请输入平仓数量");
return;
}
var postData = {
TradeId: thisObj.tradeCash.TradeId,
UnwindNotional: 1,
ActualUnwindNotional: thisObj.tradeCash.UnwindNotional,
VolType: "交易",
UnwindVol: parseFloat(thisObj.tradeCash.UnwindVol) / 100,
FinalPrice: thisObj.tradeCash.FinalPrice,
ValueDate: thisObj.tradeCash.ValueDate,
Midvol: parseFloat(thisObj.Midvol) / 100,
}
if (thisObj.trade.TTMDays || thisObj.trade.TTMDays === 0) {
postData.TTM = thisObj.trade.TTMDays;
}
main.post("/trade_cash/tradeUnwindCalc", postData).done(function (res) {
if (res.success) {
var pv = res.obj.PV;
var unwindVolPV = res.obj.UnwindVolPV;
var midPV = res.obj.MidPV;
if (pageObj.UnwindSinglePriceAngle == 0) {
pv = thisObj.trade.BuySell == "买入" ? res.obj.PV : -res.obj.PV;
unwindVolPV = thisObj.trade.BuySell == "买入" ? res.obj.UnwindVolPV : -res.obj.UnwindVolPV;
midPV = thisObj.trade.BuySell == "买入" ? res.obj.MidPV : -res.obj.MidPV;
}
var singlePV = thisObj.trade.BuySell == "买入" ? res.obj.PV : -res.obj.PV;
var singlePVPercentRate = tradeHelper.GetPremiumRateByTradeSinglePrice(singlePV, thisObj.tradeCash.InitialSpotPrice);
thisObj.tradeCash.SinglePVPercentRate = premiumRateFormat(singlePVPercentRate * 100);
thisObj.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(singlePV);
var unwindPricePercentRate = tradeHelper.GetPremiumRateByTradeSinglePrice(pv, thisObj.tradeCash.InitialSpotPrice);
thisObj.tradeCash.UnwindPricePercentRate = premiumRateFormat(unwindPricePercentRate * 100);
thisObj.tradeCash.UnwindPrice = otcformat.trading.tradeSinglePrice(pv);
thisObj.tradeCash.Day1Pnl = otcformat.trading.tradeSinglePrice(midPV - unwindVolPV);
if (thisObj.IsPercentage == "是") {
if (thisObj.tradeCash.UnwindType == "全部平仓") {
thisObj.tradeCash.UnwindPercentRate = unwindPercentFormat(thisObj.tradeCash.StockEqvNotional / thisObj.tradeCash.OriginalStockEqvNotional * 100);
}
thisObj.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceByPremiumRate(unwindPricePercentRate * thisObj.UnwindpriceAndMoneyIsAgreement, thisObj.tradeCash.OriginalStockEqvNotional * thisObj.tradeCash.UnwindPercentRate / 100, thisObj.tradeCash.ParticipationRate, thisObj.tradeCash.OriginalPrincipalSum * thisObj.tradeCash.UnwindPercentRate / 100, thisObj.tradeCash.AnnualizeFactor, thisObj.trade.BuySell, thisObj.trade.TradeType, false) * thisObj.UnwindpriceAndMoneyIsAgreement * thisObj.UnwindpriceAndamountIsAgreement);
}
else {
thisObj.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(thisObj.tradeCash.UnwindPrice * thisObj.UnwindpriceAndMoneyIsAgreement, thisObj.tradeCash.OriginalStockEqvNotional * thisObj.tradeCash.UnwindNotional / thisObj.tradeCash.OriginalNotional, thisObj.tradeCash.UnwindNotional, thisObj.tradeCash.OriginalPrincipalSum * thisObj.tradeCash.UnwindNotional / thisObj.tradeCash.OriginalNotional, thisObj.tradeCash.AnnualizeFactor, thisObj.trade.BuySell, thisObj.trade.TradeType, false) * thisObj.UnwindpriceAndMoneyIsAgreement * thisObj.UnwindpriceAndamountIsAgreement);
}
thisObj.$set(thisObj, "singleOptionValueResult", res.obj);
}
});
},
getCashflowUnwindPart: function () {
var thisObj = this;
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
main.message("请输入平仓日期");
return;
}
var postData = {
TradeId: thisObj.tradeCash.TradeId,
UnwindNotional: thisObj.tradeCash.UnwindStockEqvNotional,
VolType: "交易",
ValueDate: thisObj.tradeCash.ValueDate
}
if (thisObj.trade.TTMDays || thisObj.trade.TTMDays === 0) {
postData.TTM = thisObj.trade.TTMDays;
}
main.post("/trade_cash/tradeUnwindCalc", postData).done(function (res) {
if (res.success) {
var pv = res.obj.PV;
if (pageObj.UnwindAmountAngle == 0) {
pv = thisObj.trade.BuySell == "买入" ? res.obj.PV : -res.obj.PV;
}
thisObj.tradeCash.Amount = otcformat.trading.tradePrice(pv);//otcformat.trading.tradePrice(pv * thisObj.tradeCash.UnwindPercentRate / 100);
}
});
},
getUnwindVol: function () {
var thisObj = this;
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
main.message("请输入平仓日期");
return;
}
if (main.isEmpty(thisObj.tradeCash.FinalPrice)) {
main.message("请输入合理的标的价格");
return;
}
if (thisObj.trade.IsUsePremiumRate) {
if (main.isEmpty(thisObj.tradeCash.UnwindPricePercentRate)) {
main.message("请输入平仓单价");
return;
}
}
else {
if (main.isEmpty(thisObj.tradeCash.UnwindPrice)) {
main.message("请输入平仓单价");
return;
}
}
var postData = {
TradeId: thisObj.tradeCash.TradeId,
FinalPrice: thisObj.tradeCash.FinalPrice,
ValueDate: thisObj.tradeCash.ValueDate,
TTM: thisObj.trade.TTMDays,
UnwindPrice: thisObj.trade.IsUsePremiumRate ? tradeHelper.GetTradeSinglePriceByPremiumRate(thisObj.tradeCash.SinglePVPercentRate / 100, thisObj.tradeCash.InitialSpotPrice) : thisObj.tradeCash.SinglePV
};
main.post("/trade_cash/GetImpliedUnWindVol", postData).done(function (res) {
if (res.success) {
thisObj.tradeCash.UnwindVol = main.formatNumber(res.obj * 100);
thisObj.IsGetVolSurface = false;
}
});
},
getVolSurface: function () {
var thisObj = this;
var trade = thisObj.trade;
//获取交易波动率
if (trade.TradeType === "现金流交易") {
return 0;
}
var postData = _.extend({
VolType: "交易",
Strike: trade.Strike,
SpotPrice: thisObj.tradeCash.FinalPrice,
TradeDate: thisObj.tradeCash.ValueDate,
ExerciseDate: trade.ExerciseDate,
IsMoneynessOption: trade.IsMoneynessOption,
CallPut: trade.OptionType === "看涨" ? "Call" : "Put",
UnderlyingId: trade.UnderlyingId,
UnderlyingCode: trade.UnderlyingCode,
UnderlyingName: trade.UnderlyingName,
UnderlyingTypeId: thisObj.varietyid,
BaseVol: null,
BidVar: null,
AskVar: null,
MidVar: null
});
if (!postData.TradeDate || !postData.ExerciseDate) {
var msg = [];
!postData.TradeDate && msg.push('缺少平仓日期');
!postData.ExerciseDate && msg.push('缺少到期日期');
return $.Deferred(function () {
var self = this;
setTimeout(function () {
self.resolve({ success: true, obj: '', msg: msg.join(',') });
}, 100);
}).promise();
}
if (pageObj.is东证) {
postData.TradeDate = thisObj.tradeCash.ValueDate;
}
main.post("/pricing/AjaxGetVol", postData).done(function (resp) {
var vol = resp.obj.vol;
if (isNaN(vol)) {
let msg = resp.msg || resp.message;
return main.message("未获取到波动率: " + msg);
}
thisObj.tradeCash.UnwindVol = main.formatNumber(vol * 100);
thisObj.IsGetVolSurface = true;
if (pageObj.is东证) {
this.Midvol = thisObj.tradeCash.UnwindVol;
}
});
},
setUnwindDate: function (e) {
var thisObj = this;
thisObj.tradeCash.ValueDate = e;
if (thisObj.trade.TradeType === "现金流交易") {
this.getCashflowUnwindPart();
return;
}
var postData = {
ValueDate: thisObj.tradeCash.ValueDate,
TradeId: thisObj.tradeCash.TradeId,
SpotPrice: thisObj.tradeCash.FinalPrice,
};
main.post("/trade/GetTradeOfDate", postData).done(function (res) {
if (res.success) {
thisObj.tradeCash.TradeAmount = otcformat.trading.notional(res.obj.TradeAmount);
thisObj.tradeCash.Strike = otcformat.trading.umprice(res.obj.IsMoneynessOptionData ? (res.obj.Strike * res.obj.SpotPrice) : res.obj.Strike, 4);
thisObj.tradeCash.InitialSpotPrice = otcformat.trading.umprice(res.obj.SpotPrice, 4);
thisObj.tradeCash.UnwindTradeAmount = otcformat.trading.notional(res.obj.TradeAmount);
thisObj.tradeCash.OriginalStockEqvNotional = otcformat.trading.StockEqvNotional(res.obj.OriginalStockEqvNotional);
thisObj.tradeCash.StockEqvNotional = otcformat.trading.StockEqvNotional(res.obj.StockEqvNotional);
thisObj.tradeCash.UnwindPercentRate = unwindPercentFormat(res.obj.StockEqvNotional / res.obj.OriginalStockEqvNotional * 100);
thisObj.tradeCash.UnderlyingCode = res.obj.UnderlyingCode;
thisObj.trade.UnderlyingCode = res.obj.UnderlyingCode;
if (thisObj.trade.IsUsePremiumRate) {
if (thisObj.tradeCash.IsUnwindStockEqvNotional) {
thisObj.changeUnwindStockEqvNotional();
}
else {
thisObj.changeUnwindPercentRate();
}
}
else {
thisObj.changeUnwindTradeAmount();
}
}
});
main.post("/trade_cash/GetPositionVol", postData).done(function (res) {
if (res.success) {
thisObj.tradeCash.UnwindVol = main.formatNumber(res.obj * 100); //计算对应的持仓波动率
if (pageObj.is东证) {
thisObj.Midvol = thisObj.tradeCash.UnwindVol;
}
}
thisObj.setTTM(thisObj.trade);
});
},
changeUnderlyingPrice: function () {
this.tradeCash.FinalPriceType = "User";
this.tradeCash.FinalPrice = otcformat.trading.umprice(this.tradeCash.FinalPrice);
if (this.IsGetVolSurface) this.getVolSurface();
},
refreshUnderlyingPrice: function () {
var thisObj = this;
main.post("/underlying_manager/GetUnderlyingPriceByCode",
{ code: thisObj.trade.UnderlyingCode, tradeId: thisObj.trade.id, valuedate: thisObj.tradeCash.ValueDate }).done(function (res) {
thisObj.tradeCash.FinalPrice = otcformat.trading.umprice(res.obj);
thisObj.tradeCash.FinalPriceType = "System";
});
},
changeUnwindTradeAmount: function () {
if (parseFloat(this.tradeCash.UnwindTradeAmount) > parseFloat(this.tradeCash.TradeAmount)) {
main.message("平仓数量不能超过持仓数量");
this.tradeCash.UnwindTradeAmount = "";
}
this.tradeCash.UnwindTradeAmount = otcformat.trading.notional(this.tradeCash.UnwindTradeAmount, 2);
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.UnwindTradeAmount / this.tradeCash.TradeOriginalAmount * 100);
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
},
changeUnwindPercentRate: function () {
if (parseFloat(this.tradeCash.UnwindPercentRate) / 100 * parseFloat(this.tradeCash.OriginalStockEqvNotional) > parseFloat(this.tradeCash.StockEqvNotional)) {
main.message("平仓数量不能超过持仓数量");
this.tradeCash.UnwindPercentRate = "";
}
if (this.tradeCash.Trade_TradeType == "现金流交易") {
this.tradeCash.UnwindStockEqvNotional = otcformat.trading.tradePrice(parseFloat(this.tradeCash.UnwindPercentRate) / 100 * parseFloat(this.tradeCash.OriginalStockEqvNotional));
this.getCashflowUnwindPart();
return;
}
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.UnwindPercentRate);
this.tradeCash.UnwindNotional = this.tradeCash.OriginalNotional * this.tradeCash.UnwindPercentRate / 100;
this.tradeCash.UnwindTradeAmount = this.tradeCash.UnwindNotional / (this.variety.CountRatio || 1);
if (this.IsPercentage == "是") {
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceByPremiumRate(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndMoneyIsAgreement / 100, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
}
else {
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
}
},
changeUnwindStockEqvNotional: function () {
if (parseFloat(this.tradeCash.UnwindStockEqvNotional) > parseFloat(this.tradeCash.StockEqvNotional)) {
main.message("平仓数量不能超过持仓数量");
this.tradeCash.UnwindStockEqvNotional = "";
}
if (this.tradeCash.Trade_TradeType == "现金流交易") {
this.tradeCash.UnwindPercentRate = otcformat.trading.tradePrice(parseFloat(this.tradeCash.UnwindStockEqvNotional) / parseFloat(this.tradeCash.OriginalStockEqvNotional) * 100);
this.getCashflowUnwindPart();
return;
}
this.tradeCash.UnwindTradeAmount = this.tradeCash.TradeOriginalAmount * (this.tradeCash.UnwindStockEqvNotional / this.tradeCash.OriginalStockEqvNotional)
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
this.tradeCash.UnwindPercentRate = parseFloat(this.tradeCash.UnwindStockEqvNotional) / parseFloat(this.tradeCash.OriginalStockEqvNotional) * 100;
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceByPremiumRate(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndMoneyIsAgreement / 100, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
},
exchangeToUnwindStockEqvNotional: function () {
this.tradeCash.IsUnwindStockEqvNotional = true;
if (this.tradeCash.UnwindType !== "全部平仓") {
this.tradeCash.UnwindStockEqvNotional = "";
this.tradeCash.Amount = "";
}
},
exchangeToUnwindPercentRate: function () {
this.tradeCash.IsUnwindStockEqvNotional = false;
if (this.tradeCash.UnwindType !== "全部平仓") {
this.tradeCash.UnwindPercentRate = "";
this.tradeCash.Amount = "";
}
},
changeUnwindPrice: function () {
this.tradeCash.UnwindPrice = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPrice);
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
var unwindPricePercentRate = tradeHelper.GetPremiumRateByTradeSinglePrice(this.tradeCash.UnwindPrice, this.tradeCash.InitialSpotPrice);
this.tradeCash.UnwindPricePercentRate = premiumRateFormat(unwindPricePercentRate * 100);
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndSinglePVIsAgreement);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndSinglePVIsAgreement);
},
changeUnwindPricePercentRateCheck: function () {
this.tradeCash.UnwindPricePercentRateCheck = premiumRateFormat(this.tradeCash.UnwindPricePercentRateCheck);
if (this.tradeCash.UnwindType == "全部平仓") {
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.StockEqvNotional / this.tradeCash.OriginalStockEqvNotional * 100);
}
var AmoutCheck = otcformat.trading.tradePrice(tradeHelper.GetTradePriceByPremiumRate(this.tradeCash.UnwindPricePercentRateCheck * this.UnwindpriceAndMoneyIsAgreement / 100, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
this.$set(this.tradeCash, "AmountCheck", AmoutCheck);
var unwindPrice = tradeHelper.GetTradeSinglePriceByPremiumRate(this.tradeCash.UnwindPricePercentRateCheck / 100, this.tradeCash.InitialSpotPrice);
this.tradeCash.UnwindPriceCheck = otcformat.trading.tradeSinglePrice(unwindPrice);
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPriceCheck * this.UnwindpriceAndSinglePVIsAgreement);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRateCheck * this.UnwindpriceAndSinglePVIsAgreement);
},
changeUnwindPriceCheck: function () {
this.tradeCash.UnwindPriceCheck = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPriceCheck);
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
var AmoutCheck = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(this.tradeCash.UnwindPriceCheck * this.UnwindpriceAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
this.$set(this.tradeCash, "AmountCheck", AmoutCheck);
var unwindPricePercentRate = tradeHelper.GetPremiumRateByTradeSinglePrice(this.tradeCash.UnwindPriceCheck, this.tradeCash.InitialSpotPrice);
this.tradeCash.UnwindPricePercentRateCheck = premiumRateFormat(unwindPricePercentRate * 100);
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPriceCheck * this.UnwindpriceAndSinglePVIsAgreement);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRateCheck * this.UnwindpriceAndSinglePVIsAgreement);
},
changeAmount: function () {
if (this.trade.TradeType == "现金流交易") {
this.tradeCash.UnwindNotional = this.tradeCash.UnwindStockEqvNotional;
return;
}
this.tradeCash.Amount = otcformat.trading.tradePrice(this.tradeCash.Amount);
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
if (this.trade.IsUsePremiumRate) {
var unwindPrice = tradeHelper.GetTradeSinglePriceByTradePrice(this.tradeCash.Amount * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
var unwindPricePercentRate = tradeHelper.GetPremiumRateByTradePrice(this.tradeCash.Amount * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
this.tradeCash.UnwindPrice = otcformat.trading.tradeSinglePrice(unwindPrice * this.UnwindpriceAndamountIsAgreement);
this.tradeCash.UnwindPricePercentRate = premiumRateFormat(unwindPricePercentRate * this.UnwindpriceAndamountIsAgreement * 100);
} else {
var unwindPrice = tradeHelper.GetTradeSinglePriceByTradePrice(this.tradeCash.Amount * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
var unwindPricePercentRate = tradeHelper.GetPremiumRateByTradePrice(this.tradeCash.Amount * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
this.tradeCash.UnwindPrice = otcformat.trading.tradeSinglePrice(unwindPrice * this.UnwindpriceAndamountIsAgreement);
this.tradeCash.UnwindPricePercentRate = premiumRateFormat(unwindPricePercentRate * this.UnwindpriceAndamountIsAgreement * 100);
}
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndSinglePVIsAgreement);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndSinglePVIsAgreement);
},
changeAmountCheck: function () {
if (this.trade.TradeType == "现金流交易") {
return;
}
this.tradeCash.AmountCheck = otcformat.trading.tradePrice(this.tradeCash.AmountCheck);
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
if (this.trade.IsUsePremiumRate) {
var UnwindPriceCheck = tradeHelper.GetTradeSinglePriceByTradePrice(this.tradeCash.AmountCheck * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
var UnwindPricePercentRateCheck = tradeHelper.GetPremiumRateByTradePrice(this.tradeCash.AmountCheck * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
this.tradeCash.UnwindPriceCheck = otcformat.trading.tradeSinglePrice(UnwindPriceCheck * this.UnwindpriceAndamountIsAgreement);
this.tradeCash.UnwindPricePercentRateCheck = premiumRateFormat(UnwindPricePercentRateCheck * this.UnwindpriceAndamountIsAgreement * 100);
} else {
var UnwindPriceCheck = tradeHelper.GetTradeSinglePriceByTradePrice(this.tradeCash.AmountCheck * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
var UnwindPricePercentRateCheck = tradeHelper.GetPremiumRateByTradePrice(this.tradeCash.AmountCheck * this.UnwindAmountAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindAmountAndMoneyIsAgreement;
this.tradeCash.UnwindPriceCheck = otcformat.trading.tradeSinglePrice(UnwindPriceCheck * this.UnwindpriceAndamountIsAgreement);
this.tradeCash.UnwindPricePercentRateCheck = premiumRateFormat(UnwindPricePercentRateCheck * this.UnwindpriceAndamountIsAgreement * 100);
}
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPriceCheck * this.UnwindpriceAndSinglePVIsAgreement);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRateCheck * this.UnwindpriceAndSinglePVIsAgreement);
},
changeUnwindPricePercentRate: function () {
this.tradeCash.UnwindPricePercentRate = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPricePercentRate);
if (this.tradeCash.UnwindType == "全部平仓") {
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.StockEqvNotional / this.tradeCash.OriginalStockEqvNotional * 100);
}
if (this.IsPercentage == "是") {
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceByPremiumRate(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndMoneyIsAgreement / 100, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
}
else {
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
}
var unwindPrice = tradeHelper.GetTradeSinglePriceByPremiumRate(this.tradeCash.UnwindPricePercentRate / 100, this.tradeCash.InitialSpotPrice);
this.tradeCash.UnwindPrice = otcformat.trading.tradeSinglePrice(unwindPrice);
this.tradeCash.SinglePV = otcformat.trading.tradeSinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndSinglePVIsAgreement);
this.tradeCash.SinglePVPercentRate = premiumRateFormat(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndSinglePVIsAgreement);
},
changeUnwindType: function () {
if (this.tradeCash.UnwindType == "全部平仓") {
this.tradeCash.UnwindStockEqvNotional = this.tradeCash.StockEqvNotional;
this.tradeCash.UnwindTradeAmount = otcformat.trading.notional(this.tradeCash.TradeAmount);
if (this.trade.TradeType != "现金流交易") {
this.tradeCash.UnwindNotional = this.tradeCash.UnwindTradeAmount * (this.variety.CountRatio || 1);
}
}
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.UnwindStockEqvNotional / this.tradeCash.OriginalStockEqvNotional * 100);
if (this.IsPercentage == "是") {
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceByPremiumRate(this.tradeCash.UnwindPricePercentRate * this.UnwindpriceAndMoneyIsAgreement / 100, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.ParticipationRate, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindPercentRate / 100, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
}
else {
this.tradeCash.Amount = otcformat.trading.tradePrice(tradeHelper.GetTradePriceBySinglePrice(this.tradeCash.UnwindPrice * this.UnwindpriceAndMoneyIsAgreement, this.tradeCash.OriginalStockEqvNotional * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.UnwindNotional, this.tradeCash.OriginalPrincipalSum * this.tradeCash.UnwindNotional / this.tradeCash.OriginalNotional, this.tradeCash.AnnualizeFactor, this.trade.BuySell, this.trade.TradeType, false) * this.UnwindpriceAndMoneyIsAgreement * this.UnwindpriceAndamountIsAgreement);
}
if (this.trade.TradeType == "现金流交易") {
this.getCashflowUnwindPart();
}
},
setTTM: function (trade) {
var thisObj = this;
trade.TTMType = "System";
main.post("/calendar/DaysInPeriod", { from: thisObj.tradeCash.ValueDate, to: trade.ExerciseDate, varietyid: thisObj.variety.id, settlementType: trade.SettlementType }, { waitMe: false }).done(function (res) {
if (res.success) {
if (pageObj.g_precisionOfMinuteInQuote) {
trade.TTMDays = parseFloat(numeral(res.obj).format("0.00000"));
} else {
trade.TTMDays = parseFloat(numeral(res.obj).format("0.0000"));
}
Vue.set(thisObj.trade, trade);
}
});
},
changeTTM: function (trade) {
var thisObj = this;
trade.TTMType = "User";
trade.TTMDays = parseFloat(main.clearNoNum(trade.TTMDays + ""));
Vue.set(thisObj.trade, trade);
},
getSumbitText: function () {
return pageObj.g_isShowReCheckClose ? "平仓审核提交" : "平仓";
},
previewTradeAbstract: function (tradeCash, trade) {
var rowData = "";
tradeCash.UnwindPricePercentRate /= 100;
main.post("/trade/TradeterminationAbstract", { tc: tradeCash, td: trade, isUnwind: true }, { async: false }).done(function (res) {
rowData = res;
})
var thisObj = this;
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, rowData, ".txt");
main.message("导出成功", 50);
thisObj.closetrade_cashWindow();
},
cancel: function (index, layero) {
thisObj.closetrade_cashWindow();
},
shade: 0.4,
area: ['380px', '400px'],
content: "<pre style='padding:10px 0 5px 10px;line-height:20px'>" + rowData + "</pre>"
});
},
previewTradeAbstractV2(abstractText) {
var thisObj = this;
eModal.alert({
title: "平仓摘要",
message: '<pre style="padding-left:27%;line-height: 26px;white-space: pre-wrap;">' + abstractText + '</pre>',
buttons: [{
text: '保存', click() {
var dateTemp = new Date().Format("yyyyMMddhhmmss");
var exKey = "Trade_" + "平仓" + "_" + dateTemp;
thisObj.downCsv(exKey, abstractText, ".txt");
main.message("导出成功", 50);
thisObj.closetrade_cashWindow();
}
}, { text: '关闭', close: true, click: thisObj.closetrade_cashWindow, style: 'secondary' },]
});
},
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(/&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp/g, " ").replace(/&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp/g, " ").replace(/权&nbsp&nbsp利&nbsp&nbsp金/g, "权 利 金").replace(/<br\/>/g, "\r\n");
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 (main.isEmpty(thisObj.tradeCash.FinalPrice)) {
main.message("请输入合理的标的价格");
return;
}
if (main.isEmpty(thisObj.tradeCash.UnwindVol)) {
main.message("请输入平仓波动率");
return;
}
if (thisObj.trade.IsUsePremiumRate) {
if (main.isEmpty(thisObj.tradeCash.UnwindPricePercentRate) && thisObj.trade.TradeType != "现金流交易") {
main.message("请输入平仓单价");
return;
}
if (main.isEmpty(thisObj.tradeCash.UnwindPercentRate) ||
parseFloat(thisObj.tradeCash.UnwindPercentRate) <= 0) {
main.message("请输入合理的平仓比例");
return;
}
//计算一下平仓份额和平仓总额
if (thisObj.tradeCash.UnwindType == "全部平仓") {
thisObj.tradeCash.UnwindPercentRate = unwindPercentFormat(thisObj.tradeCash.StockEqvNotional / thisObj.tradeCash.OriginalStockEqvNotional * 100);
}
if (thisObj.trade.TradeType !== "现金流交易") {
thisObj.tradeCash.UnwindNotional = thisObj.tradeCash.UnwindTradeAmount * (thisObj.variety.CountRatio || 1);
thisObj.tradeCash.Notional = otcformat.trading.notional(thisObj.tradeCash.TradeAmount * (thisObj.variety.CountRatio || 1));
} else {
thisObj.tradeCash.UnwindNotional = thisObj.tradeCash.UnwindStockEqvNotional;
}
}
else {
if (main.isEmpty(thisObj.tradeCash.UnwindPrice)) {
main.message("请输入平仓单价");
return;
}
if (main.isEmpty(thisObj.tradeCash.UnwindTradeAmount) ||
parseFloat(thisObj.tradeCash.UnwindTradeAmount) <= 0) {
main.message("请输入合理的平仓数量");
return;
}
//计算一下平仓份额和平仓总额
if (thisObj.tradeCash.UnwindType == "全部平仓") {
thisObj.tradeCash.UnwindTradeAmount = otcformat.trading.notional(thisObj.tradeCash.TradeAmount);
}
thisObj.tradeCash.UnwindNotional = thisObj.tradeCash.UnwindTradeAmount * (thisObj.variety.CountRatio || 1);
thisObj.tradeCash.Notional = thisObj.tradeCash.TradeAmount * (thisObj.variety.CountRatio || 1);
}
thisObj.tradeCash.UnwindFee = thisObj.tradeCash.Amount;
thisObj.tradeCash.TradePrice = thisObj.tradeCash.FinalPrice;
thisObj.tradeCash.VolType = "交易";
let _Version = 'V2';
if (pageObj.g_isShowReCheckClose) {
main.confirm("确认提交平仓审核?",
function () {
var postData = jQuery.extend(true, {}, thisObj.tradeCash);
postData.UnwindVol = parseFloat(postData.UnwindVol) / 100;
postData.TradePremium = parseFloat(postData.TradePremium) / 100
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);
postData.UnwindVol = parseFloat(postData.UnwindVol) / 100;
postData.TradePremium = parseFloat(postData.TradePremium) / 100
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 () {
var postData = jQuery.extend(true, {}, thisObj.tradeCash);
postData.UnwindPricePercentRateCheck = parseFloat(postData.UnwindPricePercentRateCheck) / 100;
if (thisObj.IsPercentage == "是") {
postData.UnwindPriceCheck = null;
}
else {
postData.UnwindPricePercentRateCheck = null;
}
main.post("/trade_cash/UnwindTradeJson", postData).done(function (res) {
thisObj.closetrade_cashWindow();
});
});
},
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.closetrade_cashWindow();
});
});
},
closetrade_cashWindow: function () {
layer.closeMe('reloadData');
},
submitApproval(status) {
var pop = '';
if (status === 'pass') {
pop = "确认通过审批?";
}
if (status === 'reject') {
pop = "确认拒绝?";
}
var confirmFunc = function (additionalProcessing) {
var pData = { tradeId: pageObj.trade.id, 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 = `<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) {
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);
},
}
});