EodPriceService.SearchUnderlyingList 三分支 Concat 投影成员不对称(债券缺 DataSource、期货/股票缺 UpdateUser),EF 翻译期抛 'DataSource' key not present 致 eodPriceQuery 开屏崩溃,补齐成员对称。eodPriceAdd.cshtml 原用 jQuery UI .autocomplete() 但 bundle 未打包该插件,调用即抛错、脚本中断、标的无法搜索;改为自带下拉补全(纯 jQuery+ajax,不依赖外部插件)。
269 lines
11 KiB
Plaintext
269 lines
11 KiB
Plaintext
@{
|
||
ViewBag.Title = "日终价格新增";
|
||
Layout = "~/Views/Shared/_InfoLayout.cshtml";
|
||
}
|
||
@section CSS
|
||
{
|
||
<style type="text/css">
|
||
.suggest-box {
|
||
position: absolute;
|
||
z-index: 9999;
|
||
background: #fff;
|
||
border: 1px solid #c5c5c5;
|
||
max-height: 260px;
|
||
overflow-y: auto;
|
||
width: 100%;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,.18);
|
||
}
|
||
.suggest-item {
|
||
padding: 7px 12px;
|
||
cursor: pointer;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
.suggest-item:hover, .suggest-item.active {
|
||
background: #eef4ff;
|
||
}
|
||
.suggest-empty {
|
||
padding: 7px 12px;
|
||
color: #999;
|
||
}
|
||
</style>
|
||
}
|
||
@section JS
|
||
{
|
||
<script type="text/javascript">
|
||
var activeGroup = null; // 当前显示的字段组选择器
|
||
var suggestItems = []; // 当前补全项
|
||
var suggestTimer = null;
|
||
|
||
$(function () {
|
||
$(".datepicker").datepicker({ changeMonth: true, changeYear: true, showButtonPanel: true, showOtherMonths: true, selectOtherMonths: true });
|
||
|
||
// 自带下拉补全:不依赖 jQuery UI(bundle 未打包 autocomplete 插件)
|
||
$("#UnderlyingInput").on("input", function () {
|
||
clearTimeout(suggestTimer);
|
||
var q = $(this).val();
|
||
if (!q) { hideSuggest(); return; }
|
||
suggestTimer = setTimeout(function () { doSuggest(q); }, 250);
|
||
}).on("focus", function () {
|
||
if ($(this).val()) doSuggest($(this).val());
|
||
});
|
||
|
||
// 点击补全项
|
||
$("#UnderlyingSuggest").on("click", ".suggest-item", function () {
|
||
var it = suggestItems[$(this).data("i")];
|
||
selectUnderlying(it);
|
||
hideSuggest();
|
||
});
|
||
|
||
// 点击外部关闭补全
|
||
$(document).on("click", function (e) {
|
||
if (!$(e.target).closest("#UnderlyingInput, #UnderlyingSuggest").length) hideSuggest();
|
||
});
|
||
});
|
||
|
||
function doSuggest(q) {
|
||
$.ajax({
|
||
url: "/eodPrice/UnderlyingSuggestForEod",
|
||
type: "POST",
|
||
data: { q: q },
|
||
success: function (res) {
|
||
suggestItems = (res && res.obj) || [];
|
||
var box = $("#UnderlyingSuggest").empty();
|
||
if (!suggestItems.length) {
|
||
box.append("<div class='suggest-empty'>未找到匹配标的</div>").show();
|
||
return;
|
||
}
|
||
$.each(suggestItems, function (i, x) {
|
||
var label = (x.Code || "") + " " + (x.Name || "") + " [" + (x.InstrumentType || "") + "]";
|
||
$("<div class='suggest-item'></div>")
|
||
.text(label)
|
||
.data("i", i)
|
||
.appendTo(box);
|
||
});
|
||
box.show();
|
||
},
|
||
error: function () { hideSuggest(); }
|
||
});
|
||
}
|
||
|
||
function hideSuggest() {
|
||
$("#UnderlyingSuggest").hide().empty();
|
||
}
|
||
|
||
function selectUnderlying(it) {
|
||
$("#UnderlyingInput").val((it.Code || "") + " " + (it.Name || ""));
|
||
$("#UnderlyingCode").val(it.Code);
|
||
$("#bond_id").val(it.Code);
|
||
$("#UnderlyingId").val(it.Id);
|
||
$("#UnderlyingInstrumentType").val(it.InstrumentType);
|
||
$("#MarketDisplay").val(it.Market);
|
||
$("#CodeDisplay").val(it.Code);
|
||
showGroupForType(it.InstrumentType);
|
||
}
|
||
|
||
// 根据标的类型显示对应的字段组
|
||
function showGroupForType(type) {
|
||
$(".price-group").hide();
|
||
activeGroup = null;
|
||
var t = (type || "").toLowerCase();
|
||
var g = null;
|
||
if (t.indexOf("bond") >= 0) g = "#bondFields";
|
||
else if (t.indexOf("future") >= 0) g = "#futureFields";
|
||
else if (t.indexOf("stock") >= 0) g = "#stockFields";
|
||
|
||
if (g) {
|
||
$(g).show();
|
||
activeGroup = g;
|
||
} else {
|
||
main.message("该标的类型(" + type + ")暂不支持新增日终价格");
|
||
}
|
||
}
|
||
|
||
function checkSubmitData() {
|
||
if (!$("#UnderlyingCode").val() || !$("#UnderlyingInstrumentType").val()) {
|
||
main.message("请先选择标的");
|
||
return false;
|
||
}
|
||
if (!activeGroup) {
|
||
main.message("该标的类型不支持新增");
|
||
return false;
|
||
}
|
||
// 仅校验当前字段组的必填项(估值日期/日期)
|
||
var ok = true;
|
||
$(activeGroup + " .req").each(function () {
|
||
if (!$(this).val()) ok = false;
|
||
});
|
||
if (!ok) {
|
||
main.message("请填写估值日期");
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
function saveEodPrice() {
|
||
if (!checkSubmitData()) return false;
|
||
|
||
// 禁用非激活字段组,避免其输入串入表单(disabled 不会进 serialize)
|
||
$(".price-group").not(activeGroup).find("input,select").prop("disabled", true);
|
||
|
||
var type = $("#UnderlyingInstrumentType").val();
|
||
var t = type.toLowerCase();
|
||
var url;
|
||
if (t.indexOf("bond") >= 0) url = "/eodPrice/EodBondPriceEditJson";
|
||
else if (t.indexOf("future") >= 0) url = "/eodPrice/EodFuturePriceEditJson";
|
||
else url = "/eodPrice/EodStockPriceEditJson";
|
||
|
||
var data = $("#form1").serialize();
|
||
$(".price-group").not(activeGroup).find("input,select").prop("disabled", false);
|
||
|
||
main.post(url, data).done(function (res) {
|
||
if (res && res.success === false) {
|
||
main.message(res.msg || "保存失败");
|
||
return;
|
||
}
|
||
var encId = res && res.obj ? res.obj.EncryptId : "";
|
||
// 规整成视图路由认的字符串(与 EodPriceView 的分支一致)
|
||
var viewType = "bond";
|
||
if (t.indexOf("future") >= 0) viewType = "CommodityFutures";
|
||
else if (t.indexOf("stock") >= 0) viewType = "Stock";
|
||
window.location.href = "/eodPrice/eodPriceview?enid=" + encId + "&UnderlyingInstrumentType=" + viewType;
|
||
if (parent && parent.reloadData) parent.reloadData();
|
||
}).fail(function (xhr) {
|
||
main.message("保存失败:" + (xhr.responseJSON && xhr.responseJSON.msg ? xhr.responseJSON.msg : xhr.statusText));
|
||
});
|
||
}
|
||
</script>
|
||
}
|
||
|
||
<form class="yc-panel" id="form1" method="post" onsubmit="return false;">
|
||
|
||
<input type="hidden" name="id" id="id" value="0" />
|
||
<input type="hidden" name="EncryptId" id="EncryptId" value="" />
|
||
<input type="hidden" name="UnderlyingCode" id="UnderlyingCode" />
|
||
<input type="hidden" name="bond_id" id="bond_id" />
|
||
<input type="hidden" name="UnderlyingId" id="UnderlyingId" />
|
||
<input type="hidden" name="UnderlyingInstrumentType" id="UnderlyingInstrumentType" />
|
||
|
||
<h4>日终价格新增</h4>
|
||
|
||
<div style="margin-top:20px; position:relative;">
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>标的</label>
|
||
<input id="UnderlyingInput" class='text-box' placeholder="输入代码/名称搜索,如 600000 或 国债" autocomplete="off" />
|
||
<div id="UnderlyingSuggest" class="suggest-box" style="display:none;"></div>
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>市场</label>
|
||
<input id="MarketDisplay" class='text-box' type='text' readonly=readonly />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>标的代码</label>
|
||
<input id="CodeDisplay" class='text-box' type='text' readonly=readonly />
|
||
</div>
|
||
|
||
@* 债券字段组 *@
|
||
<div id="bondFields" class="price-group" style="display:none;width:100%;">
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>估值日期</label>
|
||
<input class='text-box datepicker req' type='text' name='valuation_date' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>全价</label>
|
||
<input class='text-box' type='text' name='dirty_price_close' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>净价</label>
|
||
<input class='text-box' type='text' name='net_price' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>收益率</label>
|
||
<input class='text-box' type='text' name='yield' />
|
||
</div>
|
||
</div>
|
||
|
||
@* 商品期货字段组 *@
|
||
<div id="futureFields" class="price-group" style="display:none;width:100%;">
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>估值日期</label>
|
||
<input class='text-box datepicker req' type='text' name='ValueDate' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>收盘价</label>
|
||
<input class='text-box' type='text' name='ClosePrice' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>结算价</label>
|
||
<input class='text-box' type='text' name='SettlePrice' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>参考价</label>
|
||
<input class='text-box' type='text' name='ReferencePrice' />
|
||
</div>
|
||
</div>
|
||
|
||
@* 股票字段组 *@
|
||
<div id="stockFields" class="price-group" style="display:none;width:100%;">
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>估值日期</label>
|
||
<input class='text-box datepicker req' type='text' name='ValueDate' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>收盘价</label>
|
||
<input class='text-box' type='text' name='ClosePrice' />
|
||
</div>
|
||
<div class='form-group col-md-6'>
|
||
<label class='formlabel'>参考价</label>
|
||
<input class='text-box' type='text' name='ReferencePrice' />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="padding:10px;padding-left:130px;">
|
||
<button class="btn btn-primary" type="button" onclick="saveEodPrice();">保存</button>
|
||
<button class="btn btn-primary" type="button" onclick="layer.closeMe();">关闭</button>
|
||
</div>
|
||
</form>
|