const consForm = Object.assign({ VarietyId: 0, UnderlyingId: 0, UnderlyingCode: '', ContractSize: 1, CountRatio: 1, underlyingName: '' }); const consUnderlyings = ylotc.underlyings.filter(x => x.InstrumentType === 'CommodityFutures' || x.InstrumentType === 'CommoditySpot'); const vueUnderlying = function () { const _suggestionTpl = _.template($('#underlyingSuggestionTpl').html()); return { props: ['value', 'name'], data() { return { showName: '', jqInput: null }; }, mounted() { var self = this; this.jqInput = $(this.$el).children(0); this.showName = this.name; FastVue.autocomplete(this.jqInput.get(0), { valueField: 'Code', lookup(query, callback) { var arr = []; if (!query) { ylotc.underlyings.forEach(x => { arr.push(x); }); } else { query = query.toUpperCase(); ylotc.underlyings.forEach(x => { if (x.Code.indexOf(query) !== -1 || x.PinYin && x.PinYin.indexOf(query) !== -1) { arr.push(x); } }); } if (arr.length < 30) { arr = _.sortBy(arr, x => x.Code); } return arr; }, onSelect(data) { if (self.value !== data.Code) { self.value = data.Code; if (data.InstrumentType === 'Stock') { self.showName = data.Name; } self.$emit('input', self.value); } self.jqInput.blur(); }, formatResult(suggestion, currentValue) { return _suggestionTpl(suggestion.data); } }); this.jqInput.value = this.value; }, watch: { value(val, old) { if (val !== old) { $(this.$el).val(this.value).data('select', '').attr("placeholder", ''); } }, name(val, old) { if (val !== old) { this.showName = this.name; } } }, methods: { showInput() { this.jqInput.show().focus().next().hide(); }, hideInput() { this.jqInput.hide().next().show(); } }, destroyed() { FastVue.autocomplete.dispose(this.jqInput); }, template: '
' + '
' }; }; //标的信息管理 const underlyingMgr = (new function () { var autoUnderlying; //变更标的资产 function changeUnderlying(yldata, blInitEdit) { let data = yldata || {}; consForm.UnderlyingCode = data.Code || ''; consForm.UnderlyingId = parseInt(data.id) || 0; if (!blInitEdit) { vue.underlying_BasisCurve.UnderlyingCode = consForm.UnderlyingCode; vue.underlying_BasisCurve.UnderlyingId = consForm.UnderlyingId; } if (!data.Code) return; main.post('/Underlying_BasisCurve/GetUnderlyingName', { Underlyingcode: data.Code }).done(function (resp) { consForm.underlyingName = resp; $('#UnderlyingName').val(consForm.underlyingName); }); } this.init = function () { //标的资产 autoUnderlying = FastVue.autocomplete(document.getElementById('UnderlyingId'), { nameField: 'Code', valueField: 'id', searchField: ['Code'], lookup: function (queryLowerCase) { if (!queryLowerCase) { return consForm.VarietyId && consUnderlyings.filter(x => x.VarietyId === consForm.VarietyId); } return consUnderlyings.filter(x => x.Code.toLowerCase().indexOf(queryLowerCase) >= 0); }, onSelect: function (data) { changeUnderlying(data); } }); }; }()); var vue = new Vue({ el: "#vueDiv", data: { underlying_BasisCurve: { id: null, UnderlyingId: 0, UnderlyingCode: null, InterpolationMethod: 1, InterpolationData: [] } }, mounted: function () { underlyingMgr.init(); }, methods: { addUnderlying: function () { this.underlying_BasisCurve.InterpolationData.push({ term: null, UnderlyingCodes: ylotc.underlyings[0].Code, BasisCurve: null }); }, checkAddExpire: function (index) { var thisObj = this; var newExpire = thisObj.underlying_BasisCurve.InterpolationData[index].term if (!newExpire) { return main.message("请输入正确的期限"); } for (let index = 0; index < thisObj.underlying_BasisCurve.InterpolationData.length; index++) { var currentValue = thisObj.underlying_BasisCurve.InterpolationData[index]; var arr = thisObj.underlying_BasisCurve.InterpolationData; if (arr.some(function (value, i) { return i !== index && currentValue.term === value.term; })) { main.message("请输入不同的期限"); return; } } }, deleteUnderlying: function (index) { this.underlying_BasisCurve.InterpolationData.splice(index, 1); }, Reset: function () { this.$forceUpdate(); }, save: function () { var thisObj = this; if (thisObj.underlying_BasisCurve.InterpolationData.length < 1) { main.message("请新增基差曲线") return; } for (var index = 0; index < thisObj.underlying_BasisCurve.InterpolationData.length; index++) { var currentValue = thisObj.underlying_BasisCurve.InterpolationData[index]; var arr = thisObj.underlying_BasisCurve.InterpolationData; if (thisObj.underlying_BasisCurve.InterpolationData[index].BasisCurve === null) { main.message("基差不能为空") return; } if (arr.some(function (value, i) { return i !== index && currentValue.term === value.term; })) { main.message("请输入不同的期限"); return; } } main.confirm("确认保存?", function () { main.post("/Underlying_BasisCurve/SaveUnderlyingBasis_curve", { model: thisObj.underlying_BasisCurve }) .done(function (res) { if (parent) { (parent.vue || parent).reloadclient_black(); parent.layer.closeAll(); } }); }); }, cancel: function () { if (parent) { parent.layer.closeAll(); } } }, components: { 'vue-underlying': vueUnderlying() }, })