616 lines
35 KiB
JavaScript
616 lines
35 KiB
JavaScript
//otcformat禁止千分位分组
|
|
window.otcformat.options.disableGrouping = true;
|
|
|
|
const inputFormatDouble2 = Object.freeze({ precision: 2, append: '' });
|
|
const unwindPercentFormat = otcformat.fixed6;
|
|
var extraAmountInit = model.ExtraAmount;
|
|
var unwindPercentRateInit = model.UnwindPercentRate;
|
|
|
|
var vue = new Vue({
|
|
el: "#vueDiv",
|
|
data: {
|
|
trade: trade,
|
|
trade_swap: trade_swap,
|
|
tradeCash: model,
|
|
variety: variety,
|
|
pairTrade: pairTrade,
|
|
},
|
|
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);
|
|
this.tradeCash.UnwindPercentRate = unwindPercentFormat(this.tradeCash.UnwindPercentRate);
|
|
this.tradeCash.UnwindStockEqvNotional = this.tradeCash.UnwindStockEqvNotional == 0 ? this.tradeCash.StockEqvNotional : this.tradeCash.UnwindStockEqvNotional;
|
|
|
|
this.isStockEqvNotionalUnwind = this.tradeCash.UnwindStockEqvNotional != otcformat.trading.StockEqvNotional(parseFloat(this.tradeCash.UnwindPercentRate) / 100 * parseFloat(this.tradeCash.OriginalStockEqvNotional))
|
|
|
|
this.tradeCash.FinalPrice = otcformat.trading.umprice(this.tradeCash.FinalPrice);
|
|
this.tradeCash.Strike = otcformat.trading.umprice(this.tradeCash.Strike);
|
|
this.tradeCash.StartPrice = otcformat.trading.umprice(this.tradeCash.StartPrice);
|
|
|
|
if (!g_isUseApproval) {
|
|
//新增手续费设置
|
|
this.tradeCash.trade_cash_swap.GetCostFee = 0;
|
|
this.tradeCash.trade_cash_swap.PayCostFee = 0;
|
|
|
|
if (!this.trade.trade_swap.IsTradePriceWhenOpen && (!isSwap || this.tradeCash.ValueDate >= new moment(this.trade.ExerciseDate).format("YYYY-MM-DD"))) {
|
|
if (this.trade.trade_swap.IsGetFloatingProfit) {
|
|
this.tradeCash.trade_cash_swap.PayCostFee = this.trade.trade_swap.PayTradePrice * unwindPercentRateInit / 100;
|
|
}
|
|
if (this.trade.trade_swap.IsPayFloatingProfit) {
|
|
this.tradeCash.trade_cash_swap.GetCostFee = this.trade.trade_swap.GetTradePrice * unwindPercentRateInit / 100;
|
|
}
|
|
}
|
|
}
|
|
|
|
this.tradeCash.trade_cash_swap.PayCostFee = main.formatNumber(this.tradeCash.trade_cash_swap.PayCostFee);
|
|
this.tradeCash.trade_cash_swap.GetCostFee = main.formatNumber(this.tradeCash.trade_cash_swap.GetCostFee);
|
|
|
|
this.tradeCash.ExtraAmount = 0;
|
|
this.getSwapRate();
|
|
if (!g_isUseApproval) {
|
|
this.refreshGetUnderlyingPrice();
|
|
this.refreshPayUnderlyingPrice();
|
|
}
|
|
},
|
|
mounted: function () {
|
|
},
|
|
computed: function () {
|
|
},
|
|
watch: {
|
|
},
|
|
updated: function () {
|
|
},
|
|
destroyed: function () {
|
|
},
|
|
methods: {
|
|
getUnwindPriceGet: function (reason) {
|
|
var thisObj = this;
|
|
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
|
|
main.message("请输入平仓日期");
|
|
return;
|
|
}
|
|
if (main.isEmpty(thisObj.tradeCash.trade_cash_swap.GetFinalPrice) && thisObj.trade_swap.IsGetFloatingProfit) {
|
|
main.message("请输入合理的标的价格");
|
|
return;
|
|
}
|
|
if (main.isEmpty(thisObj.tradeCash.UnwindPercentRate) ||
|
|
parseFloat(thisObj.tradeCash.UnwindPercentRate) == 0) {
|
|
main.message("请输入平仓比例");
|
|
return;
|
|
}
|
|
var rate = thisObj.tradeCash.UnwindPercentRate / 100;
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
rate = parseFloat(parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) / thisObj.tradeCash.OriginalStockEqvNotional);
|
|
}
|
|
var postData = {
|
|
TradeId: thisObj.tradeCash.TradeId,
|
|
UnwindPercentRate: rate,
|
|
FinalPrice: thisObj.tradeCash.trade_cash_swap.GetFinalPrice,
|
|
ValueDate: thisObj.tradeCash.ValueDate,
|
|
isSwap: isSwap
|
|
}
|
|
|
|
main.post("/trade_cash/tradeSwapUnwindCalcGet", postData).done(function (res) {
|
|
if (res.success) {
|
|
thisObj.tradeCash.trade_cash_swap.GetInitialAmount = otcformat.trading.tradePrice(res.obj.InitialAmount);
|
|
thisObj.tradeCash.trade_cash_swap.PayExtraAmount = otcformat.trading.tradePrice(res.obj.ExtraAmount);
|
|
|
|
thisObj.tradeCash.trade_cash_swap.GetAmount = otcformat.trading.tradePrice(parseFloat(thisObj.tradeCash.trade_cash_swap.GetInitialAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.GetExtraAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.GetCostFee == null || thisObj.tradeCash.trade_cash_swap.GetCostFee == "" ? 0 : thisObj.tradeCash.trade_cash_swap.GetCostFee));
|
|
thisObj.tradeCash.trade_cash_swap.PayAmount = otcformat.trading.tradePrice(parseFloat(thisObj.tradeCash.trade_cash_swap.PayInitialAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.PayExtraAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.PayCostFee ?? 0));
|
|
thisObj.tradeCash.Amount = otcformat.trading.tradePrice(parseFloat(thisObj.tradeCash.trade_cash_swap.GetAmount) - parseFloat(thisObj.tradeCash.trade_cash_swap.PayAmount));
|
|
}
|
|
});
|
|
},
|
|
DoFeeSum: function () {
|
|
var GetCostFee = 0;
|
|
var PayCostFee = 0;
|
|
if (!this.trade.trade_swap.IsTradePriceWhenOpen && (!isSwap || this.tradeCash.ValueDate >= new moment(this.trade.ExerciseDate).format("YYYY-MM-DD"))) {
|
|
if (!this.trade.trade_swap.IsGetFloatingProfit) {
|
|
GetCostFee = this.trade.trade_swap.GetTradePrice * unwindPercentRateInit / 100;
|
|
}
|
|
if (!this.trade.trade_swap.IsPayFloatingProfit) {
|
|
PayCostFee = this.trade.trade_swap.PayTradePrice * unwindPercentRateInit / 100;
|
|
}
|
|
}
|
|
//手续费新增平仓比例计算
|
|
if (this.tradeCash.UnwindPercentRate != null && this.tradeCash.UnwindPercentRate != "" && this.tradeCash.UnwindType != "全部平仓") {
|
|
|
|
this.tradeCash.trade_cash_swap.GetCostFee = main.formatNumber(GetCostFee * (this.tradeCash.UnwindPercentRate / unwindPercentRateInit));
|
|
this.tradeCash.trade_cash_swap.PayCostFee = main.formatNumber(PayCostFee * (this.tradeCash.UnwindPercentRate / unwindPercentRateInit));
|
|
} else {
|
|
this.tradeCash.trade_cash_swap.GetCostFee = main.formatNumber(GetCostFee);
|
|
this.tradeCash.trade_cash_swap.PayCostFee = main.formatNumber(PayCostFee);
|
|
}
|
|
|
|
|
|
},
|
|
DoAmountSum: function () {
|
|
this.tradeCash.trade_cash_swap.GetExtraAmount = isNaN(parseFloat(this.tradeCash.trade_cash_swap.GetExtraAmount)) ? 0 : this.tradeCash.trade_cash_swap.GetExtraAmount;
|
|
this.tradeCash.trade_cash_swap.PayExtraAmount = isNaN(parseFloat(this.tradeCash.trade_cash_swap.PayExtraAmount)) ? 0 : this.tradeCash.trade_cash_swap.PayExtraAmount;
|
|
this.tradeCash.trade_cash_swap.GetCostFee = isNaN(parseFloat(this.tradeCash.trade_cash_swap.GetCostFee)) ? 0 : this.tradeCash.trade_cash_swap.GetCostFee;
|
|
this.tradeCash.trade_cash_swap.PayCostFee = isNaN(parseFloat(this.tradeCash.trade_cash_swap.PayCostFee)) ? 0 : this.tradeCash.trade_cash_swap.PayCostFee;
|
|
this.tradeCash.trade_cash_swap.GetInitialAmount = isNaN(parseFloat(this.tradeCash.trade_cash_swap.GetInitialAmount)) ? 0 : this.tradeCash.trade_cash_swap.GetInitialAmount;
|
|
this.tradeCash.trade_cash_swap.PayInitialAmount = isNaN(parseFloat(this.tradeCash.trade_cash_swap.PayInitialAmount)) ? 0 : this.tradeCash.trade_cash_swap.PayInitialAmount;
|
|
|
|
this.tradeCash.trade_cash_swap.GetAmount = otcformat.trading.tradePrice(parseFloat(this.tradeCash.trade_cash_swap.GetInitialAmount) + parseFloat(this.tradeCash.trade_cash_swap.GetExtraAmount) + parseFloat(this.tradeCash.trade_cash_swap.GetCostFee));
|
|
this.tradeCash.trade_cash_swap.PayAmount = otcformat.trading.tradePrice(parseFloat(this.tradeCash.trade_cash_swap.PayInitialAmount) + parseFloat(this.tradeCash.trade_cash_swap.PayExtraAmount) + parseFloat(this.tradeCash.trade_cash_swap.PayCostFee));
|
|
this.tradeCash.Amount = otcformat.trading.tradePrice(parseFloat(this.tradeCash.trade_cash_swap.GetAmount) - parseFloat(this.tradeCash.trade_cash_swap.PayAmount));
|
|
},
|
|
getUnwindPricePay: function (reason) {
|
|
var thisObj = this;
|
|
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
|
|
main.message("请输入平仓日期");
|
|
return;
|
|
}
|
|
if (main.isEmpty(thisObj.tradeCash.trade_cash_swap.PayFinalPrice) && thisObj.trade_swap.IsPayFloatingProfit) {
|
|
main.message("请输入合理的标的价格");
|
|
return;
|
|
}
|
|
if (main.isEmpty(thisObj.tradeCash.UnwindPercentRate) ||
|
|
parseFloat(thisObj.tradeCash.UnwindPercentRate) == 0) {
|
|
main.message("请输入平仓比例");
|
|
return;
|
|
}
|
|
var rate = thisObj.tradeCash.UnwindPercentRate / 100;
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
rate = parseFloat(parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) / thisObj.tradeCash.OriginalStockEqvNotional);
|
|
}
|
|
var postData = {
|
|
TradeId: thisObj.tradeCash.TradeId,
|
|
UnwindPercentRate: rate,
|
|
FinalPrice: thisObj.tradeCash.trade_cash_swap.PayFinalPrice,
|
|
ValueDate: thisObj.tradeCash.ValueDate,
|
|
isSwap: isSwap
|
|
}
|
|
|
|
main.post("/trade_cash/tradeSwapUnwindCalcPay", postData).done(function (res) {
|
|
if (res.success) {
|
|
thisObj.tradeCash.trade_cash_swap.PayInitialAmount = otcformat.trading.tradePrice(res.obj.InitialAmount);
|
|
thisObj.tradeCash.trade_cash_swap.GetExtraAmount = otcformat.trading.tradePrice(res.obj.ExtraAmount);
|
|
|
|
thisObj.tradeCash.trade_cash_swap.GetAmount = otcformat.trading.tradePrice(parseFloat(thisObj.tradeCash.trade_cash_swap.GetInitialAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.GetExtraAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.GetCostFee));
|
|
thisObj.tradeCash.trade_cash_swap.PayAmount = otcformat.trading.tradePrice(parseFloat(thisObj.tradeCash.trade_cash_swap.PayInitialAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.PayExtraAmount) + parseFloat(thisObj.tradeCash.trade_cash_swap.PayCostFee));
|
|
thisObj.tradeCash.Amount = otcformat.trading.tradePrice(parseFloat(thisObj.tradeCash.trade_cash_swap.GetAmount) - parseFloat(thisObj.tradeCash.trade_cash_swap.PayAmount));
|
|
}
|
|
});
|
|
},
|
|
getSwapRate: function () {
|
|
var thisObj = this;
|
|
var valueDate = thisObj.tradeCash.ValueDate > thisObj.trade.ExerciseDate ? thisObj.trade.ExerciseDate : thisObj.tradeCash.ValueDate;
|
|
main.post("/trade/GetSwapRateByValueDate", { valueDate: valueDate, tradeId: thisObj.trade.id, IsSwap: isSwap }).done(function (res) {
|
|
if (res.success) {
|
|
thisObj.trade_swap.GetSwapRate = res.obj.getSwapRate;
|
|
thisObj.trade_swap.PaySwapRate = res.obj.paySwapRate;
|
|
}
|
|
});
|
|
},
|
|
setUnwindDate: function (e) {
|
|
if (e > exerciseDate) {
|
|
this.tradeCash.UnwindType == "全部平仓";
|
|
}
|
|
this.tradeCash.ValueDate = e;
|
|
this.refreshGetUnderlyingPrice();
|
|
this.refreshPayUnderlyingPrice();
|
|
this.getSwapRate();
|
|
this.DoFeeSum();
|
|
},
|
|
changeGetUnderlyingPrice: function () {
|
|
this.tradeCash.trade_cash_swap.GetFinalPriceType = "User";
|
|
this.tradeCash.trade_cash_swap.GetFinalPrice = otcformat.trading.umprice(this.tradeCash.trade_cash_swap.GetFinalPrice);
|
|
this.getUnwindPriceGet();
|
|
},
|
|
changePayUnderlyingPrice: function () {
|
|
this.tradeCash.trade_cash_swap.PayFinalPriceType = "User";
|
|
this.tradeCash.trade_cash_swap.PayFinalPrice = otcformat.trading.umprice(this.tradeCash.trade_cash_swap.PayFinalPrice);
|
|
this.getUnwindPricePay();
|
|
},
|
|
refreshGetUnderlyingPrice: function (reason) {
|
|
var thisObj = this;
|
|
if (thisObj.trade_swap.IsGetFloatingProfit) {
|
|
main.post("/underlying_manager/GetUnderlyingPriceByCode",
|
|
{ code: thisObj.trade_swap.GetUnderlyingCode, tradeId: thisObj.trade.id, valuedate: thisObj.tradeCash.ValueDate })
|
|
.done(function (res) {
|
|
thisObj.tradeCash.trade_cash_swap.GetFinalPrice = otcformat.trading.umprice(res.obj);
|
|
thisObj.tradeCash.trade_cash_swap.GetFinalPriceType = "System";
|
|
|
|
thisObj.getUnwindPriceGet();
|
|
thisObj.$forceUpdate();
|
|
});
|
|
}
|
|
else {
|
|
thisObj.getUnwindPriceGet();
|
|
}
|
|
},
|
|
refreshPayUnderlyingPrice: function (reason) {
|
|
var thisObj = this;
|
|
if (thisObj.trade_swap.IsPayFloatingProfit) {
|
|
main.post("/underlying_manager/GetUnderlyingPriceByCode",
|
|
{ code: thisObj.trade_swap.PayUnderlyingCode, tradeId: thisObj.trade.id, valuedate: thisObj.tradeCash.ValueDate })
|
|
.done(function (res) {
|
|
thisObj.tradeCash.trade_cash_swap.PayFinalPrice = otcformat.trading.umprice(res.obj);
|
|
thisObj.tradeCash.trade_cash_swap.PayFinalPriceType = "System";
|
|
|
|
thisObj.getUnwindPricePay();
|
|
thisObj.$forceUpdate();
|
|
});
|
|
}
|
|
else {
|
|
thisObj.getUnwindPricePay();
|
|
}
|
|
},
|
|
changeUnwindNum: function () {
|
|
if (parseFloat(this.tradeCash.UnwindTradeAmount) <= 0) {
|
|
main.message("平仓数量不能小于或等于0");
|
|
this.tradeCash.UnwindPercentRate = "";
|
|
return;
|
|
}
|
|
if (parseFloat(this.tradeCash.UnwindTradeAmount) > parseFloat(this.tradeCash.TradeAmount)) {
|
|
main.message("平仓数量不能超过持仓数量");
|
|
this.tradeCash.UnwindPercentRate = "";
|
|
return;
|
|
}
|
|
//算平仓名义本金没有直接用期初价格,是因为,组合标的期初价格和名义本金,数量不是等比例的
|
|
this.tradeCash.UnwindStockEqvNotional = parseFloat(this.tradeCash.OriginalStockEqvNotional) / this.tradeCash.OriginalNotional * this.tradeCash.UnwindTradeAmount * underlying.CountRatio;
|
|
this.tradeCash.UnwindStockEqvNotional = otcformat.trading.StockEqvNotional(parseFloat(this.tradeCash.UnwindStockEqvNotional))
|
|
this.tradeCash.UnwindPercentRate = parseFloat(this.tradeCash.UnwindStockEqvNotional) / parseFloat(this.tradeCash.OriginalStockEqvNotional) * 100;
|
|
this.getUnwindPriceGet();
|
|
this.getUnwindPricePay();
|
|
this.tradeCash.UnwindPercentRate = main.formatNumber(this.tradeCash.UnwindPercentRate, 6);
|
|
this.isStockEqvNotionalUnwind = true;
|
|
this.tradeCash.ExtraAmount = otcformat.trading.tradePrice(unwindPercentRateInit > 0 ? extraAmountInit * (this.tradeCash.UnwindPercentRate / unwindPercentRateInit) : 0);
|
|
this.DoFeeSum();
|
|
|
|
},
|
|
changeUnwindPercentRate: function () {
|
|
if (parseFloat(this.tradeCash.UnwindPercentRate) / 100 * parseFloat(this.tradeCash.OriginalStockEqvNotional) > parseFloat(this.tradeCash.StockEqvNotional)) {
|
|
main.message("平仓数量不能超过持仓数量");
|
|
this.tradeCash.UnwindPercentRate = "";
|
|
}
|
|
this.tradeCash.UnwindPercentRate = main.formatNumber(this.tradeCash.UnwindPercentRate, 6);
|
|
this.tradeCash.UnwindStockEqvNotional = otcformat.trading.StockEqvNotional(parseFloat(this.tradeCash.UnwindPercentRate) / 100 * parseFloat(this.tradeCash.OriginalStockEqvNotional))
|
|
this.tradeCash.UnwindNotional = otcformat.trading.notional(this.tradeCash.OriginalNotional * this.tradeCash.UnwindPercentRate / 100);
|
|
this.tradeCash.UnwindTradeAmount = otcformat.trading.notional(this.tradeCash.UnwindNotional / (this.variety.CountRatio || 1));
|
|
this.getUnwindPriceGet();
|
|
this.getUnwindPricePay();
|
|
this.DoFeeSum();
|
|
this.isStockEqvNotionalUnwind = false;
|
|
this.tradeCash.ExtraAmount = otcformat.trading.tradePrice(unwindPercentRateInit > 0 ? extraAmountInit * (this.tradeCash.UnwindPercentRate / unwindPercentRateInit) : 0);
|
|
},
|
|
changeUnwindStockEqvNotional: function () {
|
|
if (parseFloat(this.tradeCash.UnwindStockEqvNotional) > parseFloat(this.tradeCash.StockEqvNotional)) {
|
|
main.message("平仓数量不能超过持仓数量");
|
|
this.tradeCash.UnwindStockEqvNotional = "";
|
|
}
|
|
|
|
this.tradeCash.UnwindStockEqvNotional = otcformat.trading.StockEqvNotional(parseFloat(this.tradeCash.UnwindStockEqvNotional))
|
|
this.tradeCash.UnwindPercentRate = parseFloat(parseFloat(this.tradeCash.UnwindStockEqvNotional) / this.tradeCash.OriginalStockEqvNotional) * 100;
|
|
this.getUnwindPriceGet();
|
|
this.getUnwindPricePay();
|
|
this.tradeCash.UnwindPercentRate = main.formatNumber(this.tradeCash.UnwindPercentRate, 6);
|
|
this.isStockEqvNotionalUnwind = true;
|
|
this.tradeCash.ExtraAmount = otcformat.trading.tradePrice(unwindPercentRateInit > 0 ? extraAmountInit * (this.tradeCash.UnwindPercentRate / unwindPercentRateInit) : 0);
|
|
this.DoFeeSum();
|
|
},
|
|
changeUnwindType: function () {
|
|
if (this.tradeCash.UnwindType == "全部平仓") {
|
|
this.tradeCash.UnwindPercentRate = otcformat.trading.notional(main.formatNumber(this.tradeCash.StockEqvNotional / this.tradeCash.OriginalStockEqvNotional * 100, 6));
|
|
this.tradeCash.UnwindStockEqvNotional = otcformat.trading.StockEqvNotional(parseFloat(this.tradeCash.StockEqvNotional));
|
|
this.tradeCash.UnwindNotional = this.tradeCash.Notional;
|
|
this.tradeCash.UnwindTradeAmount = this.tradeCash.TradeAmount;
|
|
this.isStockEqvNotionalUnwind = this.tradeCash.UnwindStockEqvNotional != otcformat.trading.StockEqvNotional(parseFloat(this.tradeCash.UnwindPercentRate) / 100 * parseFloat(this.tradeCash.OriginalStockEqvNotional))
|
|
this.getUnwindPriceGet();
|
|
this.getUnwindPricePay();
|
|
this.DoFeeSum();
|
|
|
|
}
|
|
},
|
|
setTTM: function (trade) {
|
|
var thisObj = this;
|
|
trade.TTMType = "System";
|
|
main.post("/calendar/DaysInPeriod", { from: thisObj.tradeCash.ValueDate, to: trade.ExerciseDate, varietyid: thisObj.variety.id }, { waitMe: false }).done(function (res) {
|
|
if (res.success) {
|
|
if (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);
|
|
}
|
|
});
|
|
},
|
|
getSumbitText: function () {
|
|
return g_isShowReCheckClose ? "平仓审核提交" : "平仓";
|
|
},
|
|
getSwapText: function () {
|
|
return g_isShowApplySwap ? "互换审核提交" : "互换";
|
|
},
|
|
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(/<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();
|
|
}
|
|
},
|
|
unwindSwapTrade: function () {
|
|
var thisObj = this;
|
|
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
|
|
main.message("请输入平仓日期");
|
|
return;
|
|
}
|
|
if (main.isEmpty(thisObj.tradeCash.trade_cash_swap.GetFinalPrice) && thisObj.trade_swap.IsGetFloatingProfit
|
|
|| main.isEmpty(thisObj.tradeCash.trade_cash_swap.PayFinalPrice) && thisObj.trade_swap.IsPayFloatingProfit) {
|
|
main.message("请输入合理的标的价格");
|
|
return;
|
|
}
|
|
if (thisObj.isStockEqvNotionalUnwind ?
|
|
(main.isEmpty(thisObj.tradeCash.UnwindStockEqvNotional) || parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) <= 0) :
|
|
(main.isEmpty(thisObj.tradeCash.UnwindPercentRate) || parseFloat(thisObj.tradeCash.UnwindPercentRate) <= 0)) {
|
|
main.message("请输入合理的平仓比例");
|
|
return;
|
|
}
|
|
|
|
//计算一下平仓份额和平仓总额
|
|
if (thisObj.tradeCash.UnwindType == "全部平仓") {
|
|
thisObj.tradeCash.UnwindPercentRate = main.formatNumber(thisObj.tradeCash.StockEqvNotional / thisObj.tradeCash.OriginalStockEqvNotional * 100, 6);
|
|
}
|
|
|
|
thisObj.tradeCash.Notional = otcformat.trading.notional(thisObj.tradeCash.TradeAmount * (thisObj.variety.CountRatio || 1));
|
|
thisObj.tradeCash.UnwindFee = thisObj.tradeCash.Amount;
|
|
thisObj.tradeCash.trade_cash_swap.GetSwapRate = thisObj.trade_swap.GetSwapRate;
|
|
thisObj.tradeCash.trade_cash_swap.PaySwapRate = thisObj.trade_swap.PaySwapRate;
|
|
if (thisObj.tradeCash.UnwindMethod == 1) {
|
|
if (isNaN(parseFloat(this.tradeCash.UnwindTradeAmount))) {
|
|
main.message("平仓数量不能为空");
|
|
return;
|
|
}
|
|
if (parseFloat(this.tradeCash.UnwindTradeAmount) <= 0) {
|
|
main.message("平仓数量不能小于或等于0");
|
|
return;
|
|
}
|
|
if (parseFloat(this.tradeCash.UnwindTradeAmount) > parseFloat(this.tradeCash.TradeAmount)) {
|
|
main.message("平仓数量不能超过持仓数量");
|
|
return;
|
|
}
|
|
} else {
|
|
this.tradeCash.UnwindTradeAmount = 0;//非数量平仓直接归0,不存储,避免计算小数点误差
|
|
}
|
|
if (g_isShowReCheckClose) {
|
|
main.confirm("确认提交平仓审核?",
|
|
function () {
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
thisObj.tradeCash.UnwindPercentRate = parseFloat(parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) / thisObj.tradeCash.OriginalStockEqvNotional) * 100;
|
|
}
|
|
var postData = jQuery.extend(true, {}, thisObj.tradeCash);
|
|
postData.UnwindVol = parseFloat(postData.UnwindVol) / 100;
|
|
var thisObj2 = thisObj;
|
|
main.post("/trade_cash/ApplyUnwindSwapTrade", postData).done(function (res) {
|
|
if (res.success) {
|
|
thisObj2.closetrade_cashWindow();
|
|
}
|
|
else {
|
|
try {
|
|
thisObj2.closetrade_cashWindow();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
});
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
thisObj.tradeCash.UnwindPercentRate = main.formatNumber(thisObj.tradeCash.UnwindPercentRate, 6);;
|
|
}
|
|
});
|
|
} else {
|
|
main.confirm("确认提交平仓?",
|
|
function () {
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
thisObj.tradeCash.UnwindPercentRate = parseFloat(parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) / thisObj.tradeCash.OriginalStockEqvNotional) * 100;
|
|
}
|
|
var postData = jQuery.extend(true, {}, thisObj.tradeCash);
|
|
postData.UnwindVol = parseFloat(postData.UnwindVol) / 100;
|
|
var thisObj2 = thisObj;
|
|
main.post("/trade_cash/UnwindSwapTrade", postData).done(function (res) {
|
|
if (res.success) {
|
|
thisObj2.closetrade_cashWindow();
|
|
}
|
|
else {
|
|
try {
|
|
thisObj2.closetrade_cashWindow();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
});
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
thisObj.tradeCash.UnwindPercentRate = main.formatNumber(thisObj.tradeCash.UnwindPercentRate, 6);;
|
|
}
|
|
});
|
|
}
|
|
},
|
|
swapTrade: function () {
|
|
var thisObj = this;
|
|
if (main.isEmpty(thisObj.tradeCash.ValueDate)) {
|
|
main.message("请输入互换日期");
|
|
return;
|
|
}
|
|
if (main.isEmpty(thisObj.tradeCash.trade_cash_swap.GetFinalPrice) && thisObj.trade_swap.IsGetFloatingProfit
|
|
|| main.isEmpty(thisObj.tradeCash.trade_cash_swap.PayFinalPrice) && thisObj.trade_swap.IsPayFloatingProfit) {
|
|
main.message("请输入合理的标的价格");
|
|
return;
|
|
}
|
|
if (thisObj.isStockEqvNotionalUnwind ?
|
|
(main.isEmpty(thisObj.tradeCash.UnwindStockEqvNotional) || parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) <= 0) :
|
|
(main.isEmpty(thisObj.tradeCash.UnwindPercentRate) || parseFloat(thisObj.tradeCash.UnwindPercentRate) <= 0)) {
|
|
main.message("请输入合理的互换比例");
|
|
return;
|
|
}
|
|
|
|
//计算一下平仓份额和平仓总额
|
|
if (thisObj.tradeCash.UnwindType == "全部平仓") {
|
|
thisObj.tradeCash.UnwindPercentRate = main.formatNumber(thisObj.tradeCash.StockEqvNotional / thisObj.tradeCash.OriginalStockEqvNotional * 100, 6);
|
|
}
|
|
|
|
thisObj.tradeCash.Notional = otcformat.trading.notional(thisObj.tradeCash.TradeAmount * (thisObj.variety.CountRatio || 1));
|
|
thisObj.tradeCash.UnwindFee = thisObj.tradeCash.Amount;
|
|
thisObj.tradeCash.trade_cash_swap.GetSwapRate = thisObj.trade_swap.GetSwapRate;
|
|
thisObj.tradeCash.trade_cash_swap.PaySwapRate = thisObj.trade_swap.PaySwapRate;
|
|
|
|
if (g_isShowApplySwap) {
|
|
main.confirm("确认提交互换审核?",
|
|
function () {
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
thisObj.tradeCash.UnwindPercentRate = parseFloat(parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) / thisObj.tradeCash.OriginalStockEqvNotional) * 100;
|
|
}
|
|
var postData = jQuery.extend(true, {}, thisObj.tradeCash);
|
|
postData.UnwindVol = parseFloat(postData.UnwindVol) / 100;
|
|
var thisObj2 = thisObj;
|
|
main.post("/trade_cash/ApplySwapTrade", postData).done(function (res) {
|
|
if (res.success) {
|
|
//thisObj2.previewTradeAbstract(thisObj.tradeCash, res.obj);
|
|
thisObj2.closetrade_cashWindow();
|
|
}
|
|
else {
|
|
try {
|
|
thisObj2.closetrade_cashWindow();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
main.confirm("确认互换?",
|
|
function () {
|
|
if (thisObj.isStockEqvNotionalUnwind) {
|
|
thisObj.tradeCash.UnwindPercentRate = parseFloat(parseFloat(thisObj.tradeCash.UnwindStockEqvNotional) / thisObj.tradeCash.OriginalStockEqvNotional) * 100;
|
|
}
|
|
var postData = jQuery.extend(true, {}, thisObj.tradeCash);
|
|
postData.UnwindVol = parseFloat(postData.UnwindVol) / 100;
|
|
var thisObj2 = thisObj;
|
|
main.post("/trade_cash/SwapTrade", postData).done(function (res) {
|
|
if (res.success) {
|
|
//thisObj2.previewTradeAbstract(thisObj.tradeCash, res.obj);
|
|
thisObj2.closetrade_cashWindow();
|
|
}
|
|
else {
|
|
try {
|
|
thisObj2.closetrade_cashWindow();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
},
|
|
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) {
|
|
}
|
|
},
|
|
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;
|
|
}
|
|
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);
|
|
},
|
|
}
|
|
});
|
|
|
|
function getFloatData(data) {
|
|
return isNaN(parseFloat(data)) ? 0 : parseFloat(data)
|
|
} |