274 lines
12 KiB
JavaScript
274 lines
12 KiB
JavaScript
//otcformat禁止千分位分组
|
|
window.otcformat.options.disableGrouping = true;
|
|
|
|
var autoUnderlying;
|
|
|
|
//定价格式化(来自配置)
|
|
const pricingFormat = otcformat.trading;
|
|
|
|
//数字格式化
|
|
const consNumberFormat = Object.freeze(new function () {
|
|
this.fixed2 = main.numberFormat(2);
|
|
this.fixed3 = main.numberFormat(3);
|
|
this.fixed4 = main.numberFormat(4);
|
|
this.fixed5 = main.numberFormat(5);
|
|
this.fixed6 = main.numberFormat(6);
|
|
|
|
this.percent2 = main.numberFormat({ percent: true });
|
|
|
|
this.umpriceP = main.numberFormat(pricingFormat.umpriceP.precision + 2);
|
|
this.volValueFmt = pageVue.VolMoreAccurate ? this.fixed6 : this.fixed4;
|
|
this.ttmDaysFmt = pageVue.PrecisionOfMinuteInQuote ? this.fixed5 : this.fixed4;
|
|
return this;
|
|
}());
|
|
|
|
const consUnderlyingFlag = (function () {
|
|
let unSelFlag = tradeHelper.UnderlyingSelectFlag;
|
|
return unSelFlag.UseForTrading | unSelFlag.CheckLaunch | unSelFlag.UsePinYinFilter;
|
|
}());
|
|
|
|
var vue = new Vue({
|
|
el: '#pageVue',
|
|
data: {
|
|
...page,
|
|
KOObservation: {
|
|
hasValue: false,
|
|
ObservationDates: '', KOObservationDates: '',
|
|
ObservationNum: 1, ObservationUnit: 'D', CouponDayInterval: 0,
|
|
ObservationHolidayType: 'Following', ObservationAlignEnd: true, Comments:'',
|
|
},
|
|
KOObservationShow: { date: '', flag: 2, list: [] },
|
|
editWarningTips: "",
|
|
removeChecks: false
|
|
},
|
|
mounted() {
|
|
//标的资产
|
|
autoUnderlying = tradeHelper.UnderlyingAutoComplete('UnderlyingCode', { BlackLimit: 1 })
|
|
.setFlag(consUnderlyingFlag);
|
|
autoUnderlying.onSelect(this.changeUnderlying);
|
|
this.initEdit();
|
|
},
|
|
methods: {
|
|
initEdit() {
|
|
this.removeChecks = false;
|
|
autoUnderlying.setOptions({ MinMaturityDate: this.ChangeData.ValueDate });
|
|
if (this.ChangeData.KOObservationDates && this.PayoffType === '固定') {
|
|
var arr = this.ChangeData.KOObservationDates.split(';').filter(O => O);
|
|
this.KOObservation.ObservationDates = [].concat(arr[0], this.ChangeData.KOObservationSettleDates, arr[1], (arr[2] || "0")).join(';');
|
|
} else {
|
|
this.KOObservation.ObservationDates = this.ChangeData.KOObservationDates || "";
|
|
}
|
|
},
|
|
changeValueDate() {
|
|
main.post("/trade/AjaxGetAccumulatorChangeData", { valueDate: this.ChangeData.ValueDate, tradeId: this.TradeId })
|
|
.done(resp => {
|
|
Object.assign(this.ChangeData, resp.obj);
|
|
this.initEdit();
|
|
});
|
|
},
|
|
changeUnderlying(data) {
|
|
this.editWarningTips = '';
|
|
this.ChangeData.UnderlyingCode = data.Code;
|
|
autoUnderlying.setVarietyId(data.VarietyId);
|
|
if (data.MaturityDate < this.ExerciseDate) {
|
|
this.editWarningTips = `注意:标的${data.Code}到期日'${data.MaturityDate}'小于交易到期日'${this.ExerciseDate}'`;
|
|
}
|
|
},
|
|
changeKOBarrier() {
|
|
if (this.KOObservation.ObservationDates) {
|
|
var arr = this.ChangeData.KOObservationDates.split(';').filter(o => o);
|
|
let fmt = this.IsMoneyness ? consNumberFormat.umpriceP : pricingFormat.umprice;
|
|
var barrierStr = _.toString(this.ChangeData.KOBarrier) ? fmt(this.ChangeData.KOBarrier) : '';
|
|
var index = arr.length >= 3 ? arr.length - 2 : 1;
|
|
var barrierArr = arr[index].split(',');
|
|
barrierArr.forEach(function (v, i) {
|
|
barrierArr[i] = barrierStr;
|
|
});
|
|
arr[index] = barrierArr.join(',');
|
|
this.ChangeData.KOObservationDates = arr.join(';');
|
|
if (arr.length >= 3) {
|
|
arr = [].concat(arr[0], this.ChangeData.KOObservationSettleDates, arr[1], (arr[2] || "0"));
|
|
}
|
|
this.KOObservation.ObservationDates = arr.join(';');
|
|
main.message("敲出障碍价格已同步");
|
|
}
|
|
},
|
|
//设置观察日
|
|
setObservationDates(observationId) {
|
|
let isKO = observationId === '#KO';
|
|
observationId = (new Date().getTime().toString()) + observationId;
|
|
var startTime = _.trim(this.ChangeData.ValueDate);
|
|
var endTime = _.trim(this.ExerciseDate);
|
|
if (!startTime) {
|
|
return main.alert("请输入交易日期");
|
|
}
|
|
if (!endTime) {
|
|
return main.alert("请输入到期日期");
|
|
}
|
|
var obs = this.KOObservation;
|
|
var query = {
|
|
observationNum: obs.ObservationNum,
|
|
observationUnit: obs.ObservationUnit,
|
|
observationHolidayType: obs.ObservationHolidayType,
|
|
startTime: startTime, endTime: endTime,
|
|
alignEnd: _.toString(obs.ObservationAlignEnd) !== "false",
|
|
btnId: observationId,
|
|
couponDayInterval: obs.CouponDayInterval,
|
|
tradeType: '累计期权',
|
|
Comments: obs.Comments
|
|
};
|
|
|
|
var whith = 500;
|
|
if (isKO) {
|
|
query.title1 = "障碍价格";
|
|
query.title2 = "";//票息
|
|
query.isTitle1Percent = this.IsMoneyness;
|
|
query.isTitle2Percent = true;
|
|
query.defaultTitle1Value = this.ChangeData.KOBarrier;
|
|
if (this.PayoffType === '固定') {
|
|
query.defaultTitle2Value = this.Coupon;
|
|
query.showDate2 = true;
|
|
query.date2Title = "结算日期";
|
|
query.showDate2OffsetControl = true;
|
|
query.date2OffsetControlTitle = "结算日期间隔"
|
|
whith += 20;
|
|
} else {
|
|
query.title2 = ""
|
|
}
|
|
}
|
|
|
|
query = $.param(query);
|
|
sessionStorage.setItem(observationId + "_observationdates", obs.ObservationDates);
|
|
layer.open({
|
|
type: 2, title: "设置自定义观察日", shadeClose: false, shade: 0.4,
|
|
area: [whith + 'px', '560px'], content: "/trade/tradeObservationDates?" + query
|
|
});
|
|
},
|
|
getObservationRate(observation) {
|
|
if (!observation || !observation.hasValue) return '';
|
|
var observationRate = "", newUnit = "";
|
|
switch (observation.ObservationUnit) {
|
|
case "D":
|
|
newUnit = "天"; break;
|
|
case "W":
|
|
newUnit = "周"; break;
|
|
case "M":
|
|
newUnit = "月"; break;
|
|
case "Y":
|
|
newUnit = "年"; break;
|
|
}
|
|
observationRate = observation.ObservationNum + newUnit;
|
|
if (newUnit !== "") {
|
|
observationRate = "每" + observationRate;
|
|
}
|
|
return observationRate;
|
|
},
|
|
//设置观察频率
|
|
setObservation(observationNum, observationUnit, observationHolidayType, observationDates, alignEnd, calcId, couponDayInterval, Comments) {
|
|
if (!calcId) return;
|
|
this.KOObservation = {
|
|
hasValue: true,
|
|
ObservationNum: observationNum,
|
|
ObservationUnit: observationUnit,
|
|
ObservationHolidayType: observationHolidayType,
|
|
ObservationAlignEnd: alignEnd,
|
|
CouponDayInterval: couponDayInterval,
|
|
ObservationDates: observationDates,
|
|
Comments: Comments
|
|
};
|
|
var dates = observationDates.split(';').filter(o => o);
|
|
if (dates.length === 4) {
|
|
this.ChangeData.KOObservationSettleDates = dates[1];
|
|
this.ChangeData.KOObservationDates = dates[0] + ";" + dates[2] + ";" + (dates[3] || "0") + ";";
|
|
} else {
|
|
this.ChangeData.KOObservationSettleDates = '';
|
|
this.ChangeData.KOObservationDates = observationDates;
|
|
}
|
|
this.ChangeData.KOObservation = this.KOObservation.ObservationNum + this.KOObservation.ObservationUnit;
|
|
},
|
|
showObservationDates(item) {
|
|
let obDates = item.KOObservationDates || '';
|
|
this.KOObservationShow.list = [];
|
|
this.KOObservationShow.date = item.ValueDate;
|
|
this.KOObservationShow.flag = this.PayoffType === '固定' ? 4 : 2;
|
|
if (obDates) {
|
|
let arr = obDates.split(';');
|
|
if (this.KOObservationShow.flag === 4) {
|
|
arr = [].concat(arr[0], item.KOObservationSettleDates, arr[1]).map(x => x.split(','));
|
|
this.KOObservationShow.list = arr[0].map((x, index) => {
|
|
return {
|
|
obdate: x, stdate: arr[1][index], barrier: this.formatStrike(arr[2][index])
|
|
};
|
|
});
|
|
} else {
|
|
arr = arr.map(x => x.split(','));
|
|
this.KOObservationShow.list = arr[0].map((x, index) => {
|
|
return { obdate: x, barrier: this.formatStrike(arr[1][index]) };
|
|
});
|
|
}
|
|
}
|
|
$('#modalKOObservationShow').modal('show');
|
|
},
|
|
saveChangeData() {
|
|
|
|
main.confirm('确认执行换月吗?', this.doSveChangeData.bind(this));
|
|
},
|
|
doSveChangeData() {
|
|
main.post("/trade/AjaxSaveAccumulatorChangeData", { data: this.ChangeData, tradeId: this.TradeId, removeChecks: this.removeChecks })
|
|
.done(resp => {
|
|
let changeDatas = resp.obj.changeDatas;
|
|
let dates = changeDatas.map(x => x.ValueDate);
|
|
_.remove(this.HisDataList, x => dates.includes(x.ValueDate));
|
|
this.HisDataList = this.HisDataList.concat(changeDatas);
|
|
this.HisDataList = _.orderBy(this.HisDataList, ['ValueDate'], ['desc']);
|
|
resp.obj.TradeUpdated && main.parentReload('reload');
|
|
});
|
|
},
|
|
editData(item) {
|
|
this.ChangeData.ValueDate = item.ValueDate;
|
|
this.changeValueDate();
|
|
},
|
|
removeData(item) {
|
|
main.confirm('确认删除换月数据吗?', this.doRemoveData.bind(this, item));
|
|
},
|
|
doRemoveData(item) {
|
|
main.post("/trade/AjaxRemoveAccumulatorChangeData", { valueDate: item.ValueDate, tradeId: this.TradeId })
|
|
.done(resp => {
|
|
let dates = resp.obj.changeDatas.map(x => x.ValueDate);
|
|
this.HisDataList = this.HisDataList.filter(x => !dates.includes(x.ValueDate));
|
|
resp.obj.TradeUpdated && main.parentReload('reload');
|
|
});
|
|
},
|
|
formatStrike(value) {
|
|
return this.IsMoneyness ? pricingFormat.umpriceP(value) : pricingFormat.umprice(value);
|
|
}
|
|
},
|
|
computed: {
|
|
inputFormatStrike() {
|
|
let fmt = {};
|
|
if (this.IsMoneyness) {
|
|
fmt.append = '%';
|
|
fmt.negative = false;
|
|
fmt.precision = pricingFormat.umpriceP.precision;
|
|
} else {
|
|
fmt.append = '';
|
|
fmt.negative = true;
|
|
fmt.precision = pricingFormat.umprice.precision;
|
|
}
|
|
return fmt;
|
|
},
|
|
koObservationRate() {
|
|
return this.getObservationRate(this.KOObservation);
|
|
},
|
|
canEdit() {
|
|
return this.TradeStatus === "确认成交";
|
|
}
|
|
},
|
|
components: {
|
|
'vue-datepicker': FastVue.vueDatePicker(),
|
|
'vue-number-input': FastVue.vueNumberInput()
|
|
}
|
|
});
|
|
|
|
//兼容定价计算页面观察日设置
|
|
var getObservationDatesSetting = vue.setObservation; |