// ********************** 根据关键字动态查询. ******************************** // var oldValue = ""; var oid; var highlightindex = -1; function DoAnscToFillDiv(sender, selectVal, tbid, fk_mapExt, TBModel) { //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 = $("#autoComplete").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]); $("#autodiv").remove(); oldValue = strs[0]; // 填充. FullIt(oldValue, mapExt.MyPK, tbid); highlightindex = -1; } } else { if (selectVal != oldValue) { $("#autodiv").remove(); //获得对象. //var dataObj = GenerDB(mapExt.Tag4, selectVal, mapExt.DBType, mapExt.FK_DBSrc); //if ($.isEmptyObject(dataObj)) { // //$("#divinfo").hide(); // return; //} //简洁模式 if (TBModel == "Simple") { $("#" + tbid).after("
"); $.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; var left = $("#autodiv").offset().left; $("#autoComplete").css("left", left + "px"); $("#autoC omplete").append("
" + no + '|' + name + "
"); }); } //表格模式 if (TBModel == "Table") showDataGrid(tbid, selectVal, mapExt, "Dtl"); oldValue = selectVal; document.onclick = function () { $("#autodiv").remove(); } } } } /** * 获取数据的方法 * @param {any} dbSrc 请求数据集合的内容 * @param {any} dbType 请求数据的集合了类型 SQL,函数,URL * @param {any} dbSource 如果是SQL的时,SQL的查询来源,本地,外部数据源 * @param {any} keyVal 选择替换的值 */ function GetDataTableByDB(dbSrc, dbType, dbSource, keyVal, mapExt, field, type) { // debugger if (dbSrc == null || dbSrc == undefined || dbSrc == "") return null; if (dbType == 0) { var mypk = mapExt.MyPK; if (mapExt.MyPK == undefined || mapExt.MyPK == "") { mypk = mapExt.pkval; } mapExt = new Entity("BP.Sys.MapExt", mapExt); mapExt.MyPK = mypk; //增加表单上的 var paras = getPageData() + "@Key=" + keyVal; var pkval = GetQueryString("WorkID") || GetQueryString("OID"); var data = mapExt.DoMethodReturnString("GetDataTableByField", field, paras, null, pkval, type); if (data.indexOf("err@") != -1) { alert(data); return null; } var dataObj = JSON.parse(data); return dataObj; } //处理sql,url参数. dbSrc = dbSrc.replace(/~/g, "'"); if (keyVal != null) { if (dbType == 0) keyVal = keyVal.replace(/'/g, ''); dbSrc = dbSrc.replace(/@Key/g, keyVal); dbSrc = dbSrc.replace(/@key/g, keyVal); dbSrc = dbSrc.replace(/@KEY/g, keyVal); } dbSrc = DealExp(dbSrc, null, false); //获取数据源. dataObj = DBAccess.RunDBSrc(dbSrc, dbType, dbSource); return dataObj; } /** * 文本自动完成表格展示 * type 是否为从表Dtl */ function showDataGrid(tbid, selectVal, mapExtMyPK, type) { var mapExt = new Entity("BP.Sys.MapExt", mapExtMyPK); var dataObj = GetDataTableByDB(mapExt.Tag4, mapExt.DBType, mapExt.FK_DBSrc, selectVal, mapExt, "Tag4", type); var columns = mapExt.Tag3; $("#divInfo").remove(); $("#" + tbid).after("
"); var searchTableColumns = [{ field: "", title: "序号", templet: function (d) { return d.LAY_TABLE_INDEX + 1; // 返回每条的序号: 每页条数 *(当前页 - 1 )+ 序号 } }]; //显示列的中文名称. if (typeof columns == "string" && columns != "") { $.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 }); }); } else { searchTableColumns.push({ field: "No", title: "编号" }); searchTableColumns.push({ field: "Name", title: "名称" }); } //debugger var ispagination = dataObj.length > 20 ? true : false; layui.use('table', function () { var table = layui.table; table.render({ elem: "#autoTable", id: "autoTable", cols: [searchTableColumns], data: dataObj }) //监听行单击事件(双击事件为:rowDouble) table.on('row(autoTable)', function (obj) { var data = obj.data; $("#" + tbid).val(data.No); $("#divInfo").remove(); FullIt(data.No, mapExt.pkval, tbid); }); }) } function isLegalName(name) { if (!name) { return false; } return name.match(/^[a-zA-Z\$_][a-zA-Z\d\$_]*$/); } 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] + 22; var l = rect[1]; orgObject.style.top = t + 'px'; orgObject.style.left = l + 'px'; orgObject.style.width = ""; orgObject.style.border = "1px solid rgb(51, 102, 153)"; 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 } /* 内置的Pop自动返回值. */ function ReturnValCCFormPopVal(ctrl, fk_mapExt, refEnPK, width, height, title) { var wfpreHref = GetLocalWFPreHref(); url = wfpreHref + '/WF/CCForm/PopVal.htm?FK_MapExt=' + fk_mapExt + '&RefPK=' + refEnPK + '&CtrlVal=' + ctrl.value; var v = window.showModalDialog(url, 'opp', 'scrollbars=yes;resizable=yes;center=yes;minimize:yes;maximize:yes;dialogHeight: ' + (height || 600) + 'px; dialogWidth: ' + (width || 850) + 'px; dialogTop: 100px; dialogLeft: 150px;'); if (v == null || v == '' || v == 'NaN') { return; } ctrl.value = v; ctrl.value = v; return; } //根据Name设置元素的值 分为 tb,ddl,rd function SetEleValByName(eleName, val) { var ele = $('[name$=_' + eleName + ']'); if (ele != undefined && ele.length > 0) { switch (ele[0].tagName.toUpperCase()) { case "INPUT": switch (ele[0].type.toUpperCase()) { case "CHECKBOX": //复选框 0:false 1:true val.indexOf('1') >= 0 ? $(ele).attr('checked', true) : $(ele).attr('checked', false); break; case "TEXT": //文本框 $(ele).val(val); break; case "RADIO": //单选钮 $(ele).attr('checked', false); $('[name=RB_' + eleName + '][value=' + val + ']').attr('checked', true); break; case "HIDDEN": $(ele).val(val); break; } break; //下拉框 case "SELECT": $(ele).val(val); break; //文本区域 case "TEXTAREA": $(ele).val(val); break; } } } function PopFullCtrl(val1, val2) { alert(val1, val2); } /* 内置的Pop自动返回值. google 版 软通*/ function ReturnValCCFormPopValGoogle(ctrl, fk_mapExt, refEnPK, width, height, title, formData, dtlNo, extType) { //设置摸态框的宽度和高度 $('#returnPopValModal .modal-dialog').height(height); $('#returnPopValModal .modal-dialog').width(width); $('#returnPopValModal .modal-dialog').css('margin-left', 'auto'); $('#returnPopValModal .modal-dialog').css('margin-right', 'auto'); //ctrl = $('#' + ctrl); if (typeof ctrl == "string") { ctrl = document.getElementById(ctrl); } var wfpreHref = GetLocalWFPreHref(); var fd; var dtlWin = dtlNo ? document.getElementById("F" + dtlNo).contentWindow : null; if (formData) { fd = formData; } else { fd = getFormData(false, false); } var url = ""; if (extType == "PopVal" || extType == undefined) url = wfpreHref + '/WF/CCForm/PopVal.htm?FK_MapExt=' + fk_mapExt + '&RefPK=' + refEnPK + '&CtrlVal=' + ctrl.value + "&FormData=" + escape(fd) + "&m=" + Math.random(); if (extType == "PopFullCtrl") url = wfpreHref + '/WF/CCForm/PopFullCtrl.htm?FK_MapExt=' + fk_mapExt + '&RefPK=' + refEnPK + '&CtrlVal=' + ctrl.value + "&FormData=" + escape(fd) + "&m=" + Math.random(); //杨玉慧 模态框 先用这个. $('#returnPopValModal .modal-header h4').text("请选择:" + $(ctrl).parent().parent().prev().text()); $('#iframePopModalForm').attr("src", url); //绑定连接. $('#btnPopValOK').unbind('click'); $('#btnPopValOK').bind('click', function () { //$(ctrl).val(""); setValForPopval(ctrl.id, dtlWin, ""); //为表单元素反填值。 var returnValSetObj = frames["iframePopModalForm"].window.pageSetData; var returnValObj = frames["iframePopModalForm"].window.returnVal; //设置值. if (extType == "PopFullCtrl") { PopFullCtrl(returnValSetObj, returnValObj); return; } if (returnValSetObj != null && returnValObj != null) { if (returnValSetObj[0].PopValWorkModel == "Tree" || returnValSetObj[0].PopValWorkModel == "TreeDouble") { //树模式 分组模式 frames["iframePopModalForm"].window.GetTreeReturnVal(); if (returnValSetObj[0].PopValFormat == "OnlyNo") { setValForPopval(ctrl.id, dtlWin, returnValObj.No); } else if (returnValSetObj[0].PopValFormat == "OnlyName") { setValForPopval(ctrl.id, dtlWin, returnValObj.Name); } else { // for (var property in returnValObj) { SetEleValByName(property, returnValObj[property]); } setValForPopval(ctrl.id, dtlWin, returnValObj.Name); } } else if (returnValSetObj[0].PopValWorkModel == "Group") { //分组模式 frames["iframePopModalForm"].window.GetGroupReturnVal(); setValForPopval(ctrl.id, dtlWin, returnValObj.Value); } else if (returnValSetObj[0].PopValWorkModel == "TableOnly" || returnValSetObj[0].PopValWorkModel == "TablePage") { //表格模式 if (returnValSetObj[0].PopValFormat == "OnlyNo") { $(ctrl).val(returnValObj.No); setValForPopval(ctrl.id, dtlWin, returnValObj.No); } else if (returnValSetObj[0].PopValFormat == "OnlyName") { //$(ctrl).val(returnValObj.Name); setValForPopval(ctrl.id, dtlWin, returnValObj.Name); } else { for (var property in returnValObj) { SetEleValByName(property, returnValObj[property]); } setValForPopval(ctrl.id, dtlWin, returnValObj.Name); } } else if (returnValSetObj[0].PopValWorkModel == "SelfUrl") { //自定义URL if (frames["iframePopModalForm"].window.GetReturnVal != undefined && typeof (frames["iframePopModalForm"].window.GetReturnVal) == "function") { frames["iframePopModalForm"].window.GetReturnVal() } setValForPopval(ctrl.id, dtlWin, returnValObj.Value); } } else { if (frames["iframePopModalForm"].window.returnValue != undefined) { var Value = frames["iframePopModalForm"].window.returnValue; } //$(ctrl).val(Value); setValForPopval(ctrl.id, dtlWin, Value); } //把树等都变成不显示 解决点击一个后另一个会把原来的先显示一下的问题 $(frames["iframePopModalForm"].window.document.getElementById('poptablew')).css('display', 'none'); $(frames["iframePopModalForm"].window.document.getElementById('main')).css('display', 'none'); $(frames["iframePopModalForm"].window.document.getElementById('orgjstree')).css('display', 'none'); $(frames["iframePopModalForm"].window.document.getElementById('groupTable')).css('display', 'none'); // $(".jstree-clicked").removeClass("jstree-clicked"); }); $('#btnPopValCancel').unbind('click'); $('#btnPopValCancel').bind('click', function () { //把树等都变成不显示 解决点击一个后另一个会把原来的先显示一下的问题 $(frames["iframePopModalForm"].window.document.getElementById('poptablew')).css('display', 'none'); $(frames["iframePopModalForm"].window.document.getElementById('main')).css('display', 'none'); $(frames["iframePopModalForm"].window.document.getElementById('orgjstree')).css('display', 'none'); $(frames["iframePopModalForm"].window.document.getElementById('groupTable')).css('display', 'none'); }) $('#returnPopValModal').modal().show(); //修改标题,失去焦点时进行保存 if (typeof self.parent.TabFormExists != 'undefined') { var bExists = self.parent.TabFormExists(); if (bExists) { self.parent.ChangTabFormTitle(); } } return; } /* 设置控件值,仅用在主表单/明细表(且为iframe内的)中设置控件值,目前仅用于Popval弹窗设置返回值 */ function setValForPopval(id, dtlWin, val) { if (dtlWin && dtlWin.SetTextboxValue) { dtlWin.SetTextboxValue(id, val); } else { $("#" + id).val(val); } } /* ReturnValTBFullCtrl */ function ReturnValTBFullCtrl(ctrl, fk_mapExt) { var wfPreHref = GetLocalWFPreHref(); var url = wfPreHref + '/WF/CCForm/FrmReturnValTBFullCtrl.aspx?CtrlVal=' + ctrl.value + '&FK_MapExt=' + fk_mapExt; var v = window.OpenLayuiDialog(url, 'wd', 'scrollbars=yes;resizable=yes;center=yes;minimize:yes;maximize:yes;dialogHeight: 650px; dialogWidth: 850px; dialogTop: 100px; dialogLeft: 150px;'); if (v == null || v == '' || v == 'NaN') { return; } ctrl.value = v; // 填充. FullIt(oldValue, ctrl.id, fk_mapExt); return; } /* 自动填充 */ function DDLFullCtrl(selectVal, ddlChild, fk_mapExt) { FullIt(selectVal, fk_mapExt, ddlChild); } /* 级联下拉框 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("