diff --git a/YLErpWeb/Controllers/EodPriceController.cs b/YLErpWeb/Controllers/EodPriceController.cs index 17a12bcc..91ce6409 100644 --- a/YLErpWeb/Controllers/EodPriceController.cs +++ b/YLErpWeb/Controllers/EodPriceController.cs @@ -4,18 +4,6 @@ using YLErp.Modules.EodModule; namespace YLErp.Web.Controllers { - /// - /// 新建日终价格时,编辑页用来渲染"选择标的"下拉项的轻量视图模型。 - /// 纯服务端渲染,前端不依赖任何自动补全插件。 - /// - public class UnderlyingOptionVm - { - public int Id { get; set; } - public string Code { get; set; } - public string Name { get; set; } - public string Market { get; set; } - } - public class EodPriceController : BaseController { readonly IViewRenderService _viewRenderer; @@ -71,13 +59,8 @@ namespace YLErp.Web.Controllers ViewBag.IsNew = isNew; if (isNew) { - // 新建:提供期货类标的下拉,供前端选择后回填 UnderlyingId/UnderlyingCode/市场 - ViewBag.UnderlyingOptions = BuildUnderlyingOptions( - ConsGlobal.InstrumentType.CommodityFutures, - ConsGlobal.InstrumentType.GoldFutures, - ConsGlobal.InstrumentType.TBFutures, - ConsGlobal.InstrumentType.OtherFutures, - ConsGlobal.InstrumentType.AbroadFutures); + // 新建:手工输入标的代码,失焦时调 LookupUnderlyingForEod 校验并带出市场/UnderlyingId。 + // 默认估值日期=今天:避免未填日期时落库为 0001-01-01、落在列表默认窗口(今天)之外而查不出。 return View(new eod_commodity_future_price { ValueDate = DateTime.Today }); } var intid = DecryptInt(enid); @@ -96,16 +79,7 @@ namespace YLErp.Web.Controllers ViewBag.IsNew = isNew; if (isNew) { - // 新建:提供股票类标的下拉 - ViewBag.UnderlyingOptions = BuildUnderlyingOptions( - ConsGlobal.InstrumentType.Stock, - ConsGlobal.InstrumentType.StockIndex, - ConsGlobal.InstrumentType.StockIF, - ConsGlobal.InstrumentType.HKStock, - ConsGlobal.InstrumentType.HKStockIndex, - ConsGlobal.InstrumentType.NewOtcStock, - ConsGlobal.InstrumentType.AbroadStock, - ConsGlobal.InstrumentType.AbroadStockIndex); + // 新建:手工输入标的代码,失焦时调 LookupUnderlyingForEod 校验并带出市场。 return View(new eod_stock_price { ValueDate = DateTime.Today }); } var intid = DecryptInt(enid); @@ -123,13 +97,8 @@ namespace YLErp.Web.Controllers ViewBag.IsNew = isNew; if (isNew) { - // 新建:提供债券类标的下拉(bond_id 由前端选择后回填)。 - // 默认估值日期=今天:避免未填日期时落库为 0001-01-01,落在列表默认窗口(今天)之外而查不出。 - ViewBag.UnderlyingOptions = BuildUnderlyingOptions( - ConsGlobal.InstrumentType.Bonds, - ConsGlobal.InstrumentType.TBonds, - ConsGlobal.InstrumentType.CreditBonds, - ConsGlobal.InstrumentType.OtherBonds); + // 新建:手工输入债券代码(bond_id),失焦时调 LookupUnderlyingForEod 校验并带出市场。 + // 默认估值日期=今天:避免未填日期时落库为 0001-01-01、落在列表默认窗口(今天)之外而查不出。 return View(new ChinaBondValuation { valuation_date = DateTime.Today }); } var intid = DecryptLong(enid); @@ -143,23 +112,69 @@ namespace YLErp.Web.Controllers } /// - /// 按标的类型取可下拉的标的列表(新建日终价格时供前端选择)。 - /// 返回 Id/Code/Name/Market,纯服务端渲染,不依赖前端自动补全插件。 + /// 新建日终价格时,按用户手工输入的标的代码精确查一条标的,带出名称/市场/Id。 + /// 只返回已上市(LaunchState=="1")且类型匹配的标的——与列表查询 inner join 的过滤对齐, + /// 从源头杜绝"新增能存但查不出"的幽灵记录。前端在输入框失焦时调用,不依赖任何下拉/补全插件。 /// - private List BuildUnderlyingOptions(params string[] instrumentTypes) + /// 标的代码(用户手工输入) + /// bond | future | stock,决定允许的标的类型集合 + [HttpPost] + public JsonResult LookupUnderlyingForEod(string code, string kind) { - var set = new HashSet(instrumentTypes); - return yldb.underlying_manager - .Where(n => n.UnderlyingCode != null && n.LaunchState == "1" && set.Contains(n.UnderlyingInstrumentType)) - .OrderBy(n => n.UnderlyingCode) - .Select(n => new UnderlyingOptionVm + if (string.IsNullOrWhiteSpace(code)) + { + return JsonError("请输入标的代码"); + } + code = code.Trim(); + + string[] types = kind switch + { + "future" => new[] { - Id = n.id, - Code = n.UnderlyingCode, - Name = n.UnderlyingName, - Market = n.MarketName - }) - .ToList(); + 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 u = yldb.underlying_manager + .Where(n => n.UnderlyingCode == code && n.LaunchState == "1" && set.Contains(n.UnderlyingInstrumentType)) + .Select(n => new { n.id, n.UnderlyingCode, n.UnderlyingName, n.MarketName }) + .FirstOrDefault(); + + if (u == null) + { + return JsonError("未找到该标的(不存在、未上市或类型不匹配),无法录入"); + } + + return JsonSuccess("", new + { + Id = u.id, + Code = u.UnderlyingCode, + Name = u.UnderlyingName, + Market = u.MarketName, + }); } [HttpPost] public JsonResult EodFuturePriceEditJson(eod_commodity_future_price req) diff --git a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml index aeb164ae..7a0a89c9 100644 --- a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml @@ -1,7 +1,8 @@ @model ChinaBondValuation @{ - ViewBag.Title = "日终商品期货价格 | 编辑"; + ViewBag.Title = "日终债券价格 | 编辑"; Layout = "~/Views/Shared/_InfoLayout.cshtml"; + bool isNew = ViewBag.IsNew != null && (bool)ViewBag.IsNew; } @section JS { @@ -16,16 +17,23 @@ return pass; } - function onBondPicked() { - var sel = document.getElementById('BondPicker'); - var opt = sel.options[sel.selectedIndex]; - document.getElementById('bond_id').value = opt.value; - document.getElementById('MarketBox').value = opt.getAttribute('data-market') || ''; + // 手工输入债券代码后失焦:校验标的存在且已上市,并带出市场 + function lookupBond() { + var el = document.getElementById('bond_id'); + if (!el) return; + var code = (el.value || '').trim(); + var mk = document.getElementById('MarketBox'); + if (!code) { if (mk) mk.value = ''; return; } + main.post("/eodPrice/LookupUnderlyingForEod", { code: code, kind: 'bond' }).done(function (res) { + el.value = res.obj.Code; + if (mk) mk.value = res.obj.Market || ''; + }); } function saveeod_bond_price() { - if (document.getElementById('BondPicker') && !document.getElementById('bond_id').value) { - main.message('请先选择债券标的'); return false; + var el = document.getElementById('bond_id'); + if (el && !(el.value || '').trim()) { + main.message('请输入债券标的代码'); return false; } if (!checkSubmitData()) return false; var data = $("#form1").serialize(); @@ -41,23 +49,20 @@ - + @if (!isNew) + { + + }

日终债券价格修改

- @if (ViewBag.IsNew != null && (bool)ViewBag.IsNew) + @if (isNew) {
- - + +
@@ -85,4 +90,4 @@
- \ No newline at end of file + diff --git a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml index 9cddbc82..b4edeb1a 100644 --- a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml @@ -2,6 +2,7 @@ @{ ViewBag.Title = "日终商品期货价格 | 编辑"; Layout = "~/Views/Shared/_InfoLayout.cshtml"; + bool isNew = ViewBag.IsNew != null && (bool)ViewBag.IsNew; } @section JS { @@ -16,17 +17,29 @@ return pass; } - function onFuturePicked() { - var sel = document.getElementById('FuturePicker'); - var opt = sel.options[sel.selectedIndex]; - document.getElementById('UnderlyingId').value = opt.value; - document.getElementById('UnderlyingCode').value = opt.getAttribute('data-code') || ''; - document.getElementById('MarketBox').value = opt.getAttribute('data-market') || ''; + // 手工输入期货合约代码后失焦:校验标的存在且已上市,带出市场并回填 UnderlyingId(列表查询按此 join) + function lookupFuture() { + var el = document.getElementById('UnderlyingCode'); + if (!el) return; + var code = (el.value || '').trim(); + var mk = document.getElementById('MarketBox'); + var idEl = document.getElementById('UnderlyingId'); + if (!code) { if (mk) mk.value = ''; if (idEl) idEl.value = ''; return; } + main.post("/eodPrice/LookupUnderlyingForEod", { code: code, kind: 'future' }).done(function (res) { + el.value = res.obj.Code; + if (idEl) idEl.value = res.obj.Id; + if (mk) mk.value = res.obj.Market || ''; + }); } function saveeod_commodity_future_price() { - if (document.getElementById('FuturePicker') && !document.getElementById('UnderlyingCode').value) { - main.message('请先选择期货标的'); return false; + var el = document.getElementById('UnderlyingCode'); + var idEl = document.getElementById('UnderlyingId'); + if (el && !(el.value || '').trim()) { + main.message('请输入期货标的代码'); return false; + } + if (el && idEl && !idEl.value) { + main.message('标的未校验通过,请重新输入代码后失焦'); return false; } if (!checkSubmitData()) return false; var data = $("#form1").serialize(); @@ -42,25 +55,26 @@ - - + @if (isNew) + { + + } + else + { + + + }

日终商品期货价格修改

- @if (ViewBag.IsNew != null && (bool)ViewBag.IsNew) + @if (isNew) {
- - + +
@@ -88,4 +102,4 @@
- \ No newline at end of file + diff --git a/YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml b/YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml deleted file mode 100644 index bc216e25..00000000 --- a/YLErpWeb/Views/EodPrice/eodPriceAdd.cshtml +++ /dev/null @@ -1,268 +0,0 @@ -@{ - ViewBag.Title = "日终价格新增"; - Layout = "~/Views/Shared/_InfoLayout.cshtml"; -} -@section CSS -{ - -} -@section JS -{ - -} - -
- - - - - - - - -

日终价格新增

- -
-
- - - -
-
- - -
-
- - -
- - @* 债券字段组 *@ - - - @* 商品期货字段组 *@ - - - @* 股票字段组 *@ - -
- -
- - -
-
diff --git a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml index ad7fb36f..08d58bc0 100644 --- a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml @@ -2,11 +2,11 @@ @{ ViewBag.Title = "日终股票价格 | 编辑"; Layout = "~/Views/Shared/_InfoLayout.cshtml"; + bool isNew = ViewBag.IsNew != null && (bool)ViewBag.IsNew; } @section JS {