autocomplete.setData 只写控件显示值、不触发 onSelect 回写 v-model—— 新增时默认取客户列表第一个(consClients[0])仅 setData,trade.ClientId 仍为空, 前端校验拦截且不发请求;用户须手动从下拉重选一次才能保存。 - swaptrade/swapTradeEdit.js(SwapTrade2 现用页):默认客户经 vue.changeClient 显式回写,与手动选择等价 - trade/swapTradeEdit.js(SwapTrade 旧版页,同缺陷):直接赋值回写 trade.ClientId,不走 changeClient 以避免初始化触发 initMarginRate 后端调用 与 demo/autocomplete.js 死代码删除(3be4b48c)无关:该文件零引用,生产实现在 fastVue.base.js 未改动,缺陷自山证 v2.3.0 拷贝带入即存在。
1372 lines
64 KiB
JavaScript
1372 lines
64 KiB
JavaScript
//otcformat禁止千分位分组
|
|
window.otcformat.options.disableGrouping = true;
|
|
|
|
const consClients = ylotc.clients;
|
|
const consTraders = ylotc.traders;
|
|
const consAssetUnits = page.canAddNewTrader ? ylotc.assetunits
|
|
: ylotc.assetunits.filter(x => x.TraderIds.includes(page.Trade.TraderId));
|
|
|
|
const inputFormatInteger = Object.freeze({ precision: 0, append: '' });
|
|
const inputFormatEqvNotional = Object.freeze({ precision: otcformat.trading.StockEqvNotional.precision, append: '' });
|
|
const inputFormatTradeAmount = Object.freeze({ precision: otcformat.trading.notional.precision, append: '' });
|
|
const inputFormatSwapRate = Object.freeze({ precision: otcformat.trading.premiumRateP.precision, negative: true, append: '%' });
|
|
const inputFormatTradePrice = Object.freeze({ precision: otcformat.trading.tradePrice.precision, negative: true, append: '' });
|
|
const inputFormatTradeSinglePrice = Object.freeze({ precision: otcformat.trading.tradeSinglePrice.precision, negative: true, append: '' });
|
|
const inputFormatMarginRate = Object.freeze({ precision: otcformat.trading.marginRateP.precision, append: '%' });
|
|
|
|
var salesCommissionCtrl;
|
|
var lastGetUnderlyingId = page.Trade.trade_swap.GetUnderlyingId;
|
|
var lastPayUnderlyingId = page.Trade.trade_swap.PayUnderlyingId;
|
|
var getCountRatio = page.Trade.trade_swap.GetCountRatio;
|
|
var payCountRatio = page.Trade.trade_swap.PayCountRatio;
|
|
var getContractSize = page.Trade.trade_swap.GetContractSize;
|
|
var payContractSize = page.Trade.trade_swap.PayContractSize;
|
|
|
|
const consUnderlyingFlag = (function () {
|
|
let unSelFlag = tradeHelper.UnderlyingSelectFlag;
|
|
return unSelFlag.UseForTrading | unSelFlag.IncludeMatured | unSelFlag.UsePinYinFilter | unSelFlag.IncludeBasket | unSelFlag.IncludeSynthetic | unSelFlag.CheckLaunch;
|
|
}());
|
|
|
|
const inputFormatDouble2 = Object.freeze({ precision: 2, append: '' });
|
|
var autoMarginTemplateName;
|
|
|
|
//定价格式化(来自配置)
|
|
const InputFormatPercent = Object.freeze({ precision: 2, append: '%' });
|
|
|
|
const consMetaDic = {
|
|
'组合标的': JSON.parse(page.Trade.MetaDic['组合标的'] || '{}'),
|
|
'组合标的2': JSON.parse(page.Trade.MetaDic['组合标的2'] || '{}')
|
|
};
|
|
|
|
var getMaxPrice = 0;
|
|
var payMaxPrice = 0;
|
|
var isGetSyntheticUnderlying = false;
|
|
var isPaySyntheticUnderlying = false;
|
|
|
|
function initAutoCtrl(initial) {
|
|
if (salesCommissionCtrl && (page.isAdd || !($("#Salesmen").val()))) {
|
|
salesCommissionCtrl.changeSalesmen($("#ClientId").val());
|
|
}
|
|
}
|
|
|
|
//标的选择组件
|
|
const vueUnderlying = function () {
|
|
return {
|
|
props: ['value', 'index'],
|
|
data() {
|
|
return { autoUnderlying: null };
|
|
},
|
|
mounted() {
|
|
var selFlag = tradeHelper.UnderlyingSelectFlag;
|
|
autoUnderlying = tradeHelper.UnderlyingAutoComplete(this.$el, { SelectFlag: selFlag.UsePinYinFilter | selFlag.UseForTrading | selFlag.IncludeSynthetic | selFlag.IncludeMatured | selFlag.IncludeBasket | selFlag.CheckLaunch, BlackLimit: 2, });
|
|
autoUnderlying.onSelect(this.onchange);
|
|
this.value && autoUnderlying.selectByCode(this.value);
|
|
},
|
|
methods: {
|
|
onchange(data) {
|
|
data.index = this.index;
|
|
if (this.value !== data.Code) {
|
|
this.$emit('change', data);
|
|
this.$emit('input', data.Code);
|
|
}
|
|
}
|
|
},
|
|
destroyed() {
|
|
autoUnderlying && autoUnderlying.dispose();
|
|
},
|
|
template: '<input type="text" v-model="value" />'
|
|
};
|
|
};
|
|
|
|
//ESC
|
|
$(document).keyup(function (event) {
|
|
if (event.keyCode === 27) {
|
|
window.parent.layer.closeAll();
|
|
}
|
|
});
|
|
|
|
const vue = new Vue({
|
|
el: '#tradeEditForm',
|
|
data: {
|
|
trade: _.cloneDeep(page.Trade),
|
|
viewState: {
|
|
variety: tradeHelper.getEmptyVariety(),
|
|
underlying: tradeHelper.getEmptyUnderlying(),
|
|
synthetic: null,
|
|
Extend: { TradingPlace: "柜台市场", ClearingAgency: "交易员方" },
|
|
GetObservation: {
|
|
hasValue: false,
|
|
ObservationDates: '',
|
|
ObservationNum: 1, ObservationUnit: 'D',
|
|
ObservationHolidayType: 'Following', ObservationAlignEnd: true
|
|
},
|
|
PayObservation: {
|
|
hasValue: false,
|
|
ObservationDates: '',
|
|
ObservationNum: 1, ObservationUnit: 'D',
|
|
ObservationHolidayType: 'Following', ObservationAlignEnd: true
|
|
},
|
|
GetSwapTime: undefined,
|
|
PaySwapTime: undefined,
|
|
},
|
|
currencys: page.currencys,
|
|
payNotionalSingleFee: getContractSize > 0 ? page.Trade.trade_swap.IsShare ? page.Trade.trade_swap.PaySingleFee : (page.Trade.trade_swap.PaySingleFee / getContractSize) : 0,
|
|
getNotionalSingleFee: payContractSize > 0 ? page.Trade.trade_swap.IsShare ? page.Trade.trade_swap.GetSingleFee : (page.Trade.trade_swap.GetSingleFee / payContractSize) : 0,
|
|
isSingleFee: !(page.Trade.trade_swap.PayUnAnnualRate > 0 || page.Trade.trade_swap.GetUnAnnualRate > 0)
|
|
},
|
|
watch: {
|
|
},
|
|
created: function () {
|
|
if (this.trade.MetaDic['组合标的']) {
|
|
this.viewState.synthetic = JSON.parse(this.trade.MetaDic['组合标的']);
|
|
}
|
|
this.viewState.Extend.TradingPlace = this.trade.MetaDic["交易场所"] || "";
|
|
this.viewState.Extend.ClearingAgency = this.trade.MetaDic["清算机构"] || "";
|
|
},
|
|
mounted() {
|
|
__init(this);
|
|
$("#MainProtocolCode").val(this.trade.MetaDic["主协议编号"]);
|
|
$("#SupProtocolCode").val(this.trade.MetaDic["补充协议编号"]);
|
|
|
|
//设置支付周期
|
|
this.setObservationRate();
|
|
|
|
//设置中央平台
|
|
this.setTradingPaltform();
|
|
},
|
|
methods: {
|
|
//观察频率字符串获取
|
|
getUnitStr(unit) {
|
|
let unitStr = "";
|
|
switch (unit) {
|
|
case "W": unitStr = "周"; break;
|
|
case "M": unitStr = "月"; break;
|
|
case "Y": unitStr = "年"; break;
|
|
default: unitStr = "天"; break;
|
|
}
|
|
return unitStr;
|
|
},
|
|
setObservationRate() {
|
|
//赋值支付周期
|
|
let paymentCycle = this.trade.MetaDic["支付周期"];
|
|
|
|
//赋值收取周期
|
|
let chargeCycle = this.trade.MetaDic["收取周期"];
|
|
let num = 0, unit = "", unitStr = "";
|
|
if (paymentCycle != null && paymentCycle != "undefined" && paymentCycle != "" && paymentCycle != "TERM") {
|
|
|
|
let pCycleArr = paymentCycle.split("|");
|
|
|
|
if (pCycleArr.length >= 1) {
|
|
num = pCycleArr[0].substring(0, pCycleArr[0].length - 1);
|
|
unit = pCycleArr[0].substring(pCycleArr[0].length - 1, pCycleArr[0].length);
|
|
unitStr = this.getUnitStr(unit);
|
|
}
|
|
$("#PayObservationRate").val('每' + num + unitStr).attr('lang', paymentCycle);
|
|
this.viewState.PayObservation.ObservationNum = num;
|
|
this.viewState.PayObservation.ObservationUnit = unit;
|
|
this.viewState.PayObservation.ObservationFrequency = pCycleArr[1] != null ? pCycleArr[1] : "";
|
|
}
|
|
if (chargeCycle != null && chargeCycle != "undefined" && chargeCycle != "" && chargeCycle != "TERM") {
|
|
let cCycleArr = chargeCycle.split("|");
|
|
if (cCycleArr.length >= 1) {
|
|
num = cCycleArr[0].substring(0, cCycleArr[0].length - 1);
|
|
unit = cCycleArr[0].substring(cCycleArr[0].length - 1, cCycleArr[0].length);
|
|
unitStr = this.getUnitStr(unit);
|
|
}
|
|
$("#GetObservationRate").val('每' + num + unitStr).attr('lang', chargeCycle);
|
|
|
|
this.viewState.GetObservation.ObservationNum = num;
|
|
this.viewState.GetObservation.ObservationUnit = unit;
|
|
this.viewState.GetObservation.ObservationFrequency = cCycleArr[1] != null ? cCycleArr[1] : "";
|
|
}
|
|
},
|
|
//设置中央平台
|
|
setTradingPaltform() {
|
|
let isCentralClearing = this.trade.MetaDic["中央对手方清算"];
|
|
let centralClearingPaltform = this.trade.MetaDic["中央清算平台"];
|
|
let tradingPaltform = this.trade.MetaDic["交易平台"];
|
|
$("#IsCentralClearing").val(isCentralClearing);
|
|
$("#CentralClearingPaltform").val(centralClearingPaltform);
|
|
$("#TradingPaltform").val(tradingPaltform);
|
|
},
|
|
changeIsCentralClearing() { },
|
|
changeCentralClearingPaltform() { },
|
|
changeTradingPaltform() { },
|
|
|
|
changeIsGetFloatingProfit() {
|
|
},
|
|
changeIsPayFloatingProfit() {
|
|
},
|
|
changeSwapType() {
|
|
this.trade.StockEqvNotional = 0;
|
|
this.initMarginRate();
|
|
|
|
if (this.trade.trade_swap.SwapType == "多空组合") {
|
|
this.trade.trade_swap.IsTradePriceWhenOpen = true;
|
|
}
|
|
},
|
|
//变更交易场所
|
|
changeTradingPlace() {
|
|
this.trade.MetaDic["交易场所"] = this.viewState.Extend.TradingPlace;
|
|
},
|
|
//变更清算机构
|
|
changeClearingAgency() {
|
|
this.trade.MetaDic["清算机构"] = this.viewState.Extend.ClearingAgency;
|
|
},
|
|
//收取变更数量
|
|
changeGetTradeAmount() {
|
|
var spotPrice = isGetSyntheticUnderlying ? getMaxPrice : $("#trade_swap\\.GetSpotPrice").val();
|
|
|
|
var notional = this.trade.trade_swap.GetTradeAmount * getCountRatio;
|
|
this.trade.trade_swap.GetNotional = otcformat.trading.notional(notional);
|
|
this.trade.trade_swap.GetLot = otcformat.trading.notional(notional / getContractSize);
|
|
|
|
var stockEqvNotional = spotPrice * notional;
|
|
this.trade.StockEqvNotional = otcformat.trading.stockEqvNotional(stockEqvNotional);
|
|
this.CnStockEqvNotional();
|
|
this.changeStockEqvNotional();
|
|
},
|
|
changeGetLot() {
|
|
var spotPrice = isGetSyntheticUnderlying ? getMaxPrice : $("#trade_swap\\.GetSpotPrice").val();
|
|
var notional = this.trade.trade_swap.GetLot * getContractSize;
|
|
var tradeAmount = notional / getCountRatio;
|
|
this.trade.trade_swap.GetNotional = otcformat.trading.notional(notional);
|
|
this.trade.trade_swap.GetTradeAmount = otcformat.trading.notional(tradeAmount);
|
|
|
|
var stockEqvNotional = spotPrice * notional;
|
|
this.trade.StockEqvNotional = otcformat.trading.stockEqvNotional(stockEqvNotional);
|
|
this.CnStockEqvNotional();
|
|
this.changeStockEqvNotional();
|
|
},
|
|
//支付变更数量
|
|
changePayTradeAmount() {
|
|
var spotPrice = isPaySyntheticUnderlying ? payMaxPrice : $("#trade_swap\\.PaySpotPrice").val();
|
|
|
|
var notional = this.trade.trade_swap.PayTradeAmount * payCountRatio;
|
|
this.trade.trade_swap.PayNotional = otcformat.trading.notional(notional);
|
|
this.trade.trade_swap.PayLot = otcformat.trading.notional(notional / payContractSize);
|
|
var stockEqvNotional = spotPrice * notional;
|
|
this.trade.StockEqvNotional = otcformat.trading.stockEqvNotional(stockEqvNotional);
|
|
this.CnStockEqvNotional();
|
|
this.changeStockEqvNotional();
|
|
},
|
|
changePayLot() {
|
|
var spotPrice = isPaySyntheticUnderlying ? payMaxPrice : $("#trade_swap\\.PaySpotPrice").val();
|
|
var notional = this.trade.trade_swap.PayLot * payContractSize;
|
|
var tradeAmount = notional / payCountRatio;
|
|
this.trade.trade_swap.PayNotional = otcformat.trading.notional(notional);
|
|
this.trade.trade_swap.PayTradeAmount = otcformat.trading.notional(tradeAmount);
|
|
|
|
var stockEqvNotional = spotPrice * notional;
|
|
this.trade.StockEqvNotional = otcformat.trading.stockEqvNotional(stockEqvNotional);
|
|
this.CnStockEqvNotional();
|
|
this.changeStockEqvNotional();
|
|
},
|
|
//变更名义本金(仅格式化,不反算数量)
|
|
changeStockEqvNotional() {
|
|
this.trade.StockEqvNotional = otcformat.trading.StockEqvNotional(this.trade.StockEqvNotional);
|
|
|
|
if (this.trade.trade_swap.IsPayFloatingProfit) {
|
|
// var spotPrice = isPaySyntheticUnderlying ? payMaxPrice : $("#trade_swap\\.PaySpotPrice").val();
|
|
// var notional = spotPrice != 0 ? this.trade.StockEqvNotional / spotPrice : 0;
|
|
// this.trade.trade_swap.PayNotional = otcformat.trading.notional(Math.abs(notional));
|
|
// var tradeAmount = notional / payCountRatio;
|
|
// this.trade.trade_swap.PayTradeAmount = otcformat.trading.notional(Math.abs(tradeAmount));
|
|
// var lots = notional / payContractSize;
|
|
// this.trade.trade_swap.PayLot = otcformat.trading.notional(Math.abs(lots));
|
|
if (this.isSingleFee) {
|
|
this.changeGetSingleFee();
|
|
}
|
|
else {
|
|
this.changeGetUnAnnualRate();
|
|
}
|
|
}
|
|
|
|
if (this.trade.trade_swap.IsGetFloatingProfit) {
|
|
if (this.isSingleFee) {
|
|
this.changePaySingleFee();
|
|
}
|
|
else {
|
|
this.changePayUnAnnualRate();
|
|
}
|
|
}
|
|
|
|
this.CnStockEqvNotional();
|
|
},
|
|
CnStockEqvNotional() {
|
|
//var val = this.trade.StockEqvNotional;
|
|
//var chineseVal;
|
|
//if (val === "") {
|
|
// chineseVal = "";
|
|
//} else {
|
|
// chineseVal = main.changeMoneyToChinese(val).replace(/万0\.00$/, '万');
|
|
//}
|
|
//var $parent = $("#StockEqvNotional").parent();
|
|
//var $chineseSpan = $parent.children("span.chinese");
|
|
//if (!$chineseSpan.length) {
|
|
// $parent.append(`<span class="chinese" >${chineseVal}</span>`);
|
|
//} else {
|
|
// $chineseSpan.html(chineseVal);
|
|
//}
|
|
},
|
|
showAbsPrice() {
|
|
this.isSingleFee = true;
|
|
this.trade.trade_swap.GetUnAnnualRate = 0;
|
|
this.trade.trade_swap.PayUnAnnualRate = 0;
|
|
},
|
|
showPercentPrice() {
|
|
this.isSingleFee = false;
|
|
this.trade.trade_swap.GetSingleFee = 0;
|
|
this.getNotionalSingleFee = this.trade.trade_swap.GetSingleFee;
|
|
this.trade.trade_swap.PaySingleFee = 0;
|
|
this.payNotionalSingleFee = this.trade.trade_swap.PaySingleFee;
|
|
|
|
},
|
|
changePaySingleFee() {
|
|
this.trade.trade_swap.PaySingleFee = this.payNotionalSingleFee;
|
|
this.trade.trade_swap.PayTradePrice = this.trade.trade_swap.PaySingleFee * this.trade.trade_swap.GetLot;
|
|
if (!this.trade.trade_swap.IsShare) {
|
|
this.trade.trade_swap.PayTradePrice = this.trade.trade_swap.PaySingleFee * this.trade.trade_swap.GetNotional;
|
|
}
|
|
},
|
|
changePayUnAnnualRate() {
|
|
this.trade.trade_swap.PayTradePrice = this.trade.trade_swap.PayUnAnnualRate * this.trade.StockEqvNotional;
|
|
},
|
|
changePayTradePrice() {
|
|
if (this.isSingleFee) {
|
|
this.trade.trade_swap.PaySingleFee = this.trade.trade_swap.GetLot > 0 ? this.trade.trade_swap.PayTradePrice / this.trade.trade_swap.GetLot : 0;
|
|
if (!this.trade.trade_swap.IsShare) {
|
|
this.trade.trade_swap.PaySingleFee = this.trade.trade_swap.GetNotional > 0 ? this.trade.trade_swap.PayTradePrice / this.trade.trade_swap.GetNotional : 0;
|
|
}
|
|
this.payNotionalSingleFee = this.trade.trade_swap.PaySingleFee;
|
|
}
|
|
else {
|
|
this.trade.trade_swap.PayUnAnnualRate = this.trade.StockEqvNotional > 0 ? this.trade.trade_swap.PayTradePrice / this.trade.StockEqvNotional : 0;
|
|
}
|
|
},
|
|
//变更交易日期
|
|
changeTradeDate(force) {
|
|
|
|
if (this.trade.trade_swap.IsPayFloatingProfit) {
|
|
this.getSpotPrice(this.trade.trade_swap.PayUnderlyingCode, "", this.trade.TradeDate);
|
|
var spotPrice = isPaySyntheticUnderlying ? payMaxPrice : $("#trade_swap\\.PaySpotPrice").val();
|
|
var notional = this.trade.trade_swap.PayTradeAmount * payCountRatio;
|
|
this.trade.trade_swap.PayNotional = otcformat.trading.notional(notional);
|
|
this.trade.trade_swap.PayLot = otcformat.trading.notional(notional / payContractSize);
|
|
var stockEqvNotional = spotPrice * notional;
|
|
this.trade.StockEqvNotional = otcformat.trading.stockEqvNotional(stockEqvNotional);
|
|
}
|
|
if (this.trade.trade_swap.IsGetFloatingProfit) {
|
|
this.getSpotPrice(this.trade.trade_swap.GetUnderlyingCode, "组合标的", this.trade.TradeDate);
|
|
var spotPrice = isGetSyntheticUnderlying ? getMaxPrice : $("#trade_swap\\.GetSpotPrice").val();
|
|
var notional = this.trade.trade_swap.GetTradeAmount * getCountRatio;
|
|
this.trade.trade_swap.GetNotional = otcformat.trading.notional(notional);
|
|
this.trade.trade_swap.GetLot = otcformat.trading.notional(notional / getContractSize);
|
|
var stockEqvNotional = spotPrice * notional;
|
|
this.trade.StockEqvNotional = otcformat.trading.stockEqvNotional(stockEqvNotional);
|
|
}
|
|
},
|
|
//变更结算日期
|
|
changeExerciseDate() {
|
|
this.trade.SettlementDate = this.trade.ExerciseDate;
|
|
},
|
|
changeGetSingleFee() {
|
|
this.trade.trade_swap.GetSingleFee = this.getNotionalSingleFee;
|
|
this.trade.trade_swap.GetTradePrice = this.trade.trade_swap.GetSingleFee * this.trade.trade_swap.PayLot;
|
|
if (!this.trade.trade_swap.IsShare) {
|
|
this.trade.trade_swap.GetTradePrice = this.trade.trade_swap.GetSingleFee * this.trade.trade_swap.PayNotional;
|
|
}
|
|
},
|
|
changeGetUnAnnualRate() {
|
|
this.trade.trade_swap.GetTradePrice = this.trade.trade_swap.GetUnAnnualRate * this.trade.StockEqvNotional;
|
|
},
|
|
changeGetTradePrice() {
|
|
if (this.isSingleFee) {
|
|
this.trade.trade_swap.GetSingleFee = this.trade.trade_swap.PayLot > 0 ? this.trade.trade_swap.GetTradePrice / this.trade.trade_swap.PayLot : 0;
|
|
if (!this.trade.trade_swap.IsShare) {
|
|
this.trade.trade_swap.GetSingleFee = this.trade.trade_swap.PayNotional > 0 ? this.trade.trade_swap.GetTradePrice / this.trade.trade_swap.PayNotional : 0;
|
|
}
|
|
this.getNotionalSingleFee = this.trade.trade_swap.GetSingleFee;
|
|
}
|
|
else {
|
|
this.trade.trade_swap.GetUnAnnualRate = this.trade.StockEqvNotional > 0 ? this.trade.trade_swap.GetTradePrice / this.trade.StockEqvNotional : 0;
|
|
}
|
|
},
|
|
changeBaseUnit() {
|
|
if (this.isSingleFee) {
|
|
this.changePayTradePrice();
|
|
this.changeGetTradePrice();
|
|
}
|
|
},
|
|
savetrade() {
|
|
if (!this.checkSubmitData()) {
|
|
return false;
|
|
}
|
|
|
|
this.savetrade_inner();
|
|
},
|
|
savetrade_inner() {
|
|
this.trade.OriginalStockEqvNotional = this.trade.StockEqvNotional;
|
|
this.trade.trade_swap.GetSpotPrice = $("#trade_swap\\.GetSpotPrice").val();
|
|
this.trade.trade_swap.PaySpotPrice = $("#trade_swap\\.PaySpotPrice").val();
|
|
if (!this.trade.trade_swap.IsGetFloatingProfit) {
|
|
this.trade.trade_swap.GetUnderlyingId = null;
|
|
this.trade.trade_swap.GetUnderlyingCode = null;
|
|
this.trade.trade_swap.GetSpotPrice = null;
|
|
this.trade.trade_swap.GetTradeAmount = null;
|
|
}
|
|
if (!this.trade.trade_swap.IsPayFloatingProfit) {
|
|
this.trade.trade_swap.PayUnderlyingId = null;
|
|
this.trade.trade_swap.PayUnderlyingCode = null;
|
|
this.trade.trade_swap.PaySpotPrice = null;
|
|
this.trade.trade_swap.PayTradeAmount = null;
|
|
}
|
|
if (this.trade.trade_swap.IsPayFloatingProfit) {
|
|
this.trade.UnderlyingId = this.trade.trade_swap.PayUnderlyingId;
|
|
this.trade.UnderlyingCode = this.trade.trade_swap.PayUnderlyingCode;
|
|
}
|
|
else {
|
|
this.trade.UnderlyingId = this.trade.trade_swap.GetUnderlyingId;
|
|
this.trade.UnderlyingCode = this.trade.trade_swap.GetUnderlyingCode;
|
|
}
|
|
var isSwapTimeAndRate = this.trade.ExerciseDate + ";" + 0
|
|
|
|
|
|
|
|
if (!_.trim(this.trade.trade_swap.GetSwapRate)) {
|
|
this.trade.trade_swap.GetSwapRate = 0;
|
|
}
|
|
|
|
if (!_.trim(this.trade.trade_swap.PaySwapRate)) {
|
|
this.trade.trade_swap.PaySwapRate = 0;
|
|
}
|
|
if ((this.trade.trade_swap.GetSwapTimeAndRate == null || this.trade.trade_swap.GetSwapTimeAndRate == isSwapTimeAndRate || this.trade.trade_swap.IsGetFloatingProfit)) {
|
|
this.trade.trade_swap.GetSwapTimeAndRate = this.trade.ExerciseDate + ";" + this.trade.trade_swap.GetSwapRate + ";false";
|
|
}
|
|
if ((this.trade.trade_swap.PaySwapTimeAndRate == null || this.trade.trade_swap.PaySwapTimeAndRate == isSwapTimeAndRate || this.trade.trade_swap.IsPayFloatingProfit)) {
|
|
this.trade.trade_swap.PaySwapTimeAndRate = this.trade.ExerciseDate + ";" + this.trade.trade_swap.PaySwapRate + ";false";
|
|
}
|
|
this.trade.TradeType = "收益互换";
|
|
this.trade.StructureType = "收益互换";
|
|
this.trade.IsUsePremiumRate = true;
|
|
this.trade.IsTradePricePayType = true;
|
|
this.trade.SalesCommission = salesCommissionCtrl.getValue();
|
|
this.trade.UnderlyingInstrumentType = "Stock";
|
|
var isNotionalValid = true;
|
|
var isUnderlyingValid = true;
|
|
var isSpotPriceValid = true;
|
|
if (this.trade.trade_swap.IsGetFloatingProfit && this.trade.trade_swap.SwapType == "多空组合") {
|
|
this.trade.get_trade_swap_details.forEach(x => {
|
|
if (!x.Notional > 0) {
|
|
isNotionalValid = false;
|
|
}
|
|
if (!x.UnderlyingCode) {
|
|
isUnderlyingValid = false
|
|
}
|
|
if (!x.SpotPrice) {
|
|
isSpotPriceValid = false
|
|
}
|
|
});
|
|
this.trade.IsGroup = 1;
|
|
}
|
|
else if (!this.trade.trade_swap.IsGetFloatingProfit) {
|
|
this.trade.trade_swap.PayTradePrice = null;
|
|
this.trade.trade_swap.GetLongShort = null;
|
|
}
|
|
|
|
if (this.trade.trade_swap.IsPayFloatingProfit && this.trade.trade_swap.SwapType == "多空组合") {
|
|
this.trade.pay_trade_swap_details.forEach(x => {
|
|
if (!x.Notional > 0) {
|
|
isNotionalValid = false;
|
|
}
|
|
if (!x.UnderlyingCode) {
|
|
isUnderlyingValid = false
|
|
}
|
|
if (!x.SpotPrice) {
|
|
isSpotPriceValid = false
|
|
}
|
|
});
|
|
this.trade.IsGroup = 1;
|
|
}
|
|
else if (!this.trade.trade_swap.IsPayFloatingProfit) {
|
|
this.trade.trade_swap.GetTradePrice = null;
|
|
this.trade.trade_swap.PayLongShort = null;
|
|
}
|
|
|
|
if (!isNotionalValid) {
|
|
main.message("篮子标的详情设置,数量不能为空");
|
|
return false;
|
|
}
|
|
if (!isUnderlyingValid) {
|
|
main.message("篮子标的详情设置,标的不能为空");
|
|
return false;
|
|
}
|
|
if (!isSpotPriceValid) {
|
|
main.message("篮子标的详情设置,期初价格不能为空");
|
|
return false;
|
|
}
|
|
//数据库统一是每手手续费
|
|
if (!this.trade.trade_swap.IsShare) {
|
|
this.trade.trade_swap.PaySingleFee = (this.trade.trade_swap.GetNotional > 0 && this.trade.trade_swap.PayTradePrice != null) ? this.trade.trade_swap.PayTradePrice.toFixed(otcformat.trading.tradePrice.precision) / this.trade.trade_swap.GetNotional * getContractSize : 0;
|
|
this.trade.trade_swap.GetSingleFee = (this.trade.trade_swap.PayNotional > 0 && this.trade.trade_swap.GetTradePrice != null) ? this.trade.trade_swap.GetTradePrice.toFixed(otcformat.trading.tradePrice.precision) / this.trade.trade_swap.PayNotional * payContractSize : 0;
|
|
}
|
|
if (!this.isSingleFee) {
|
|
this.trade.trade_swap.PaySingleFee = 0;
|
|
this.trade.trade_swap.GetSingleFee = 0;
|
|
}
|
|
else {
|
|
this.trade.trade_swap.PayUnAnnualRate = 0;
|
|
this.trade.trade_swap.GetUnAnnualRate = 0;
|
|
}
|
|
|
|
this.trade.MetaDic = {
|
|
'组合标的': consMetaDic["组合标的"] ? JSON.stringify(consMetaDic["组合标的"]) : '',
|
|
'组合标的2': consMetaDic["组合标的2"] ? JSON.stringify(consMetaDic["组合标的2"]) : '',
|
|
'交易场所': this.viewState.Extend.TradingPlace,
|
|
'清算机构': this.viewState.Extend.ClearingAgency,
|
|
"主协议编号": $("#MainProtocolCode").val(),
|
|
"补充协议编号": $("#SupProtocolCode").val(),
|
|
"中央对手方清算": $("#IsCentralClearing").val(),
|
|
"中央清算平台": $("#CentralClearingPaltform").val(),
|
|
"交易平台": $("#TradingPaltform").val(),
|
|
"收取周期": $("#GetObservationRate").attr('lang') ?? "",
|
|
"支付周期": $("#PayObservationRate").attr('lang') ?? "",
|
|
"ExchangeRate": this.trade.ExchangeRate,
|
|
};
|
|
console.log(this.trade.MetaDic);
|
|
|
|
if (page.showCCR) {
|
|
this.trade.MetaDic["ccr_k"] = $("#ccr_k").val();
|
|
this.trade.MetaDic["ignoreRiskExposure"] = $("#ignoreRiskExposure").val();
|
|
}
|
|
|
|
if (this.viewState.GetSwapTime != undefined) this.trade.MetaDic["ObservationRemark1"] = this.viewState.GetSwapTime;
|
|
if (this.viewState.PaySwapTime != undefined) this.trade.MetaDic["ObservationRemark2"] = this.viewState.PaySwapTime;
|
|
|
|
if (page.parentTradeId > 0) {
|
|
this.trade.ParentTradeId = page.parentTradeId;
|
|
}
|
|
if (this.trade.ParentTradeId > 0) {
|
|
this.trade.IsGroup = 2;
|
|
}
|
|
var tags = new Array();
|
|
$(".tag-context .tag-item").each(function (i, v) {
|
|
tags.push({ Id: $(v).data("id"), Name: $(v).data("name") });
|
|
});
|
|
this.trade.Tags = tags;
|
|
main.post("/trade/tradeEditJson", this.trade).done(function (resp) {
|
|
window.location.href = "/trade/tradeview?enid=" + resp.obj.EncryptId;
|
|
if (window.parent && window.parent.reloadtrade) {
|
|
window.parent.reloadtrade();
|
|
}
|
|
});
|
|
},
|
|
changeMainProtocolCode() {
|
|
this.getSupProtocolCode();
|
|
},
|
|
getMainProtocolCode() {
|
|
$("#MainProtocolCode option").remove();
|
|
main.post("/Client/getMainProtocolCodes", { clientId: $("#ClientId").val() }, { async: false }).done(function (resp) {
|
|
var obj = $("#MainProtocolCode");
|
|
_.forEach(resp, (v) => {
|
|
obj.append("<option >" + v.Text + "</option>");
|
|
})
|
|
});
|
|
this.getSupProtocolCode()
|
|
},
|
|
getSupProtocolCode() {
|
|
$("#SupProtocolCode option").remove();
|
|
if ($("#MainProtocolCode").val()) {
|
|
main.post("/Client/getSideProtocols", { mainProtocol: $("#MainProtocolCode").val() }, { async: false }).done(function (resp) {
|
|
var obj = $("#SupProtocolCode");
|
|
_.forEach(resp, (v) => {
|
|
obj.append("<option >" + v + "</option>");
|
|
})
|
|
});
|
|
}
|
|
},
|
|
getSyntheticPrices(underlyingCode, metaKey, tradeDate) {
|
|
var thisObj = this;
|
|
main.post('/pricing/AjaxGetSyntheticPriceModel', { underlyingCode: underlyingCode, tradeDate: tradeDate }, false).done(function (resp) {
|
|
$(metaKey === '组合标的' ? "#trade_swap\\.GetSpotPrice" : "#trade_swap\\.PaySpotPrice")
|
|
.val(otcformat.trading.umprice(resp.obj.Price));
|
|
consMetaDic[metaKey] = resp.obj;
|
|
if (resp.obj.SuList) {
|
|
if (metaKey === '组合标的') {
|
|
getMaxPrice = 0;
|
|
resp.obj.SuList.forEach((item, index) => getMaxPrice = Math.abs(item.Price * item.Coefficient) > getMaxPrice ? Math.abs(item.Price * item.Coefficient) : getMaxPrice);
|
|
}
|
|
else {
|
|
payMaxPrice = 0;
|
|
resp.obj.SuList.forEach((item, index) => payMaxPrice = Math.abs(item.Price * item.Coefficient) > payMaxPrice ? Math.abs(item.Price * item.Coefficient) : payMaxPrice);
|
|
}
|
|
}
|
|
thisObj.changeStockEqvNotional();
|
|
});
|
|
},
|
|
getSpotPrice(underlyingCode, metaKey, StartDate) {
|
|
var thisObj = this;
|
|
main.post("/pricing/AjaxGetUnderlyingPrice", { underlyingCode: underlyingCode, tradeDate: StartDate })
|
|
.done(function (resp) {
|
|
$(metaKey === '组合标的' ? "#trade_swap\\.GetSpotPrice" : "#trade_swap\\.PaySpotPrice")
|
|
.val(otcformat.trading.umprice(resp.obj.price));
|
|
thisObj.changeStockEqvNotional();
|
|
});
|
|
},
|
|
setGetUnderlyingCode(data) {
|
|
var thisObj = this;
|
|
getCountRatio = data.CountRatio;
|
|
getContractSize = data.ContractSize;
|
|
thisObj.trade.trade_swap.GetUnderlyingId = data.id;
|
|
if (lastGetUnderlyingId !== data.id) {
|
|
thisObj.trade.get_trade_swap_details = [];
|
|
|
|
main.post("/swapTrade/GetBasketUnderlyingDetails?underlyingId=" + data.id).done(function (res) {
|
|
lastGetUnderlyingId = data.id;
|
|
thisObj.trade.get_trade_swap_details = res[0];
|
|
thisObj.trade.QuoteCurrency = res[1].QuoteCurrency;
|
|
thisObj.trade.get_trade_swap_details.forEach(x => {
|
|
x.LongShort = "多头"
|
|
});
|
|
});
|
|
}
|
|
|
|
let $i = $("#trade_swap\\.GetSpotPrice");
|
|
if (data.IsSynthetic) {
|
|
isGetSyntheticUnderlying = true;
|
|
$i.val('');
|
|
let TradeDate = thisObj.TradeDate;
|
|
this.getSyntheticPrices(data.Code, "组合标的", TradeDate);
|
|
} else {
|
|
isGetSyntheticUnderlying = false;
|
|
consMetaDic["组合标的"] = null;
|
|
let StartDate = thisObj.StartDate;
|
|
this.getSpotPrice(data.Code, "组合标的", StartDate);
|
|
this.changeStockEqvNotional();
|
|
}
|
|
$i.prop('readonly', data.IsSynthetic).next('.btn').toggle(!data.IsSynthetic);
|
|
},
|
|
setPayUnderlyingCode(data) {
|
|
var thisObj = this;
|
|
payCountRatio = data.CountRatio;
|
|
payContractSize = data.ContractSize;
|
|
thisObj.trade.trade_swap.PayUnderlyingId = data.id;
|
|
thisObj.trade.trade_swap.PayUnderlyingCode = data.Code;
|
|
if (lastPayUnderlyingId !== data.id) {
|
|
thisObj.trade.pay_trade_swap_details = [];
|
|
|
|
main.post("/swapTrade/GetBasketUnderlyingDetails?underlyingId=" + data.id).done(function (res) {
|
|
lastPayUnderlyingId = data.id;
|
|
thisObj.trade.pay_trade_swap_details = res[0];
|
|
thisObj.trade.QuoteCurrency = res[1].QuoteCurrency;
|
|
thisObj.trade.pay_trade_swap_details.forEach(x => {
|
|
x.LongShort = "多头"
|
|
});
|
|
});
|
|
}
|
|
|
|
let $i = $("#trade_swap\\.PaySpotPrice");
|
|
if (data.IsSynthetic) {
|
|
isPaySyntheticUnderlying = true;
|
|
$i.val('');
|
|
let TradeDate = thisObj.TradeDate;
|
|
this.getSyntheticPrices(data.Code, "组合标的2", TradeDate);
|
|
} else {
|
|
isPaySyntheticUnderlying = false;
|
|
consMetaDic["组合标的2"] = null;
|
|
let StartDate = thisObj.StartDate;
|
|
this.getSpotPrice(data.Code, "组合标的2", StartDate);
|
|
}
|
|
$i.prop('readonly', data.IsSynthetic).next('.btn').toggle(!data.IsSynthetic);
|
|
|
|
this.changeStockEqvNotional();
|
|
this.initMarginRate();
|
|
},
|
|
blurSwapRate(btnId) {
|
|
if (btnId == "Get" && this.trade.trade_swap.IsGetFloatingProfit) {//支付端浮动收益
|
|
return;
|
|
}
|
|
if (btnId != "Get" && this.trade.trade_swap.IsPayFloatingProfit) {//收取端浮动收益
|
|
return;
|
|
}
|
|
var observationDates = btnId == "Get" ? this.trade.trade_swap.GetSwapTimeAndRate : this.trade.trade_swap.PaySwapTimeAndRate;
|
|
var that = this;
|
|
if (observationDates && observationDates.length > 0) {
|
|
var rates = observationDates.split(";");
|
|
var rateArr = rates[1].split(",");
|
|
var swapRate = btnId == "Get" ? this.trade.trade_swap.GetSwapRate : this.trade.trade_swap.PaySwapRate;
|
|
var same = true;
|
|
var rate1 = rateArr[0];
|
|
rateArr.forEach(function (item) {
|
|
if (item != rate1) {
|
|
same = false;
|
|
}
|
|
});
|
|
if (same) {
|
|
var confirmMsg = "检测到互换利率发生变化,将自动覆盖观察列表";
|
|
main.confirm(confirmMsg, function () {
|
|
rateArr.forEach(function (element, index, arr) {
|
|
arr[index] = swapRate;
|
|
});
|
|
rates[1] = rateArr.join(",");
|
|
observationDates = rates.join(";");
|
|
if (btnId == "Get") {
|
|
that.trade.trade_swap.GetSwapTimeAndRate = observationDates;
|
|
} else {
|
|
that.trade.trade_swap.PaySwapTimeAndRate = observationDates;
|
|
}
|
|
|
|
});
|
|
} else {
|
|
main.message("检测到互换利率与互换利率列表不一致,请手动重新生成互换列表");
|
|
}
|
|
}
|
|
|
|
},
|
|
setObservationDates(btnId) {
|
|
var startTime = this.trade.TradeDate;
|
|
var endTime = this.trade.ExerciseDate;
|
|
if (main.isEmpty(startTime)) {
|
|
main.message("请输入开始日期");
|
|
return false;
|
|
}
|
|
if (main.isEmpty(endTime)) {
|
|
main.message("请输入到期日期");
|
|
return false;
|
|
}
|
|
|
|
var observation = btnId == "Get" ? this.viewState.GetObservation : this.viewState.PayObservation;
|
|
var observationNum = observation.ObservationNum;
|
|
var observationUnit = observation.ObservationUnit;
|
|
var observationHolidayType = observation.ObservationHolidayType;
|
|
var observationFrequency = observation.ObservationFrequency;
|
|
|
|
var alignEnd = observation.ObservationAlignEnd;
|
|
var observationDates = btnId == "Get" ? this.trade.trade_swap.GetSwapTimeAndRate : this.trade.trade_swap.PaySwapTimeAndRate;
|
|
sessionStorage.setItem(btnId + "_observationdates", observationDates ?? "");
|
|
var defaultSwapRate = btnId == "Get" ? this.trade.trade_swap.GetSwapRate : this.trade.trade_swap.PaySwapRate;
|
|
|
|
var Comments = btnId == "Get" ? this.viewState.GetSwapTime : this.viewState.PaySwapTime;
|
|
Comments = Comments == undefined ? btnId == "Get" ? this.trade.MetaDic["ObservationRemark1"] : this.trade.MetaDic["ObservationRemark2"] : Comments;
|
|
Comments = Comments == undefined ? "" : Comments;
|
|
var calcMode = this.trade.trade_swap.RateCalcMode;
|
|
layer.open({
|
|
type: 2,
|
|
title: "设置互换日期",
|
|
shadeClose: false,
|
|
shade: 0.4,
|
|
area: ['500px', '560px'],
|
|
content: "/trade/tradeObservationDates?observationNum=" + observationNum + "&observationUnit=" + observationUnit + "&observationHolidayType=" + observationHolidayType + "&startTime=" + startTime + "&endTime=" + endTime + "&alignEnd=" + alignEnd + "&btnId=" + btnId + "&title1=互换利率&title2=&isTitle1Percent=true&isTitle2Percent=false&defaultTitle1Value=" + defaultSwapRate + "&defaultTitle2Value=0&hideTips=true&Comments=" + Comments + "&calcMode=" + calcMode + "&showCloseCheck=true" + "&ObservationFrequency=" + observationFrequency
|
|
});
|
|
},
|
|
getObservationDatesSetting(observationNum, observationUnit, observationHolidayType, observationDates, alignEnd, btnId, couponDayInterval, Comments, ObservationFrequency) {
|
|
let observation = {
|
|
ObservationNum: observationNum,
|
|
ObservationUnit: observationUnit,
|
|
ObservationHolidayType: observationHolidayType,
|
|
ObservationAlignEnd: alignEnd,
|
|
ObservationFrequency: ObservationFrequency
|
|
};
|
|
let observationUnitStr = "天";
|
|
switch (observationUnit) {
|
|
case "W": observationUnitStr = "周"; break;
|
|
case "M": observationUnitStr = "月"; break;
|
|
case "Y": observationUnitStr = "年"; break;
|
|
}
|
|
|
|
if (btnId == "Get") {
|
|
this.viewState.GetObservation = observation;
|
|
this.trade.trade_swap.GetSwapTimeAndRate = observationDates;
|
|
this.viewState.GetSwapTime = Comments;
|
|
if (observationDates != "" && observationDates != null && observationDates != undefined) {
|
|
var rates = observationDates.split(";");
|
|
var rate = rates[1].split(",")[0];
|
|
this.trade.trade_swap.GetSwapRate = rate;
|
|
var getObservations = this.trade.ExerciseDate + ";" + this.trade.trade_swap.GetSwapRate + ";false";
|
|
}
|
|
}
|
|
else {
|
|
this.viewState.PayObservation = observation;
|
|
this.trade.trade_swap.PaySwapTimeAndRate = observationDates;
|
|
this.viewState.PaySwapTime = Comments;
|
|
if (observationDates != "" && observationDates != null && observationDates != undefined) {
|
|
var rates = observationDates.split(";");
|
|
var rate = rates[1].split(",")[0];
|
|
this.trade.trade_swap.PaySwapRate = rate;
|
|
var payObervations = this.trade.ExerciseDate + ";" + this.trade.trade_swap.PaySwapRate + ";false";
|
|
}
|
|
}
|
|
let obUn = "";
|
|
let obViewStr = "";
|
|
if (observationDates != "") {
|
|
obUn = observationNum + observationUnit;
|
|
obViewStr = "每" + observationNum + observationUnitStr;
|
|
if (ObservationFrequency != "" && ObservationFrequency != null && ObservationFrequency != undefined) {
|
|
obUn += "|" + ObservationFrequency;
|
|
}
|
|
} else {
|
|
obUn = "TERM"
|
|
obViewStr = "";
|
|
}
|
|
if (btnId == "Get") {
|
|
$("#PayObservationRate").val("").attr("lang", "");
|
|
} else {
|
|
$("#GetObservationRate").val("").attr("lang", "");
|
|
}
|
|
$("#" + btnId + "ObservationRate").val(obViewStr).attr("lang", obUn);
|
|
},
|
|
checkSubmitData() {
|
|
//验证输入的日期格式是否正确(包括交易日期、开始日、到期日)
|
|
var ExerciseDate = this.trade.ExerciseDate;
|
|
var regTime = /^[0-9]{4}-[0-1]?[0-9]{1}-[0-3]?[0-9]{1}$/;
|
|
if (main.isEmpty(ExerciseDate)) {
|
|
main.message("请输入到期日期");
|
|
return false;
|
|
}
|
|
if (!regTime.test(ExerciseDate)) {
|
|
main.message("请输入正确的到期日期格式");
|
|
return false;
|
|
}
|
|
|
|
var TradeDate = this.trade.TradeDate;
|
|
if (main.isEmpty(TradeDate)) {
|
|
main.message("请输入成交日期");
|
|
return false;
|
|
}
|
|
if (!regTime.test(TradeDate)) {
|
|
main.message("请输入正确的成交日期格式");
|
|
return false;
|
|
}
|
|
|
|
if (TradeDate > ExerciseDate) {
|
|
main.message("到期日期不能早于成交日期");
|
|
return false;
|
|
}
|
|
|
|
var SettlementDate = this.trade.SettlementDate;
|
|
if (!main.isEmpty(SettlementDate) && regTime.test(ExerciseDate) && SettlementDate < ExerciseDate) {
|
|
main.message("结算日期不能早于到期日期");
|
|
return false;
|
|
}
|
|
|
|
var StartDate = this.trade.StartDate;
|
|
if (main.isEmpty(StartDate)) {
|
|
main.message("请输入开始日期");
|
|
return false;
|
|
}
|
|
|
|
if (main.isEmpty(StartDate)) {
|
|
main.message("请输入开始日期");
|
|
return false;
|
|
}
|
|
|
|
if (this.trade.trade_swap.IsGetFloatingProfit && main.isEmpty(this.trade.trade_swap.GetLongShort)) {
|
|
main.message("请选择多投空头");
|
|
return false;
|
|
}
|
|
if (this.trade.trade_swap.IsPayFloatingProfit && main.isEmpty(this.trade.trade_swap.PayLongShort)) {
|
|
main.message("请输入多投空头");
|
|
return false;
|
|
}
|
|
|
|
//if (this.trade.trade_swap.IsGetFloatingProfit && !this.trade.trade_swap.GetUnderlyingCode) {
|
|
// main.message("请设置收取标的信息");
|
|
// return false;
|
|
//}
|
|
|
|
//if (this.trade.trade_swap.IsPayFloatingProfit && !this.trade.trade_swap.PayUnderlyingCode) {
|
|
// main.message("请设置支付标的信息");
|
|
// return false;
|
|
//}
|
|
|
|
if (!this.trade.AssetId) {
|
|
main.message("请设置簿记账户");
|
|
return false;
|
|
}
|
|
|
|
if (!this.trade.ClientId) {
|
|
main.message("请设置交易对手方");
|
|
return false;
|
|
}
|
|
|
|
if (!this.trade.StockEqvNotional > 0 && this.trade.trade_swap.SwapType != "多空组合") {
|
|
main.message("请设置名义本金");
|
|
return false;
|
|
}
|
|
|
|
if (!this.trade.trade_swap.AnnualDays > 0) {
|
|
main.message("请设置年化天数");
|
|
return false;
|
|
}
|
|
if (!this.checkObservationDates()) {
|
|
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
checkObservationDates() {
|
|
var getSwapTimeRates = this.trade.trade_swap.GetSwapTimeAndRate || "";
|
|
var paySwapTimeRates = this.trade.trade_swap.PaySwapTimeAndRate || "";
|
|
var isget = this.trade.trade_swap.IsGetFloatingProfit;
|
|
var ispay = this.trade.trade_swap.IsPayFloatingProfit;
|
|
var checkGet = true;
|
|
var checkPay = true;
|
|
if (ispay && getSwapTimeRates.length > 0) {
|
|
checkGet = this.checkSwapTimeRates(getSwapTimeRates);
|
|
}
|
|
if (isget && paySwapTimeRates.length > 0) {
|
|
checkPay = this.checkSwapTimeRates(paySwapTimeRates);
|
|
}
|
|
if (!checkGet || !checkPay) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
checkSwapTimeRates(swapTimeRates) {
|
|
var StartDate = this.trade.StartDate;
|
|
var ExerciseDate = this.trade.ExerciseDate;
|
|
var fields = swapTimeRates.split(';').filter(o => o);
|
|
var fieldList0 = fields[0] ? fields[0].split(',') : null;
|
|
var check = true;
|
|
if (fieldList0) {
|
|
fieldList0.forEach(item => {
|
|
if (item.length > 10) {
|
|
item = (new Date(item)).Format("yyyy-MM-dd");
|
|
}
|
|
if (item < StartDate) {
|
|
main.message("互换观察日不可以早于交易开始日");
|
|
check = false;
|
|
} else if (item > ExerciseDate) {
|
|
main.message("互换观察日不可以晚于交易到期日");
|
|
check = false;
|
|
}
|
|
});
|
|
}
|
|
return check;
|
|
},
|
|
deleteItem: function (index, isForGet) {
|
|
if (isForGet) {
|
|
this.trade.get_trade_swap_details.splice(index, 1);
|
|
this.sumStockEqvNotional(true);
|
|
}
|
|
else {
|
|
this.trade.pay_trade_swap_details.splice(index, 1);
|
|
this.sumStockEqvNotional(false);
|
|
}
|
|
},
|
|
deleteAll: function (isForGet) {
|
|
if (isForGet) {
|
|
this.trade.get_trade_swap_details = [];
|
|
}
|
|
else {
|
|
this.trade.pay_trade_swap_details = [];
|
|
}
|
|
},
|
|
add: function (isForGet) {
|
|
if (isForGet) {
|
|
this.trade.get_trade_swap_details.push({ LongShort: "多头", UnderlyingCode: "", SpotPrice: "", Notional: "", TradePrice: "" });
|
|
}
|
|
else {
|
|
this.trade.pay_trade_swap_details.push({ LongShort: "多头", UnderlyingCode: "", SpotPrice: "", Notional: "", TradePrice: "" });
|
|
}
|
|
},
|
|
changePayUnderlying: function (data) {
|
|
this.trade.pay_trade_swap_details[data.index].SpotPrice = data.Price;
|
|
},
|
|
changeGetUnderlying: function (data) {
|
|
this.trade.get_trade_swap_details[data.index].SpotPrice = data.Price;
|
|
},
|
|
changeClient: function (client) {
|
|
this.trade.ClientId = client.id;
|
|
this.initMarginRate();
|
|
|
|
|
|
let selClient = consClients.find(x => x.id == client.id);
|
|
|
|
$("#IsCentralClearing").val(selClient.IsCentralClearing);
|
|
$("#CentralClearingPaltform").val(selClient.CentralClearingPaltform);
|
|
$("#TradingPaltform").val(selClient.TradingPaltform);
|
|
},
|
|
sumStockEqvNotional: function (isGet) {
|
|
var stockEqvNotional = 0;
|
|
if (isGet) {
|
|
this.trade.get_trade_swap_details.forEach(x => {
|
|
stockEqvNotional += x.SpotPrice * x.Notional;
|
|
});
|
|
}
|
|
else {
|
|
this.trade.pay_trade_swap_details.forEach(x => {
|
|
stockEqvNotional += x.SpotPrice * x.Notional;
|
|
});
|
|
}
|
|
this.trade.StockEqvNotional = stockEqvNotional;
|
|
},
|
|
sumTradePrice: function (isGet) {
|
|
var tradePrice = 0;
|
|
if (isGet) {
|
|
this.trade.get_trade_swap_details.forEach(x => {
|
|
tradePrice += x.TradePrice;
|
|
});
|
|
}
|
|
else {
|
|
this.trade.pay_trade_swap_details.forEach(x => {
|
|
tradePrice += x.TradePrice;
|
|
});
|
|
}
|
|
|
|
if (isGet && tradePrice > 0 || !isGet && tradePrice < 0) {
|
|
this.trade.trade_swap.PayTradePrice = Math.abs(tradePrice);
|
|
this.trade.trade_swap.GetTradePrice = 0;
|
|
}
|
|
else {
|
|
this.trade.trade_swap.GetTradePrice = Math.abs(tradePrice);
|
|
this.trade.trade_swap.PayTradePrice = 0;
|
|
}
|
|
},
|
|
initMarginRate() { //初始预付金 初始话
|
|
_that = this
|
|
console.log({ ClientId: this.trade.ClientId, Type: this.trade.trade_swap.SwapType, UnderlyingCode: this.trade.trade_swap.PayUnderlyingCode })
|
|
if ((page.isAdd || page.isHuaAn) && this.trade.ClientId != null && ((this.trade.trade_swap.SwapType == "普通" && this.trade.trade_swap.PayUnderlyingCode != null) || this.trade.trade_swap.SwapType == "多空组合")) {
|
|
main.post("/swapTrade/GetInitMarginRate", { ClientId: this.trade.ClientId, Type: this.trade.trade_swap.SwapType, UnderlyingCode: this.trade.trade_swap.PayUnderlyingCode, tradeDate: this.trade.TradeDate })
|
|
.done(function (resp) {
|
|
if (resp.obj > 0) {
|
|
_that.trade.trade_swap.GetMarginRate = resp.obj
|
|
}
|
|
});
|
|
}
|
|
},
|
|
//交易审批
|
|
submit(status) {
|
|
var pop = '';
|
|
if (status === 'pass') {
|
|
pop = "确认通过审批?";
|
|
}
|
|
if (status === 'reject') {
|
|
pop = "确认拒绝?";
|
|
}
|
|
var confirmFunc = function (additionalProcessing) {
|
|
var pData = { tradeId: page.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);
|
|
if (page.generateAmendDoc) {
|
|
if (data.obj && data.obj.generateChangeSuccess) {
|
|
main.downloadFiles(data.obj.url);
|
|
try { window.parent.reloadtrade(); } catch (e) { }
|
|
}
|
|
}
|
|
if (page.needSendChangeEmail) {
|
|
if (data.obj && data.obj.generateChangeSuccess) {
|
|
main.confirm("确认发送变更确认书?",
|
|
function () {
|
|
main.post("/trade/SendChangeConfirmEmails", { tradeids: tradeId }).done(
|
|
function (data) {
|
|
if (data.success) {
|
|
main.message("发送成功");
|
|
} else {
|
|
main.message(data.msg);
|
|
}
|
|
try {
|
|
window.parent.reloadtrade();
|
|
} catch (e) {
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
try {
|
|
window.parent.reloadtrade();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
try { window.parent.reloadtrade(); } catch (e) { }
|
|
}
|
|
if (parent) {
|
|
parent.layer.closeAll();
|
|
}
|
|
});
|
|
}
|
|
main.confirm(pop, confirmFunc);
|
|
}
|
|
},
|
|
computed: {
|
|
maxTradeDate() {
|
|
let exerciseDate = this.trade.ExerciseDate;
|
|
return exerciseDate && exerciseDate <= page.valuedate ? exerciseDate : page.valuedate;
|
|
},
|
|
},
|
|
components: {
|
|
'vue-datepicker': FastVue.vueDatePicker(),
|
|
'vue-number-input': FastVue.vueNumberInput(),
|
|
'vue-underlying': vueUnderlying()
|
|
},
|
|
destroyed() {
|
|
|
|
}
|
|
});
|
|
|
|
function __init(vue) {
|
|
//交易员
|
|
if (page.canAddNewTrader) {
|
|
autoTrader = FastVue.autocomplete(document.getElementById('TraderId'), {
|
|
nameField: 'Name', valueField: 'id', searchField: ['Name', 'PinYin'], lookup: consTraders,
|
|
onSelect(data) {
|
|
vue.trade.TraderId = data.id;
|
|
vue.trade.TraderName = data.Name;
|
|
}
|
|
});
|
|
let traderId = page.Trade.TraderId;
|
|
let trader = traderId ? consTraders.find(x => x.id === traderId) : null;
|
|
if (!trader && page.IsNew) {
|
|
trader = consTraders[0];
|
|
trader && (vue.trade.TraderId = trader.id);
|
|
}
|
|
autoTrader.setData(trader);
|
|
}
|
|
|
|
//簿记账户
|
|
let autoAssetUnit = FastVue.autocomplete(document.getElementById('AssetId'), {
|
|
nameField: 'Name', valueField: 'id', searchField: ['Name', 'PinYin'], lookup: consAssetUnits,
|
|
onSelect(data) {
|
|
vue.trade.AssetId = data.id;
|
|
}
|
|
});
|
|
let assetId = page.Trade.AssetId;
|
|
let asset = assetId ? consAssetUnits.find(x => x.id === assetId) : null;
|
|
if (!asset && page.IsNew) {
|
|
asset = consAssetUnits[0];
|
|
asset && (vue.trade.AssetId = asset.id);
|
|
}
|
|
autoAssetUnit.setData(asset);
|
|
|
|
salesCommissionCtrl = new SalesCommissionCtrl(document.getElementById('salesCommissionCtrl'), page.Trade.SalesCommission);
|
|
//客户名称
|
|
if (page.canChangeClient) {
|
|
let autoClient = FastVue.autocomplete(document.getElementById('ClientId'), {
|
|
nameField: 'Name', valueField: 'id', searchField: ['Name', 'PinYin'],
|
|
lookup: consClients, onSelect: function (rep) {
|
|
vue.changeClient(rep);
|
|
salesCommissionCtrl.changeSalesmen(rep.id);
|
|
|
|
_getMainProtocolCode(rep);
|
|
}
|
|
});
|
|
let clientId = page.Trade.ClientId;
|
|
let client = clientId ? consClients.find(x => x.id === clientId) : null;
|
|
!client && page.IsNew && (client = consClients[0]);
|
|
//setData 只写控件显示值、不触发 onSelect 回写 v-model——新增时默认客户须显式回写,否则 trade.ClientId 为空、保存报"请设置交易对手方"
|
|
client && page.IsNew && (vue.trade.ClientId = client.id);
|
|
autoClient.setData(client);
|
|
_getMainProtocolCode(client);
|
|
}
|
|
if (page.isGuoTou) {
|
|
if (page.Trade.TradeType !== "现金流交易" && page.Trade.TradeType !== "自定义交易") {
|
|
//预付金模板
|
|
autoMarginTemplateName = FastVue.autocomplete(document.getElementById('MarginTemplateName'), {
|
|
nameField: 'Text', valueField: 'Value', searchField: ['Text'], lookup: page.tradeMarginTemplateItems,
|
|
onSelect(data) {
|
|
vue.trade.MarginTemplateName = data.Value;
|
|
if (vue.trade.MarginTemplateName === "系统默认") {
|
|
vue.trade.MarginType = 0;
|
|
vue.trade.MarginRate = 0;
|
|
vue.trade.PositionMarginRate = 0;
|
|
}
|
|
else if (vue.trade.MarginTemplateName === "无预付金") {
|
|
vue.trade.MarginType = 1;
|
|
vue.trade.MarginRate = 0;
|
|
vue.trade.PositionMarginRate = 0;
|
|
}
|
|
else {
|
|
page.tradeMarginTemplates.forEach(x => {
|
|
if (vue.trade.MarginTemplateName === x.Name) {
|
|
vue.trade.MarginType = x.MarginType;
|
|
vue.trade.MarginRate = x.InitialMarginRatio;
|
|
if (vue.trade.MarginType == 3) {
|
|
vue.trade.PositionMarginRate = 0;
|
|
}
|
|
else {
|
|
vue.trade.PositionMarginRate = x.PositionMarginRatio;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
let marginTemplateName = page.Trade.MarginTemplateName;
|
|
let marginTemplate = marginTemplateName ? page.tradeMarginTemplateItems.find(x => x.Value === marginTemplateName) : null;
|
|
if (!marginTemplate && page.IsNew) {
|
|
marginTemplate = page.tradeMarginTemplateItems[0];
|
|
marginTemplate && (vue.trade.MarginTemplateName = marginTemplate.Value);
|
|
}
|
|
autoMarginTemplateName.setData(marginTemplate);
|
|
}
|
|
}
|
|
}
|
|
function _getMainProtocolCode(client) {
|
|
$("#MainProtocolCode option").remove();
|
|
if (client) {
|
|
let clientId = typeof client === 'object' ? client.id : client;
|
|
main.post("/Client/getMainProtocolCodes", { clientId: clientId }, { async: false }).done(function (resp) {
|
|
var obj = $("#MainProtocolCode");
|
|
_.forEach(resp, (v) => {
|
|
obj.append("<option >" + v.Text + "</option>");
|
|
})
|
|
});
|
|
}
|
|
$("#SupProtocolCode option").remove();
|
|
if ($("#MainProtocolCode").val()) {
|
|
main.post("/Client/getSideProtocols", { mainProtocol: $("#MainProtocolCode").val() }, { async: false }).done(function (resp) {
|
|
var obj = $("#SupProtocolCode");
|
|
_.forEach(resp, (v) => {
|
|
obj.append("<option >" + v + "</option>");
|
|
})
|
|
});
|
|
}
|
|
}
|
|
var getObservationDatesSetting = vue.getObservationDatesSetting;
|
|
function setGetUnderlyingCode(data) {
|
|
getCountRatio = data.CountRatio;
|
|
$("#trade_swap_GetUnderlyingId").val(data.id);
|
|
if (lastGetUnderlyingId !== data.id) {
|
|
vueDetails.getDetails = [];
|
|
}
|
|
let $i = $("#trade_swap\\.GetSpotPrice");
|
|
if (data.IsSynthetic) {
|
|
isGetSyntheticUnderlying = true;
|
|
$i.val('');
|
|
let TradeDate = $("#TradeDate").val();
|
|
getSyntheticPrices(data.Code, "组合标的", TradeDate);
|
|
} else {
|
|
isGetSyntheticUnderlying = false;
|
|
consMetaDic["组合标的"] = null;
|
|
let StartDate = $("#StartDate").val();
|
|
getSpotPrice(data.Code, "组合标的", StartDate);
|
|
changeStockEqvNotional();
|
|
}
|
|
$i.prop('readonly', data.IsSynthetic).next('.btn').toggle(!data.IsSynthetic);
|
|
}
|
|
function initUnderlyingCtrl() {
|
|
//let GetUnderlyingCodeCtrl = tradeHelper.UnderlyingAutoComplete('trade.trade_swap.GetUnderlyingCode', {
|
|
// SelectFlag: consUnderlyingFlag,
|
|
// OnSelect: vue.setGetUnderlyingCode,
|
|
// BlackLimit: 2
|
|
//});
|
|
|
|
//let PayUnderlyingCodeCtrl = tradeHelper.UnderlyingAutoComplete('trade.trade_swap.PayUnderlyingCode', {
|
|
// SelectFlag: consUnderlyingFlag,
|
|
// OnSelect: vue.setPayUnderlyingCode,
|
|
// BlackLimit: 2
|
|
//});
|
|
//组合标的控件
|
|
synthenticPriceCtrl.init({
|
|
getSynthetic(input) {
|
|
return consMetaDic[input.dataset.meta];
|
|
},
|
|
setSynthetic(input, synthetic) {
|
|
|
|
input.value = synthetic.Price;
|
|
consMetaDic[input.dataset.meta] = synthetic;
|
|
|
|
if (input.id == "trade_swap.GetSpotPrice") {
|
|
isGetSyntheticUnderlying = true;
|
|
getMaxPrice = 0;
|
|
synthetic.SuList.forEach((item, index) => getMaxPrice = Math.abs(item.Price * item.Coefficient) > getMaxPrice ? Math.abs(item.Price * item.Coefficient) : getMaxPrice);
|
|
var notional = getMaxPrice != 0 ? $("#StockEqvNotional").val() / getMaxPrice : 0;
|
|
// $("#trade_swap_GetNotional").val(otcformat.trading.notional(Math.abs(notional)));
|
|
var tradeAmount = notional / getCountRatio;
|
|
vue.trade.trade_swap.GetTradeAmount = otcformat.trading.notional(Math.abs(tradeAmount));
|
|
vue.trade.trade_swap.GetLot = otcformat.trading.notional(vue.trade.trade_swap.GetTradeAmount / getContractSize);
|
|
//$("#trade.trade_swap\\.GetTradeAmount").val(otcformat.trading.notional(Math.abs(tradeAmount)));
|
|
}
|
|
else {
|
|
isPaySyntheticUnderlying = true;
|
|
payMaxPrice = 0;
|
|
synthetic.SuList.forEach((item, index) => payMaxPrice = Math.abs(item.Price * item.Coefficient) > payMaxPrice ? Math.abs(item.Price * item.Coefficient) : payMaxPrice);
|
|
var notional = payMaxPrice != 0 ? $("#StockEqvNotional").val() / payMaxPrice : 0;
|
|
//$("#trade_swap_PayNotional").val(otcformat.trading.notional(Math.abs(notional)));
|
|
var tradeAmount = notional / payCountRatio;
|
|
vue.trade.trade_swap.PayTradeAmount = otcformat.trading.notional(Math.abs(tradeAmount));
|
|
vue.trade.trade_swap.PayLot = otcformat.trading.notional(vue.trade.trade_swap.PayTradeAmount / payContractSize);
|
|
}
|
|
}
|
|
});
|
|
|
|
if ('Price' in consMetaDic['组合标的']) {
|
|
$("#trade_swap\\.GetSpotPrice").prop('readonly', true).next('.btn').hide();
|
|
}
|
|
if ('Price' in consMetaDic['组合标的2']) {
|
|
$("#trade_swap\\.PaySpotPrice").prop('readonly', true).next('.btn').hide();
|
|
}
|
|
}
|
|
$(function () {
|
|
initUnderlyingCtrl();
|
|
|
|
initAutoCtrl(true);
|
|
|
|
$(".datepicker").change(function () {
|
|
var dateVal = $(this).val();
|
|
if (!dateVal) return;
|
|
dateVal = dateVal.replace(/\D/g, '').padStart(4, '0');
|
|
switch (dateVal.length) {
|
|
case 4:
|
|
dateVal = new Date().getFullYear() + dateVal; break;
|
|
case 6:
|
|
dateVal = '20' + dateVal; break;
|
|
case 8: break;
|
|
default:
|
|
dateVal = dateVal.length > 8 ? dateVal.substring(0, 8) : ''; break;
|
|
}
|
|
|
|
if (dateVal) {
|
|
dateVal = moment(dateVal).format('YYYY-MM-DD');
|
|
!/^\d+/.test(dateVal) && (dateVal = '');
|
|
}
|
|
|
|
$(this).datepicker("setDate", dateVal);
|
|
});
|
|
if (consMetaDic['组合标的'] && consMetaDic['组合标的'].SuList) {
|
|
consMetaDic['组合标的'].SuList.forEach((item, index) => getMaxPrice = Math.abs(item.Price * item.Coefficient) > getMaxPrice ? Math.abs(item.Price * item.Coefficient) : getMaxPrice);
|
|
if (getMaxPrice > 0) {
|
|
isGetSyntheticUnderlying = true;
|
|
}
|
|
}
|
|
|
|
if (consMetaDic['组合标的2'] && consMetaDic['组合标的2'].SuList) {
|
|
consMetaDic['组合标的2'].SuList.forEach((item, index) => payMaxPrice = Math.abs(item.Price * item.Coefficient) > payMaxPrice ? Math.abs(item.Price * item.Coefficient) : payMaxPrice);
|
|
if (payMaxPrice > 0) {
|
|
isPaySyntheticUnderlying = true;
|
|
}
|
|
}
|
|
}); |