// ********************** 根据关键字动态查询. ******************************** // var oldValue = ""; var oid; var highlightindex = -1; function DoAnscToFillDiv(sender, selectVal, tbid, fk_mapExt, dbSrc, dbType) { openDiv(sender, tbid); var mapExt = new Entity("BP.Sys.MapExt", fk_mapExt); var myEvent = window.event || arguments[0]; var myKeyCode = myEvent.keyCode; // 获得ID为divinfo里面的DIV对象 . var autoNodes = $("#divinfo").children("div"); if (myKeyCode == 38) { if (highlightindex != -1) { autoNodes.eq(highlightindex).css("background-color", "white"); autoNodes.eq(highlightindex).css("color", "Black"); if (highlightindex == 0) { highlightindex = autoNodes.length - 1; } else { highlightindex--; } } else { highlightindex = autoNodes.length - 1; } autoNodes.eq(highlightindex).css("background-color", "rgb(40, 132, 250)"); autoNodes.eq(highlightindex).css("color", "white"); } else if (myKeyCode == 40) { if (highlightindex != -1) { autoNodes.eq(highlightindex).css("background-color", "white"); autoNodes.eq(highlightindex).css("color", "black"); highlightindex++; } else { highlightindex++; } if (highlightindex == autoNodes.length) { autoNodes.eq(autoNodes.length).css("background-color", "white"); autoNodes.eq(autoNodes.length).css("color", "black"); highlightindex = 0; } autoNodes.eq(highlightindex).css("background-color", "rgb(40, 132, 250)"); autoNodes.eq(highlightindex).css("color", "white"); } else if (myKeyCode == 13) { if (highlightindex != -1) { //获得选中的那个的文本值 var textInputText = autoNodes.eq(highlightindex).text(); var strs = textInputText.split('|'); autoNodes.eq(highlightindex).css("background-color", "white"); $("#" + tbid).val(strs[0]); $("#divinfo").hide(); oldValue = strs[0]; // 填充. FullIt(oldValue, mapExt.MyPK, tbid); highlightindex = -1; } } else { if (selectVal != oldValue) { $("#divinfo").empty(); //获得对象. var mapExt = new Entity("BP.Sys.MapExt", fk_mapExt); var dataObj = GenerDB(mapExt.Doc, selectVal, mapExt.DBType, mapExt.FK_DBSrc); if ($.isEmptyObject(dataObj)) { $("#divinfo").hide(); return; } //简洁模式 if (TBModel == "Simple"){ $.each(dataObj, function (idx, item) { var no = item.No; if (no == undefined) no = item.NO; var name = item.Name; if (name == undefined) name = item.NAME; $("#divinfo").append("
" + no + '|' + name + "
"); }); } //表格模式 if(TBModel=="Table") showDataGrid(sender, tbid, dataObj, mapExt); oldValue = selectVal; } } } function showDataGrid(sender, tbid, dataObj, mapExt) { //加载bootStrap的js if (GetHrefUrl().indexOf("CCForm") != -1) { $('head').append(''); $('head').append(''); Skip.addJs("../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js"); } else { $('head').append(''); $('head').append(''); Skip.addJs("./Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js"); } var columns = mapExt.Tag3; $("#divinfo").append("
"); //取消DIV的宽度 document.getElementById('divinfo').style.width = ""; //显示行号的添加 var searchTableColumns = [{ formatter: function (value, row, index) { return index + 1; } }]; //显示列的中文名称 if (typeof columns == "string") { $.each(columns.split(","), function (i, o) { var exp = o.split("="); var field; var title; if (exp.length == 1) { field = title = exp[0]; } else if (exp.length == 2) { field = exp[0]; title = exp[1]; } if (!isLegalName(field)) { return true; } searchTableColumns.push({ field: field, title: title }); }); var options = { striped: true, cache: false, showHeader: true, sortOrder: "asc", strictSearch: true, minimumCountColumns: 2, clickToSelect: true, sortable: false, cardView: false, detailView: false, uniqueId: "No", columns: searchTableColumns }; //选中行的操作 options.onClickRow = function (row, element) { $("#divinfo").empty(); $("#divinfo").css("display", "none"); highlightindex = -1; $("#" + tbid).val(row.No); FullIt(row.No, mapExt.MyPK, tbid); }; $('#viewGrid').bootstrapTable(options); $('#viewGrid').bootstrapTable("load", dataObj); } } function isLegalName(name) { if (!name) { return false; } return name.match(/^[a-zA-Z\$_][a-zA-Z\d\$_]*$/); } //填充其他的控件. function FullIt(selectVal, refPK, elementId,type) { if (oid == null) oid = GetQueryString('OID'); if (oid == null) oid = GetQueryString('WorkID'); if (oid == null) { oid = 0; return; } var mypk = ""; if (refPK.indexOf("FullData") != -1) mypk = refPK; else mypk = refPK + "_FullData"; //获得对象. var mapExt = new Entity("BP.Sys.MapExt"); mapExt.SetPKVal(mypk); var i = mapExt.RetrieveFromDBSources(); //没有填充其他控件 if (i == 0) return; //生成关键字. GenerPageKVs(); //执行填充主表的控件. FullCtrl(selectVal, elementId, mapExt,type); //执行个性化填充下拉框,比如填充ddl下拉框的范围. FullCtrlDDL(selectVal, elementId, mapExt); //执行填充从表. FullDtl(selectVal, mapExt); //执行确定后执行的JS var backFunc = mapExt.Tag2; if (backFunc != null && backFunc != "" && backFunc != undefined) { var oid = GetQueryString("OID") if (backFunc.indexOf("@OID") != -1 && oid==null) { //获取OID的值 var oid = elementId.replace("TB_", "").replace("DDL_", "").replace("CB_", "").replace(mapExt.AttrOfOper + "_", ""); backFunc = backFunc.replace(/@OID/g, oid); } backFunc = DealSQL(backFunc, selectVal); DBAccess.RunFunctionReturnStr(backFunc); } } function openDiv(e, tbID) { if (document.getElementById("divinfo").style.display == "none") { var txtObject = e; // document.getElementById(tbID); var orgObject = document.getElementById("divinfo"); var rect = getoffset(txtObject); var t = rect[0] + 29; var l = rect[1]; orgObject.style.top = t + 'px'; orgObject.style.left = l + 'px'; orgObject.style.display = "block"; txtObject.focus(); } } function getoffset(e) { var t = e.offsetTop; var l = e.offsetLeft; while (e = e.offsetParent) { if (e.id == 'divCCForm') { break; } t += e.offsetTop; l += e.offsetLeft; } var rec = new Array(1); rec[0] = t; rec[1] = l; return rec } var kvs = null; function GenerPageKVs() { var ddls = null; ddls = parent.document.getElementsByTagName("select"); kvs = ""; for (var i = 0; i < ddls.length; i++) { var id = ddls[i].name; if (id.indexOf('DDL_') == -1) { continue; } var myid = id.substring(id.indexOf('DDL_') + 4); kvs += '~' + myid + '=' + ddls[i].value; } ddls = document.getElementsByTagName("select"); for (var i = 0; i < ddls.length; i++) { var id = ddls[i].name; if (id.indexOf('DDL_') == -1) { continue; } var myid = id.substring(id.indexOf('DDL_') + 4); kvs += '~' + myid + '=' + ddls[i].value; } return kvs; } /* 自动填充 type: 0 主表 1 从表*/ function DDLFullCtrl(selectVal, ddlChild, fk_mapExt,type) { FullIt(selectVal, fk_mapExt, ddlChild,type); } /* 级联下拉框 param 传到后台的一些参数 例如从表的行数据 主表的字段值 如果param参数在,就不去页面中取KVS 了,PARAM 就是*/ function DDLAnsc(selectVal, ddlChild, fk_mapExt, param) { //1.初始值为空或者NULL时,相关联的字段没有数据显示 if (selectVal == null || selectVal == "") { $("#" + ddlChild).empty(); //无数据返回时,提示显示无数据,并将与此关联的下级下拉框也处理一遍,edited by liuxc,2015-10-22 $("#" + ddlChild).append("