- flags 新增 StockIF: 1 << (i++)(之前定义但__getPostData漏映射)和 Fund: 1 << (i++) - __getPostData 新增 StockIF→'StockIF'、Fund→'Fund' 映射 - 修复511380等股指标的/基金标的在新版互换交易下拉框无法检索的问题
735 lines
30 KiB
JavaScript
735 lines
30 KiB
JavaScript
//tradeHelper
|
|
(function () {
|
|
|
|
function tradeHelper() { }
|
|
|
|
//期权类型{ value: "彩虹期权", pinyin: 'CHQQ' },
|
|
tradeHelper.OptionTradeTypes = Object.freeze([{ value: "香草期权", pinyin: 'XCQQ' }
|
|
, { value: "障碍期权", pinyin: 'ZAQQ' }, { value: "二元期权", pinyin: 'EYQQ' }
|
|
, { value: "亚式期权", pinyin: 'YSQQ' }, { value: "合成价差期权", pinyin: 'HCJCQQ' }
|
|
, { value: "双鲨期权", pinyin: 'SSQQ' }, { value: "区间累积期权", pinyin: 'QJLJQQ' }
|
|
, { value: "凤凰期权", pinyin: 'FHQQ' }, { value: "雪球期权", pinyin: 'XQQQ' }
|
|
, { value: "气囊结构", pinyin: 'QNJG' }, { value: "收益增强结构", pinyin: 'SYZQJG' }
|
|
, { value: "现金流交易", pinyin: 'XJLJY' }, { value: "Risky期权", pinyin: 'RiskyQQ' }
|
|
, { value: "累计期权", pinyin: 'LJQQ' }
|
|
]);
|
|
|
|
//标的资产类型{ value: 'StockIF', text: '股指期货' }
|
|
tradeHelper.InstrumentTypes = Object.freeze([{ value: 'CommodityFutures', text: '商品期货' }
|
|
, { value: 'CommoditySpot', text: '商品现货' }, { value: 'Stock', text: '股票' }, { value: 'StockIndex', text: '股指' }
|
|
, { value: 'StockIF', text: '股指期货' }, { value: "CreditBonds", text: '信用债' }, { value: "Bonds", text: '利率债' }, { value: "TBonds", text: '利率债' }, { value: "OtherBonds", text: '其它债券' }]);
|
|
|
|
//行权方式
|
|
tradeHelper.ExerciseModes = [{ value: 'European', text: '欧式' }, { value: 'American', text: '美式' }];
|
|
|
|
//看涨看跌
|
|
tradeHelper.OptionTypes = Object.freeze([{ value: '看涨', text: '看涨' }, { value: '看跌', text: '看跌' }]);
|
|
|
|
//收益结算
|
|
tradeHelper.SettlementTypes = Object.freeze([{ value: '0', text: '收盘价' }, { value: '1', text: '结算价' }, { value: '2', text: '参考价' }]);
|
|
|
|
//根据名义本金获取有效名义本金
|
|
tradeHelper.GetStockEqvNotionalReal = function (stockEqvNotional, participationRate, annualizeFactor) {
|
|
stockEqvNotional = parseFloat(stockEqvNotional) || 0; //名义本金
|
|
annualizeFactor = annualizeFactor ? parseFloat(annualizeFactor) || 0 : 1; //年化系数
|
|
participationRate = participationRate ? parseFloat(participationRate) || 0 : 1; //参与率
|
|
return stockEqvNotional * participationRate * annualizeFactor;
|
|
}
|
|
|
|
//根据有效名义本金获取名义本金
|
|
tradeHelper.GetStockEqvNotional = function (stockEqvNotionalReal, participationRate, annualizeFactor) {
|
|
stockEqvNotionalReal = parseFloat(stockEqvNotionalReal) || 0; //名义本金
|
|
annualizeFactor = annualizeFactor ? parseFloat(annualizeFactor) || 0 : 1; //年化系数
|
|
participationRate = participationRate ? parseFloat(participationRate) || 0 : 1; //参与率
|
|
return participationRate > 0 && annualizeFactor > 0 ? stockEqvNotionalReal / participationRate / annualizeFactor : 0;
|
|
}
|
|
|
|
//根据权利金总额获取期权费率
|
|
tradeHelper.GetPremiumRateByTradePrice = function (tradePrice, stockEqvNotional, participationRate, principalSum, annualizeFactor, buySell, tradeType, isOpen) {
|
|
var absTradePrice = Math.abs(tradePrice) || 0; //交易总额
|
|
stockEqvNotional = parseFloat(stockEqvNotional) || 0; //名义本金
|
|
principalSum = parseFloat(principalSum) || 0; //保底收益总额
|
|
annualizeFactor = annualizeFactor ? parseFloat(annualizeFactor) || 0 : 1; //年化系数
|
|
participationRate = participationRate ? parseFloat(participationRate) || 0 : 1; //参与率
|
|
if (!isOpen) {
|
|
return stockEqvNotional > 0 && annualizeFactor > 0 && participationRate > 0
|
|
? (tradePrice - principalSum * (buySell === "卖出" ? -1 : 1)) / stockEqvNotional / annualizeFactor / participationRate : 0;
|
|
}
|
|
else {
|
|
return stockEqvNotional > 0 && annualizeFactor > 0 && participationRate > 0
|
|
? (absTradePrice - principalSum) / stockEqvNotional / annualizeFactor / participationRate : 0;
|
|
}
|
|
}
|
|
|
|
//根据权利金单价获取期权费率
|
|
tradeHelper.GetPremiumRateByTradeSinglePrice = function (tradeSinglePrice, spotPrice) {
|
|
spotPrice = Math.abs(spotPrice) || 0;
|
|
return spotPrice > 0 ? tradeSinglePrice / spotPrice : 0;
|
|
}
|
|
|
|
//根据交易总额获取权利金单价
|
|
tradeHelper.GetTradeSinglePriceByTradePrice = function (tradePrice, stockEqvNotional, notional, principalSum, annualizeFactor, buySell, tradeType, isOpen) {
|
|
notional = parseFloat(notional); //交易份额
|
|
if (notional < 1e-6) return 0;
|
|
var absTradePrice = Math.abs(tradePrice) || 0; //交易总额
|
|
stockEqvNotional = parseFloat(stockEqvNotional) || 0; //名义本金
|
|
principalSum = parseFloat(principalSum) || 0; //保底收益率
|
|
annualizeFactor = annualizeFactor ? parseFloat(annualizeFactor) || 0 : 1; //年化系数
|
|
if (!isOpen) {
|
|
return (tradePrice - principalSum * (buySell === "卖出" ? -1 : 1)) / notional;
|
|
}
|
|
else {
|
|
return (absTradePrice - principalSum) / notional;
|
|
}
|
|
}
|
|
|
|
//根据期权费率获取权利金单价
|
|
tradeHelper.GetTradeSinglePriceByPremiumRate = function (premiumRate, spotPrice) {
|
|
return Math.abs(spotPrice) * premiumRate || 0;
|
|
}
|
|
|
|
//根据权利金单价获取交易总额
|
|
tradeHelper.GetTradePriceBySinglePrice = function (tradeSinglePrice, stockEqvNotional, notional, principalSum, annualizeFactor, buySell, tradeType, isOpen) {
|
|
//var absTradeSinglePrice = tradeSinglePrice || 0; //单价
|
|
notional = parseFloat(notional) || 0; //交易份额
|
|
stockEqvNotional = parseFloat(stockEqvNotional) || 0; //名义本金
|
|
principalSum = parseFloat(principalSum) || 0; //保底收益总额
|
|
annualizeFactor = annualizeFactor ? parseFloat(annualizeFactor) || 0 : 1; //年化系数
|
|
if (!isOpen) {
|
|
return tradeSinglePrice * notional + principalSum * (buySell === "卖出" ? -1 : 1);
|
|
}
|
|
else {
|
|
return tradeSinglePrice * notional + principalSum;
|
|
}
|
|
}
|
|
|
|
//根据期权费率获取交易总额
|
|
tradeHelper.GetTradePriceByPremiumRate = function (premiumRate, stockEqvNotional, participationRate, principalSum, annualizeFactor, buySell, tradeType, isOpen) {
|
|
stockEqvNotional = parseFloat(stockEqvNotional) || 0; //名义本金
|
|
participationRate = participationRate ? parseFloat(participationRate) || 0 : 1; //参与率
|
|
principalSum = parseFloat(principalSum) || 0; //保底收益率
|
|
annualizeFactor = annualizeFactor ? parseFloat(annualizeFactor) || 0 : 1; //年化系数
|
|
if (!isOpen) {
|
|
return premiumRate * participationRate * stockEqvNotional * annualizeFactor + principalSum * (buySell === "卖出" ? -1 : 1);
|
|
}
|
|
else {
|
|
//let absPremiumRate = Math.abs(premiumRate) || 0; //期权费率
|
|
return premiumRate * participationRate * stockEqvNotional * annualizeFactor + principalSum;
|
|
}
|
|
}
|
|
|
|
tradeHelper.GetTradeStatus = function (trade, tradeCash) {
|
|
if (tradeCash.Action === "系统操作-平仓费" && (tradeCash.UnwindType === "部分平仓" || tradeCash.UnwindType === "全部平仓")) {
|
|
return "已平仓";
|
|
}
|
|
if (tradeCash.Action === "系统操作-行权费" && tradeCash.ExerciseWay === "到期行权" && tradeCash.UnwindType === "到期") {
|
|
return "已到期";
|
|
}
|
|
if ((tradeCash.Action === "系统操作-平仓费" && tradeCash.UnwindType === "部分行权") || tradeCash.Action === "系统操作-行权费") {
|
|
return "已行权";
|
|
}
|
|
return trade.TradeStatus;
|
|
}
|
|
|
|
//空的品种数据
|
|
tradeHelper.getEmptyVariety = function (instType) {
|
|
return { id: 0, Code: "", Name: "", InstrumentType: instType || "", TradeUnit: "", QuoteUnit: "", CountRatio: 1, PriceTick: 1, ContractSize: 1, QuoteCurrency: "" };
|
|
};
|
|
|
|
//空的标的数据
|
|
tradeHelper.getEmptyUnderlying = function (varietyId) {
|
|
return { id: 0, Code: "", Name: "", VarietyId: varietyId || 0, InstrumentType: '', QuoteUnitString: "" };
|
|
};
|
|
|
|
//根据有效成交(持仓)份额获取成交(持仓)数量(如果notional传入份额,这时countRatio可以不传值,如果notional传入数量,这时countRatio传1)
|
|
tradeHelper.getTradeAmountV = function (trade, notional, countRatio) {
|
|
if (!trade) return '';
|
|
if (trade.TradeType === '累计期权') {
|
|
return (tradeHelper.IsNumber(notional) ? notional : 0 || trade.OriginalNotional || 0) / (countRatio || trade.CountRatio || 1);
|
|
}
|
|
if (trade.SpotPrice && !Number.isFinite(notional)) {
|
|
return trade.OriginalStockEqvNotional / Math.abs(trade.SpotPrice) / (countRatio || trade.CountRatio || 1);
|
|
}
|
|
var participationRate = trade.ParticipationRate;
|
|
if (!_.trim(participationRate)) {
|
|
participationRate = 1;
|
|
}
|
|
var annRate = participationRate * trade.AnnualizeFactor;
|
|
return (tradeHelper.IsNumber(notional) ? notional : 0 || trade.OriginalNotional || 0) / (annRate || 1) / (countRatio || trade.CountRatio || 1);
|
|
};
|
|
//成交数量
|
|
tradeHelper.geTradeAmountFormat = function (cellvalue, options, rowObject) {
|
|
var amount = Math.abs(tradeHelper.getTradeAmountV(rowObject));
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? amount * (rowObject.CountRatio || 1) : amount);
|
|
}
|
|
|
|
tradeHelper.getNotionalFormat = function (cellvalue, options, rowObject) {
|
|
cellvalue = Math.abs(cellvalue || 0);
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? cellvalue * (rowObject.CountRatio || 1) : cellvalue);
|
|
}
|
|
//保留两位小数
|
|
tradeHelper.getNotionalFormatByDouble = function (cellvalue, options, rowObject) {
|
|
var notional = page.IsUseDisplayNotional ? cellvalue * (rowObject.CountRatio || 1) : cellvalue;
|
|
return notional ? notional.toFixed(2) : "0.00";
|
|
}
|
|
|
|
//存续数量
|
|
tradeHelper.getTradeAmountVFormat = function (cellValue, options, rowObject) {
|
|
if (rowObject.TradeStatus === page.trade_yizhixing || rowObject.TradeStatus === page.trade_yidaoqi || rowObject.TradeStatus === page.trade_yipingcang) {
|
|
return otcformat.trading.notional(0);
|
|
}
|
|
else {
|
|
var amount = Math.abs(tradeHelper.getTradeAmountV(rowObject, rowObject.TradeAmount, 1));
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? amount * (rowObject.CountRatio || 1) : amount);
|
|
}
|
|
}
|
|
//持仓数量
|
|
tradeHelper.getTradeAmountPositionFormat = function (cellValue, options, rowObject) {
|
|
var amount = Math.abs(tradeHelper.getTradeAmountV(rowObject.trade || rowObject, rowObject.TradeAmount, 1));
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? amount * (rowObject.CountRatio || 1) : amount);
|
|
}
|
|
//有效持仓数量
|
|
tradeHelper.getTradeAmountValidPositionFormat = function (cellValue, options, rowObject) {
|
|
if (rowObject.trade.TradeType == "现金流交易") {
|
|
return "";
|
|
}
|
|
else {
|
|
cellvalue = Math.abs(cellvalue || 0);
|
|
return tradeHelper.geTradeAmountFormat(cellValue, options, rowObject);
|
|
|
|
}
|
|
}
|
|
//终止数量
|
|
tradeHelper.getUnwindTradeAmountFormat = function (cellValue, options, rowObject) {
|
|
var amount = rowObject.trade_cash.Action === "系统操作-行权费" ? rowObject.trade_cash.TradeAmount : rowObject.trade_cash.UnwindTradeAmount;
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? amount * (rowObject.CountRatio || 1) : amount);
|
|
}
|
|
|
|
//到期数量
|
|
tradeHelper.getExpireTradeAmountFormat = function (cellValue, options, rowObject) {
|
|
var amount = 0;
|
|
if (rowObject.trade_cash == null) {
|
|
amount = rowObject.TradeAmount;
|
|
} else {
|
|
amount = rowObject.trade_cash.TradeAmount == null || rowObject.trade_cash.TradeAmount == null ? 0 : rowObject.trade_cash.TradeAmount;
|
|
}
|
|
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? amount * (rowObject.CountRatio || 1) : amount);
|
|
}
|
|
|
|
//将数量转化为份额,只修改formatter 显示值
|
|
tradeHelper.getAmountToNotional = function (colModelGrid) {
|
|
if (page.IsUseDisplayNotional) {
|
|
colModelGrid.forEach(a => {
|
|
switch (a.label) {
|
|
case "成交数量":
|
|
a.formatter = tradeHelper.geTradeAmountFormat;
|
|
break;
|
|
case "有效成交数量":
|
|
case "了结数量":
|
|
case "敲出数量":
|
|
case "交易数量":
|
|
case "[收取]交易数量":
|
|
case "[支付]交易数量":
|
|
case "有效存续数量":
|
|
case "交易数量":
|
|
case "有效数量":
|
|
a.formatter = tradeHelper.getNotionalFormat;
|
|
break;
|
|
case "存续数量":
|
|
a.formatter = tradeHelper.getTradeAmountVFormat;
|
|
break;
|
|
case "持仓数量":
|
|
a.formatter = tradeHelper.getTradeAmountPositionFormat;
|
|
break;
|
|
case "有效持仓数量":
|
|
case "有效交易数量":
|
|
a.formatter = tradeHelper.getTradeAmountValidPositionFormat;
|
|
break;
|
|
//case "终止数量":
|
|
// a.formatter = tradeHelper.getUnwindTradeAmountFormat;
|
|
//case "提前终止数量":
|
|
// a.formatter = tradeHelper.getUnwindTradeAmountFormat;
|
|
// break;
|
|
case "到期数量":
|
|
a.formatter = tradeHelper.getExpireTradeAmountFormat;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
return colModelGrid;
|
|
}
|
|
|
|
tradeHelper.IsNumber = function (n) {
|
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
}
|
|
|
|
tradeHelper.IsCodesExistsCommoditySpot = function (codes) {
|
|
var flag = false;
|
|
main.post("/trade/IsCodesExistsCommoditySpot", { codes: codes }, { async: false }).done(function (res) {
|
|
flag = res.obj;
|
|
});
|
|
return flag;
|
|
}
|
|
tradeHelper.IsBond = function (instType) {
|
|
switch (instType) {
|
|
case "Bonds":
|
|
case "TBonds":
|
|
case "CreditBonds":
|
|
case "OtherBonds":
|
|
return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
window.tradeHelper = tradeHelper;
|
|
}());
|
|
|
|
//标的选择
|
|
(function (global) {
|
|
|
|
//标的选择组合过滤选项
|
|
const SelectFlag = (function () {
|
|
let i = 0;
|
|
let flags = {
|
|
None: 0,
|
|
Stock: 1 << (i++),
|
|
StockIndex: 1 << (i++),
|
|
StockIF: 1 << (i++),
|
|
CreditBonds: 1 << (i++),
|
|
Bonds: 1 << (i++),
|
|
TBonds: 1 << (i++),
|
|
OtherBonds: 1 << (i++),
|
|
CommodityFutures: 1 << (i++),
|
|
CommoditySpot: 1 << (i++),
|
|
UseRightFilter: 1 << (i++),
|
|
IncludeSynthetic: 1 << (i++),
|
|
OnlySynthetic: 1 << (i++),
|
|
CheckLaunch: 1 << (i++),
|
|
UsePinYinFilter: 1 << (i++),
|
|
IncludeMatured: 1 << (i++),
|
|
UseForTrading: 1 << (i++),
|
|
IncludeBasket: 1 << (i++),
|
|
OnlyBasket: 1 << (i++),
|
|
Fund: 1 << (i++)
|
|
};
|
|
flags.OtcTrade = flags.UsePinYinFilter | flags.IncludeMatured | flags.IncludeSynthetic | flags.IncludeBasket;
|
|
flags.OtcForward = flags.UsePinYinFilter | flags.IncludeMatured | flags.IncludeBasket | flags.CommodityFutures | flags.StockIF | flags.CommoditySpot;
|
|
return Object.freeze(flags);
|
|
}());
|
|
|
|
global.UnderlyingSelectFlag = SelectFlag;
|
|
|
|
const AjaxUrl = '/frontdata/AjaxGetUnderlyingSelect';
|
|
|
|
//默认选项(UnderlyingSelectService)
|
|
const DefaultOptions = {
|
|
ClientId: 0,
|
|
VarietyId: 0,
|
|
BlackLimit: 0,
|
|
MaxShowLength: 20,
|
|
SelectFlag: SelectFlag.None,
|
|
UseCodeAsId: false,
|
|
UseAll: false,//是否添加全部选项
|
|
Scenario: '', //使用场景
|
|
UseSignle: false,
|
|
MinMaturityDate: null,
|
|
InstrumentTypes:[],
|
|
};
|
|
|
|
//控件基类
|
|
function ControlBase(options) {
|
|
|
|
this.options = $.extend({}, DefaultOptions, options);
|
|
|
|
//设置选项
|
|
this.setFlag = function (flag) {
|
|
this.setOptions({ SelectFlag: parseInt(flag) || 0 });
|
|
return this;
|
|
};
|
|
|
|
this.getFlag = function () {
|
|
return this.options.SelectFlag;
|
|
};
|
|
//设置选项
|
|
if (!this.setOptions) {
|
|
this.setOptions = function (newOptions) {
|
|
this.options = $.extend({}, this.options, newOptions);
|
|
return this;
|
|
};
|
|
}
|
|
|
|
function __getPostData() {
|
|
let options = this.options;
|
|
let sf = options.SelectFlag;
|
|
let instrumentTypes = Array.isArray(options.InstrumentTypes) ? options.InstrumentTypes.slice() : [];
|
|
(sf & SelectFlag.Stock) > 0 && (instrumentTypes.push('Stock'));
|
|
(sf & SelectFlag.StockIndex) > 0 && (instrumentTypes.push('StockIndex'));
|
|
(sf & SelectFlag.StockIF) > 0 && (instrumentTypes.push('StockIF'));
|
|
(sf & SelectFlag.CommodityFutures) > 0 && (instrumentTypes.push('CommodityFutures'));
|
|
(sf & SelectFlag.CommoditySpot) > 0 && (instrumentTypes.push('CommoditySpot'));
|
|
(sf & SelectFlag.CreditBonds) > 0 && (instrumentTypes.push('CreditBonds'));
|
|
(sf & SelectFlag.Bonds) > 0 && (instrumentTypes.push('Bonds'));
|
|
(sf & SelectFlag.TBonds) > 0 && (instrumentTypes.push('TBonds'));
|
|
(sf & SelectFlag.OtherBonds) > 0 && (instrumentTypes.push('OtherBonds'));
|
|
(sf & SelectFlag.Fund) > 0 && (instrumentTypes.push('Fund'));
|
|
return {
|
|
FilterCode: '{{{q}}}',
|
|
ClientId: options.ClientId,
|
|
VarietyId: options.VarietyId,
|
|
BlackLimit: options.BlackLimit,
|
|
MaxShowLength: options.MaxShowLength,
|
|
InstrumentTypes: instrumentTypes,
|
|
UsePinYinFilter: (sf & (SelectFlag.UsePinYinFilter | SelectFlag.Stock | SelectFlag.StockIndex)) > 0,
|
|
IncludeMatured: (sf & SelectFlag.IncludeMatured) > 0,
|
|
OnlySynthetic: (sf & SelectFlag.OnlySynthetic) > 0,
|
|
IncludeSynthetic: (sf & SelectFlag.IncludeSynthetic) > 0,
|
|
CheckLaunch: (sf & SelectFlag.CheckLaunch) > 0,
|
|
UseForTrading: (sf & SelectFlag.UseForTrading) > 0,
|
|
IncludeBasket: (sf & SelectFlag.IncludeBasket) > 0,
|
|
OnlyBasket: (sf & SelectFlag.OnlyBasket) > 0,
|
|
MinMaturityDate: this.MinMaturityDate
|
|
};
|
|
}
|
|
|
|
//获取请求参数
|
|
this.getPostData = __getPostData.bind(this);
|
|
}
|
|
|
|
function UnderlyingSelectCtrl() {
|
|
|
|
function __init(el) {
|
|
var thisOptions = this.options;
|
|
$(el).selectpicker({
|
|
liveSearch: true,
|
|
selectAllText: '全选',
|
|
deselectAllText: '全不选',
|
|
actionsBox: true
|
|
}).ajaxSelectPicker({
|
|
ajax: {
|
|
url: AjaxUrl,
|
|
data: this.getPostData
|
|
},
|
|
locale: {
|
|
currentlySelected: '已选择',
|
|
emptyTitle: '',
|
|
errorText: '',
|
|
searchPlaceholder: '',
|
|
statusInitialized: '搜索选择标的',
|
|
statusNoResults: '没有结果',
|
|
statusSearching: '',
|
|
statusTooShort: ''
|
|
},
|
|
preprocessData: function (data) {
|
|
data.obj.unshift({ 'Code': '---', 'id': '', 'Name': '' });
|
|
return _.map(data.obj, x => {
|
|
return { 'value': thisOptions.UseCodeAsId ? x.Code : x.id, 'text': x.Code, 'data': { 'subtext': x.Name } };
|
|
});
|
|
},
|
|
minLength: 2,
|
|
requestDelay: 600
|
|
});
|
|
};
|
|
|
|
this.init = function (el, options) {
|
|
|
|
ControlBase.call(this, options);
|
|
|
|
el = FastVue.getDomElement(el);
|
|
|
|
if (!el) {
|
|
throw '[UnderlyingSelectCtrl]not found html element';
|
|
}
|
|
|
|
__init.call(this, el);
|
|
|
|
return this;
|
|
}
|
|
|
|
this.dispose = function () {
|
|
$(_el).autocomplete('dispose');
|
|
};
|
|
}
|
|
|
|
//标的选择控件
|
|
global.UnderlyingSelectCtrl = function (el, options) {
|
|
|
|
return new UnderlyingSelectCtrl().init(el, options);
|
|
};
|
|
|
|
//标的自动完成
|
|
function UnderlyingAutoComplete() {
|
|
|
|
var _el, _onSelectFn, _emptyUnderlying = tradeHelper.getEmptyUnderlying(), _options;
|
|
|
|
function __init() {
|
|
|
|
let opts = {
|
|
serviceUrl: AjaxUrl,
|
|
minChars: 0,
|
|
deferRequestBy: 600,
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
paramName: 'FilterCode',
|
|
params: this.getPostData(),
|
|
onSearchError: function (query, jqXHR, textStatus, errorThrown) {
|
|
console.log('查询出错');
|
|
},
|
|
formatResult(suggestion, currentValue) {
|
|
return '<span class="text">' + suggestion.value + '<small class="text-muted">' + suggestion.data.Name + '</small></span>';
|
|
},
|
|
transformResult: function (resp, originalQuery) {
|
|
if (resp.success !== true) {
|
|
main.alert(resp.msg);
|
|
return { suggestions: [] };
|
|
}
|
|
if (_options.UseAll) {
|
|
resp.obj.splice(0, 0, { Code: _options.UseSignle?"--": "全部", Name: "", id: 0 });
|
|
}
|
|
return {
|
|
suggestions: resp.obj.map(x => {
|
|
return { value: x.Code, data: x };
|
|
})
|
|
};
|
|
},
|
|
onSelect(suggestion) {
|
|
if (suggestion.data.Disallow) {
|
|
if (suggestion.data.IsSynthetic || suggestion.data.IsBasket) {
|
|
main.alert(suggestion.data.BlackWhiteState === 1 ? "该组合中包含存在于黑名单的标的" : "该组合中包含不在白名单中的标的");
|
|
}
|
|
else {
|
|
main.alert(suggestion.data.BlackWhiteState === 1 ? "该标的存在于黑名单中" : "该标的不在白名单中");
|
|
$(this).val($(this).attr("placeholder"));
|
|
return;
|
|
}
|
|
}
|
|
$(this).data('select', '1');
|
|
_onSelectFn && _onSelectFn(suggestion.data);
|
|
},
|
|
};
|
|
|
|
$(_el).autocomplete('dispose').on('focus', function () {
|
|
$(this).data('select', '').attr("placeholder", $(this).val()).val('');
|
|
}).on('blur', function () {
|
|
!$(this).data('select') && $(this).val($(this).attr("placeholder"));
|
|
}).on('keydown', function (event) {
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
$(this).blur();
|
|
}
|
|
}).autocomplete(opts);
|
|
};
|
|
|
|
this.init = function (el, options) {
|
|
|
|
ControlBase.call(this, options);
|
|
|
|
_options = this.options;
|
|
|
|
_onSelectFn = this.options.onSelect || this.options.OnSelect;
|
|
|
|
_el = FastVue.getDomElement(el);
|
|
|
|
if (!_el) {
|
|
throw '[UnderlyingAutoComplete]not found html element';
|
|
}
|
|
|
|
__init.call(this);
|
|
|
|
return this;
|
|
};
|
|
|
|
//设置输入值
|
|
this.setValue = function (value) {
|
|
_el.value = typeof value === 'undefined' ? '' : '' + value;
|
|
};
|
|
|
|
this.setData = function (data) {
|
|
if (typeof data === 'object') {
|
|
_el.value = data.Code || '';
|
|
} else if (typeof data !== 'undefined') {
|
|
_el.value = '' + data;
|
|
} else {
|
|
_el.value = '';
|
|
}
|
|
};
|
|
|
|
//选择时的回调处理
|
|
this.onSelect = function (fn) {
|
|
typeof fn === 'function' && (this.options.onSelect = _onSelectFn = fn);
|
|
return this;
|
|
};
|
|
|
|
//根据品种(首选,也可以是对象)选择第一个匹配项
|
|
this.selectFirst = function (data) {
|
|
let postData = this.getPostData();
|
|
postData.VarietyId = 0;
|
|
postData.FilterCode = '';
|
|
if (data) {
|
|
postData = Object.assign(postData, typeof data === 'object' ? data : { VarietyId: parseInt(data) || 0 });
|
|
}
|
|
postData.MaxShowLength = 1;
|
|
return main.post(AjaxUrl, postData).done(function (resp) {
|
|
let obj = resp.obj[0] || _emptyUnderlying;
|
|
_el.value = obj.Code;
|
|
_onSelectFn && _onSelectFn(obj);
|
|
});
|
|
};
|
|
|
|
//使用标的代码精确匹配
|
|
this.selectByCode = function (code) {
|
|
let postData = {
|
|
FilterCode: code, ExcatCodeFilter: true,
|
|
UseForTrading: (this.options.SelectFlag & SelectFlag.UseForTrading) > 0
|
|
};
|
|
return main.post(AjaxUrl, postData).done(function (resp) {
|
|
let obj = resp.obj[0] || _emptyUnderlying;
|
|
_el.value = obj.Code;
|
|
_onSelectFn && _onSelectFn(obj);
|
|
});
|
|
};
|
|
|
|
//使用标的ID精确匹配
|
|
this.selectById = function (underlyingId) {
|
|
let postData = { UnderlyingId: underlyingId };
|
|
return main.post(AjaxUrl, postData).done(function (resp) {
|
|
let obj = resp.obj[0] || _emptyUnderlying;
|
|
_el.value = obj.Code;
|
|
_onSelectFn && _onSelectFn(obj);
|
|
});
|
|
};
|
|
|
|
//配置过滤选项
|
|
this.setFlag = function (flag) {
|
|
this.options.SelectFlag = parseInt(flag) || 0;
|
|
$(_el).autocomplete('setOptions', { params: this.getPostData() });
|
|
return this;
|
|
};
|
|
|
|
//配置过滤选项
|
|
this.setVarietyId = function (varietyId) {
|
|
this.options.VarietyId = parseInt(varietyId) || 0;
|
|
$(_el).autocomplete('setOptions', { params: this.getPostData() });
|
|
return this;
|
|
};
|
|
|
|
//配置过滤选项
|
|
this.setOptions = function (newOptions) {
|
|
this.options = $.extend({}, this.options, newOptions);
|
|
$(_el).autocomplete('setOptions', { params: this.getPostData() });
|
|
_onSelectFn = this.options.onSelect;
|
|
return this;
|
|
};
|
|
|
|
//清除查询缓存
|
|
this.clearCache = function () {
|
|
$(_el).autocomplete('clearCache');
|
|
};
|
|
|
|
this.dispose = function () {
|
|
$(_el).autocomplete('dispose');
|
|
};
|
|
}
|
|
|
|
//标的自动完成(jquery.autocomplete)
|
|
global.UnderlyingAutoComplete = function (el, options) {
|
|
return new UnderlyingAutoComplete().init(el, options);
|
|
};
|
|
|
|
}(window.tradeHelper));
|
|
|
|
//场内期权选择
|
|
(function (global) {
|
|
|
|
const AjaxUrl = '/exchange_list_option/getoptionbycode';
|
|
|
|
function ExchangeOptionAutoComplete() {
|
|
|
|
let _el, _onSelectFn;
|
|
|
|
function __init() {
|
|
|
|
let opts = {
|
|
lookup: [],
|
|
minChars: 0,
|
|
onSelect(suggestion) {
|
|
$(this).data('select', '1');
|
|
_onSelectFn && _onSelectFn(suggestion.data);
|
|
},
|
|
showNoSuggestionNotice: true, noSuggestionNotice: '未找到'
|
|
};
|
|
|
|
$(_el).autocomplete('dispose').on('focus', function () {
|
|
$(this).data('select', '').attr("placeholder", $(this).val()).val('');
|
|
}).on('blur', function () {
|
|
!$(this).data('select') && $(this).val($(this).attr("placeholder"));
|
|
}).on('keydown', function (event) {
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
$(this).blur();
|
|
}
|
|
}).autocomplete(opts);
|
|
};
|
|
|
|
this.init = function (el) {
|
|
_el = FastVue.getDomElement(el);
|
|
if (!_el) {
|
|
throw '[ExchangeOptionAutoComplete]not found html element';
|
|
}
|
|
__init.call(this);
|
|
return this;
|
|
};
|
|
|
|
//设置输入值
|
|
this.setValue = function (value) {
|
|
_el.value = value;
|
|
};
|
|
|
|
this.setData = this.setValue; //别名
|
|
|
|
//选择时的回调处理
|
|
this.onSelect = function (fn) {
|
|
typeof fn === 'function' && (_onSelectFn = fn);
|
|
};
|
|
|
|
//根据标的代码设置选项
|
|
this.setSelect = function (underlyingCode, blSelectFirst) {
|
|
let postData = { UnderlyingCode: underlyingCode };
|
|
main.post(AjaxUrl, postData).done(function (resp) {
|
|
let suggestions = [];
|
|
if (resp.success !== true) {
|
|
main.alert(resp.msg);
|
|
} else {
|
|
suggestions = resp.obj.map(x => {
|
|
return { value: x.ContractCode, data: x };
|
|
})
|
|
}
|
|
|
|
$(_el).autocomplete('setOptions', { lookup: suggestions })
|
|
|
|
if (blSelectFirst) {
|
|
if (suggestions.length) {
|
|
_el.dataset.select = '1';
|
|
_el.value = suggestions[0].value;
|
|
_onSelectFn && _onSelectFn(suggestions[0].data);
|
|
} else {
|
|
_el.value = '';
|
|
}
|
|
}
|
|
});
|
|
};
|
|
}
|
|
|
|
//场内期权代码自动完成(jquery.autocomplete)
|
|
global.ExchangeOptionAutoComplete = function (el) {
|
|
|
|
return new ExchangeOptionAutoComplete().init(el);
|
|
};
|
|
|
|
}(window.tradeHelper));
|
|
|
|
Object.freeze(window.tradeHelper);
|