163 lines
5.6 KiB
JavaScript
163 lines
5.6 KiB
JavaScript
const RateNumberFormat = Object.freeze({ precision: 2, append: '%', negative: true });
|
|
|
|
//标的品种
|
|
var vueVariety = function () {
|
|
return {
|
|
props: ['value'],
|
|
data() {
|
|
return { autoVariety: null };
|
|
},
|
|
mounted() {
|
|
let self = this;
|
|
this.autoVariety = FastVue.autocomplete(this.$el, {
|
|
lookup: pageObj.varieties, nameField: 'Name', valueField: 'id', searchField: ['Name', 'Code', 'PinYin'],
|
|
onSelect: function (data) {
|
|
self.$emit('input', data.id);
|
|
}
|
|
});
|
|
if (this.value) {
|
|
let va = pageObj.varieties.find(x => x.id === this.value);
|
|
va && this.autoVariety.setData(va);
|
|
}
|
|
},
|
|
beforeDestroy() {
|
|
if (this.autoVariety) {
|
|
this.autoVariety.dispose();
|
|
this.autoVariety = null;
|
|
}
|
|
},
|
|
template: '<input name="VarietyId" class="text-box" type="text">'
|
|
};
|
|
};
|
|
|
|
//标的资产
|
|
var vueUnderlying = function () {
|
|
var dataMap = {};
|
|
return {
|
|
props: ['value'],
|
|
data() {
|
|
return { autoUnderlying: null };
|
|
},
|
|
mounted() {
|
|
let self = this;
|
|
let flag = tradeHelper.UnderlyingSelectFlag;
|
|
this.autoUnderlying = tradeHelper.UnderlyingAutoComplete(this.$el)
|
|
.setFlag(flag.UsePinYinFilter | flag.UseRightFilter);
|
|
this.autoUnderlying.onSelect(function (data) {
|
|
dataMap["u" + data.id] = data;
|
|
self.$emit('input', data.id);
|
|
});
|
|
if (this.value) {
|
|
if (dataMap["u" + this.value]) {
|
|
this.autoUnderlying.setData(dataMap["u" + this.value]);
|
|
} else {
|
|
this.autoUnderlying.selectById(this.value);
|
|
}
|
|
}
|
|
},
|
|
destroyed() {
|
|
if (this.autoUnderlying) {
|
|
this.autoUnderlying.dispose();
|
|
this.autoUnderlying = null;
|
|
}
|
|
},
|
|
template: '<input name="UnderlyingId" class="text-box" type="text">'
|
|
};
|
|
};
|
|
|
|
(function () {
|
|
let data = pageObj.Model;
|
|
if (_.trim(data.SpecialConfig)) {
|
|
let special = JSON.parse(data.SpecialConfig);
|
|
data.VarityList = special.VarityList || [];
|
|
data.UnderlyingList = special.UnderlyingList || [];
|
|
} else {
|
|
data.VarityList = [];
|
|
data.UnderlyingList = [];
|
|
}
|
|
}());
|
|
|
|
var vue = new Vue({
|
|
el: "#formEdit",
|
|
data: {
|
|
Model: pageObj.Model,
|
|
updateKey: { variety: 0, underlying: 0 }
|
|
},
|
|
computed: {
|
|
xRatePlaceHolder() {
|
|
return this.Model.xType === "估值日期" ? "例:-3,-2,0,2,3" : "例:-0.1,-5%,0,0.05,10%";
|
|
},
|
|
yRatePlaceHolder() {
|
|
return this.Model.yType === "估值日期" ? "例:-3,-2,0,2,3" : "例:-0.1,-5%,0,0.05,10%";
|
|
}
|
|
},
|
|
mounted: function () {
|
|
|
|
},
|
|
methods: {
|
|
//新增标的品种特殊配置
|
|
addVaritySpecial() {
|
|
this.Model.VarityList.push({ id: 0, Name: "", Rate: "" });
|
|
},
|
|
removeVaritySpecial(index) {
|
|
this.Model.VarityList.splice(index, 1);
|
|
this.updateKey.variety++;
|
|
},
|
|
addUnderlyingSpecial() {
|
|
this.Model.UnderlyingList.push({ id: 0, Name: "", Rate: "" });
|
|
},
|
|
removeUnderlyingSpecial(index) {
|
|
this.Model.UnderlyingList.splice(index, 1);
|
|
this.updateKey.underlying++;
|
|
},
|
|
saveData() {
|
|
let model = _.cloneDeep(this.Model);
|
|
model.ConfigName = _.trim(model.ConfigName);
|
|
if (!model.ConfigName) {
|
|
return main.alert("情景名称 必须填写");
|
|
}
|
|
if (!model.xType) {
|
|
return main.alert("横坐标类型 必须填写");
|
|
}
|
|
if (!model.yType) {
|
|
return main.alert("纵坐标类型 必须填写");
|
|
}
|
|
if (model.xType === model.yType) {
|
|
return main.alert("横纵坐标类型 不能一致");
|
|
}
|
|
let special = {
|
|
VarityList: _.reduce(model.VarityList, (acc, cur) => {
|
|
cur.id && cur.Rate && acc.push({ id: cur.id, Rate: cur.Rate });
|
|
return acc;
|
|
}, []),
|
|
UnderlyingList: _.reduce(model.UnderlyingList, (acc, cur) => {
|
|
cur.id && cur.Rate && acc.push({ id: cur.id, Rate: cur.Rate });
|
|
return acc;
|
|
}, [])
|
|
};
|
|
if (special.VarityList.length !== _.uniqBy(special.VarityList, 'id').length) {
|
|
return main.alert("标的品种变动率 有重复的标的品种!");
|
|
}
|
|
if (special.UnderlyingList.length !== _.uniqBy(special.UnderlyingList, 'id').length) {
|
|
return main.alert("标的代码变动率 有重复的标的代码!");
|
|
}
|
|
|
|
model.SpecialConfig = JSON.stringify(special);
|
|
model.VarityList = model.UnderlyingList = null;
|
|
main.post("/ScenarioAnalysis/AjaxScenarioEdit", model).done(function (res) {
|
|
layer.callParentMethod('parent', 'reloadData');
|
|
window.location.href = "/ScenarioAnalysis/ScenarioView?enid=" + res.obj.EncryptId;
|
|
});
|
|
}
|
|
},
|
|
components: {
|
|
"vue-variety": vueVariety(),
|
|
"vue-underlying": vueUnderlying(),
|
|
'vue-number-input': FastVue.vueNumberInput(),
|
|
}
|
|
});
|
|
|
|
//ESC
|
|
$(document).keyup(function (event) {
|
|
event.keyCode === 27 && layer.closeMe();
|
|
}); |