diff --git a/YLErpWeb/Controllers/EodPriceController.cs b/YLErpWeb/Controllers/EodPriceController.cs index 91ce6409..62747ff9 100644 --- a/YLErpWeb/Controllers/EodPriceController.cs +++ b/YLErpWeb/Controllers/EodPriceController.cs @@ -176,6 +176,63 @@ namespace YLErp.Web.Controllers Market = u.MarketName, }); } + + /// + /// 新建日终价格时,按手工输入的片段做服务端模糊联想(代码或名称包含匹配),只回前 20 条。 + /// 与 LookupUnderlyingForEod 同样只返回已上市(LaunchState=="1")且类型匹配的标的。 + /// 用原生下拉渲染(不依赖 jQuery UI,bundle 未打包),避免几十万标的全量渲染卡死。 + /// + [HttpPost] + public JsonResult SuggestUnderlyingForEod(string q, string kind) + { + if (string.IsNullOrWhiteSpace(q)) + { + return JsonSuccess("", new List()); + } + q = q.Trim(); + + string[] types = kind switch + { + "future" => new[] + { + ConsGlobal.InstrumentType.CommodityFutures, + ConsGlobal.InstrumentType.GoldFutures, + ConsGlobal.InstrumentType.TBFutures, + ConsGlobal.InstrumentType.OtherFutures, + ConsGlobal.InstrumentType.AbroadFutures, + }, + "stock" => new[] + { + ConsGlobal.InstrumentType.Stock, + ConsGlobal.InstrumentType.StockIndex, + ConsGlobal.InstrumentType.StockIF, + ConsGlobal.InstrumentType.HKStock, + ConsGlobal.InstrumentType.HKStockIndex, + ConsGlobal.InstrumentType.NewOtcStock, + ConsGlobal.InstrumentType.AbroadStock, + ConsGlobal.InstrumentType.AbroadStockIndex, + }, + _ => new[] + { + ConsGlobal.InstrumentType.Bonds, + ConsGlobal.InstrumentType.TBonds, + ConsGlobal.InstrumentType.CreditBonds, + ConsGlobal.InstrumentType.OtherBonds, + }, + }; + var set = new HashSet(types); + + var list = yldb.underlying_manager + .Where(n => n.LaunchState == "1" && set.Contains(n.UnderlyingInstrumentType) + && (n.UnderlyingCode.Contains(q) || n.UnderlyingName.Contains(q))) + .OrderBy(n => n.UnderlyingCode) + .Take(20) + .Select(n => new { n.id, Code = n.UnderlyingCode, Name = n.UnderlyingName, Market = n.MarketName }) + .ToList(); + + return JsonSuccess("", list); + } + [HttpPost] public JsonResult EodFuturePriceEditJson(eod_commodity_future_price req) { diff --git a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml index 7a0a89c9..417f5c25 100644 --- a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml @@ -43,6 +43,63 @@ }); } + // 服务端模糊联想:输入时按需查前20条匹配(代码或名称),原生下拉,不用插件 + var _eodSuggestTimer = null; + function eodSuggest(input, kind) { + clearTimeout(_eodSuggestTimer); + var q = (input.value || '').trim(); + if (q.length < 1) { eodHideSuggest(); return; } + _eodSuggestTimer = setTimeout(function () { + main.post('/eodPrice/SuggestUnderlyingForEod', { q: q, kind: kind }).done(function (res) { + if (res.success && res.obj && res.obj.length) { + eodRenderSuggest(res.obj, input, kind); + } else { + eodHideSuggest(); + } + }); + }, 250); + } + function eodRenderSuggest(list, input, kind) { + var box = document.getElementById('eodSuggestBox'); + if (!box) return; + box.innerHTML = ''; + list.forEach(function (item) { + var div = document.createElement('div'); + div.className = 'eod-suggest-item'; + var code = document.createElement('span'); + code.className = 'eod-suggest-code'; + code.textContent = item.Code; + var name = document.createElement('span'); + name.className = 'eod-suggest-name'; + name.textContent = item.Name || ''; + div.appendChild(code); div.appendChild(name); + div.onmousedown = function (e) { + e.preventDefault(); + input.value = item.Code; + eodHideSuggest(); + var fn = { bond: lookupBond, future: lookupFuture, stock: lookupStock }[kind]; + if (fn) fn(); + }; + box.appendChild(div); + }); + var r = input.getBoundingClientRect(); + box.style.left = r.left + 'px'; + box.style.top = (r.bottom + 2) + 'px'; + box.style.width = Math.max(r.width, 220) + 'px'; + box.style.display = 'block'; + } + function eodHideSuggest() { + var b = document.getElementById('eodSuggestBox'); + if (b) b.style.display = 'none'; + } + document.addEventListener('click', function (e) { + var b = document.getElementById('eodSuggestBox'); + if (b && b.style.display === 'block' && !b.contains(e.target) + && e.target.id !== 'bond_id' && e.target.id !== 'UnderlyingCode') { + b.style.display = 'none'; + } + }); + } @@ -62,7 +119,7 @@ { 标的代码 - + 市场 diff --git a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml index b4edeb1a..966f360a 100644 --- a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml @@ -49,6 +49,63 @@ }); } + // 服务端模糊联想:输入时按需查前20条匹配(代码或名称),原生下拉,不用插件 + var _eodSuggestTimer = null; + function eodSuggest(input, kind) { + clearTimeout(_eodSuggestTimer); + var q = (input.value || '').trim(); + if (q.length < 1) { eodHideSuggest(); return; } + _eodSuggestTimer = setTimeout(function () { + main.post('/eodPrice/SuggestUnderlyingForEod', { q: q, kind: kind }).done(function (res) { + if (res.success && res.obj && res.obj.length) { + eodRenderSuggest(res.obj, input, kind); + } else { + eodHideSuggest(); + } + }); + }, 250); + } + function eodRenderSuggest(list, input, kind) { + var box = document.getElementById('eodSuggestBox'); + if (!box) return; + box.innerHTML = ''; + list.forEach(function (item) { + var div = document.createElement('div'); + div.className = 'eod-suggest-item'; + var code = document.createElement('span'); + code.className = 'eod-suggest-code'; + code.textContent = item.Code; + var name = document.createElement('span'); + name.className = 'eod-suggest-name'; + name.textContent = item.Name || ''; + div.appendChild(code); div.appendChild(name); + div.onmousedown = function (e) { + e.preventDefault(); + input.value = item.Code; + eodHideSuggest(); + var fn = { bond: lookupBond, future: lookupFuture, stock: lookupStock }[kind]; + if (fn) fn(); + }; + box.appendChild(div); + }); + var r = input.getBoundingClientRect(); + box.style.left = r.left + 'px'; + box.style.top = (r.bottom + 2) + 'px'; + box.style.width = Math.max(r.width, 220) + 'px'; + box.style.display = 'block'; + } + function eodHideSuggest() { + var b = document.getElementById('eodSuggestBox'); + if (b) b.style.display = 'none'; + } + document.addEventListener('click', function (e) { + var b = document.getElementById('eodSuggestBox'); + if (b && b.style.display === 'block' && !b.contains(e.target) + && e.target.id !== 'bond_id' && e.target.id !== 'UnderlyingCode') { + b.style.display = 'none'; + } + }); + } @@ -74,7 +131,7 @@ { 标的代码 - + 市场 diff --git a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml index 08d58bc0..b7403e24 100644 --- a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml @@ -42,6 +42,64 @@ main.parentReloadData(); }); } + + // 服务端模糊联想:输入时按需查前20条匹配(代码或名称),原生下拉,不用插件 + var _eodSuggestTimer = null; + function eodSuggest(input, kind) { + clearTimeout(_eodSuggestTimer); + var q = (input.value || '').trim(); + if (q.length < 1) { eodHideSuggest(); return; } + _eodSuggestTimer = setTimeout(function () { + main.post('/eodPrice/SuggestUnderlyingForEod', { q: q, kind: kind }).done(function (res) { + if (res.success && res.obj && res.obj.length) { + eodRenderSuggest(res.obj, input, kind); + } else { + eodHideSuggest(); + } + }); + }, 250); + } + function eodRenderSuggest(list, input, kind) { + var box = document.getElementById('eodSuggestBox'); + if (!box) return; + box.innerHTML = ''; + list.forEach(function (item) { + var div = document.createElement('div'); + div.className = 'eod-suggest-item'; + var code = document.createElement('span'); + code.className = 'eod-suggest-code'; + code.textContent = item.Code; + var name = document.createElement('span'); + name.className = 'eod-suggest-name'; + name.textContent = item.Name || ''; + div.appendChild(code); div.appendChild(name); + div.onmousedown = function (e) { + e.preventDefault(); + input.value = item.Code; + eodHideSuggest(); + var fn = { bond: lookupBond, future: lookupFuture, stock: lookupStock }[kind]; + if (fn) fn(); + }; + box.appendChild(div); + }); + var r = input.getBoundingClientRect(); + box.style.left = r.left + 'px'; + box.style.top = (r.bottom + 2) + 'px'; + box.style.width = Math.max(r.width, 220) + 'px'; + box.style.display = 'block'; + } + function eodHideSuggest() { + var b = document.getElementById('eodSuggestBox'); + if (b) b.style.display = 'none'; + } + document.addEventListener('click', function (e) { + var b = document.getElementById('eodSuggestBox'); + if (b && b.style.display === 'block' && !b.contains(e.target) + && e.target.id !== 'bond_id' && e.target.id !== 'UnderlyingCode') { + b.style.display = 'none'; + } + }); + } @@ -62,7 +120,7 @@ { 标的代码 - + 市场