//初始化信息 var ensName = GetQueryString("EnsName"); var webUser = new WebUser(); //当前用户查询信息. var ur = new Entity("BP.Sys.UserRegedit"); ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs"; ur.RetrieveFromDBSources(); var cfg = new Entity("BP.Sys.EnCfg"); cfg.No = ensName; cfg.RetrieveFromDBSources(); function InitToolBar() { //创建处理器. var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm"); handler.AddUrlData(); //增加参数. //获得map基本信息. mapBase = handler.DoMethodReturnJSON("Search_MapBaseInfo"); pkFiled = mapBase.EntityPK; $("#title").text(mapBase.EnDesc); document.title = mapBase.EnDesc; var data = handler.DoMethodReturnJSON("Search_SearchAttrs"); //绑定外键枚举查询条件. var attrs = data["Attrs"]; var html = ""; var searchFields = mapBase.SearchFields; //关键字查询 if (searchFields == null || searchFields == "" || searchFields == undefined) { searchFields = ""; if (mapBase.IsShowSearchKey == "1") { var keyLabel = cfg.GetPara("KeyLabel"); if (keyLabel == null || keyLabel == undefined || keyLabel == "") keyLabel = "关键字"; html += '
'; html += ''; html += ''; html += '
'; } //String字段查询 } else { var strs = searchFields.split("@"); var str; var fieldV = ""; for (var i = 0; i < strs.length; i++) { if (strs[i] == "") continue; str = strs[i].split("="); if (str.length < 2 || str[0] == "" || str[1] == "") continue; fields.push(str[1]); fieldV = ur.GetPara(str[1]); if (fieldV == null || fieldV == undefined) fieldV = ""; html += '
'; html += ''; html += ''; html += '
'; } } //数值型的查询增加 var searchFieldsOfNum = mapBase.SearchFieldsOfNum; var val1 = ""; var val2 = ""; if (searchFieldsOfNum != null && searchFieldsOfNum != undefined && searchFieldsOfNum != "") { var strs = searchFieldsOfNum.split("@"); var str; var fieldV = ""; for (var i = 0; i < strs.length; i++) { if (strs[i] == "") continue; str = strs[i].split("="); if (str.length < 2 || str[0] == "" || str[1] == "") continue; fields.push(str[1]); fieldV = ur.GetPara(str[1]); if (fieldV == null || fieldV == undefined || fieldV == "") { val1 = ""; val2 = ""; } else { val1 = fieldV.split(',')[0]; val2 = fieldV.split(',')[1]; } html += '
'; html += ''; html += ''; html += ""; html += ''; html += '
'; } } if (mapBase.DTSearchWay != "0") { var dateType = "date"; if (mapBase.DTSearchWay != "1") dateType = "datatime"; html += '
'; html += ''; html += ""; html += "

请选择日期

"; html += "
"; html += ""; html += "
"; html += '
'; html += ''; html += ""; html += "

请选择日期

"; html += "
"; html += ""; html += "
"; } $("#toolBar").append(html); //设置基础信息. //格式为: @WFSta=0@FK_Dept=02 var json = AtParaToJson(ur.Vals); for (var i = 0; i < attrs.length; i++) { var attr = attrs[i]; var str = ""; str += '
'; str += ""; str += ""; str += "
" str = $(str); $("#toolBar").append(str); //设置基础信息. } html = ""; //为查询外键赋值. for (var i = 0; i < attrs.length; i++) { var attr = attrs[i]; var selectVal = json[attr.Field]; if (selectVal == undefined || selectVal == "") selectVal = "all"; //判断是否有级联关系 var myPK = "ActiveDDL_" + ensName + "_" + attr.Field; var mapExt = new Entity("BP.Sys.MapExt"); mapExt.SetPKVal(myPK); var isExist = mapExt.RetrieveFromDBSources(); //处理级联关系 if (isExist == 1) { var ddlPerant = $("#DDL_" + mapExt.AttrOfOper); var ddlChild = $("#DDL_" + mapExt.AttrsOfActive); if (ddlPerant != null && ddlChild != null) { ddlPerant.attr("onchange", "DDLRelation(this.value,\'" + "DDL_" + mapExt.AttrsOfActive + "\', \'" + mapExt.MyPK + "\',\'" + ddlPerant.val() + "\')"); } } $("#DDL_" + attr.Field).val(selectVal); } html = ""; html += '
'; html += '  '; html += '
'; $("#toolBar").append(html); var pickdates = $(".ccformdate"); if (pickdates.length > 0) { $("#LAB_DTFrom").html(ur.DTFrom); $("#LAB_DTTo").html(ur.DTTo); $("#TB_DTFrom").val(ur.DTFrom); $("#TB_DTTo").val(ur.DTTo); } pickdates.each(function (i, pickdate) { var id = this.getAttribute('id'); if ($("#" + id).html() == '') { $("#" + id).html("

请选择时间

"); } pickdate.addEventListener('tap', function () { var _self = this; var optionsJson = this.getAttribute('data-options') || '{}'; var options = JSON.parse(optionsJson); var id = this.getAttribute('id'); _self.picker = new mui.DtPicker(options); _self.picker.show(function (rs) { $("#" + id).html(rs.text); $("#TB_" + id.substr(4)).val(rs.text); _self.picker.dispose(); _self.picker = null; }); }, false); }); } //初始化下拉列表框的OPERATION function InitDDLOperation(frmData, mapAttr, defVal) { var operations = ""; operations += ""; var ens = frmData[mapAttr.Field]; if (ens == null) { ens = [{ 'IntKey': 0, 'Lab': '否' }, { 'IntKey': 1, 'Lab': '是' }]; } for (var i = 0; i < ens.length; i++) { var en = ens[i]; if (en.No == undefined) operations += ""; else operations += ""; } return operations; } function SearchCondition() { //保存查询条件. var ensName = GetQueryString("EnsName"); var ur = new Entity("BP.Sys.UserRegedit"); ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs"; ur.FK_Emp = webUser.No; if ($("#TB_Key") != null && $("#TB_Key").val() != "") ur.SearchKey = $("#TB_Key").val(); else ur.SearchKey = ""; //增加字段查询 var val = ""; for (var i = 0; i < fields.length; i++) { var field = fields[i]; var strs = $("input[name='TB_" + field + "']"); if (strs.length == 1) { ur.SetPara(field, $("#TB_" + field).val()); } else { if ($("#TB_" + field + "_0").val() == "" && $("#TB_" + field + "_1").val() == "") ur.SetPara(field, ""); else ur.SetPara(field, $("#TB_" + field + "_0").val() + "," + $("#TB_" + field + "_1").val()); } } //设置查询时间. if ($("#TB_DTFrom").length == 1) ur.DTFrom = $("#TB_DTFrom").val(); if ($("#TB_DTTo").length == 1) ur.DTTo = $("#TB_DTTo").val(); //获得外键的查询条件,存储里面去. var str = ""; $("select[name^='DDL_']").each(function () { var id = $(this).attr("id"); id = id.replace("DDL_", ""); str += "@" + id + "=" + $(this).val(); }); ur.FK_Emp = webUser.No; ur.CfgKey = "SearchAttrs"; ur.Vals = str; ur.FK_MapData = ensName; ur.Save(); } /** *初始化数据信息 */ function InitData() { //创建处理器. var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm"); handler.AddUrlData() handler.AddPara("PageIdx", pageIdx); handler.AddPara("PageSize", pageSize); //查询集合 var data = handler.DoMethodReturnString("Search_SearchIt"); if (data.indexOf('err@') == 0) { mui.alert(data); return; } //当前用户页面信息. var ur = new Entity("BP.Sys.UserRegedit"); ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs"; ur.RetrieveFromDBSources(); var count = ur.GetPara("RecCount"); if (count % pageSize != 0) pages = parseInt(count / pageSize) + 1; else pages = parseInt(count / pageSize); if (pages == 0) pages = 1; data = JSON.parse(data); mapAttrs = data.Attrs; return data["DT"]; } function GetShowFields() { var idx = 0; if (mobileShowModel == 0 || mobileShowContent=="") { //默认显示map的可见的前四个字段 $.each(mapAttrs, function (i, mapAttr) { if (mapAttr.UIVisible == 0 || mapAttr.KeyOfEn == "OID" || mapAttr.KeyOfEn == "WorkID" || mapAttr.KeyOfEn == "NodeID" || mapAttr.KeyOfEn == "MyNum" || mapAttr.KeyOfEn == "MyPK") return true; if (idx < 4) showField.push(mapAttr); idx++; }); } if (mobileShowModel == 1 && mobileShowContent != "") { mobileShowContent = mobileShowContent + ","; mobileShowContent = replaceAll(mobileShowContent, " ", ""); $.each(mapAttrs, function (i, mapAttr) { if (mapAttr.UIVisible == 0 || mapAttr.KeyOfEn == "OID" || mapAttr.KeyOfEn == "WorkID" || mapAttr.KeyOfEn == "NodeID" || mapAttr.KeyOfEn == "MyNum" || mapAttr.KeyOfEn == "MyPK") return true; //记录换行的字段 if (mobileShowContent.indexOf("@" + mapAttr.KeyOfEn + ",") >= 0 || mobileShowContent.indexOf("@" + mapAttr.KeyOfEn + "@")>=0) { mapAttr.IsCR =1; showField.push(mapAttr); return true; } if (mobileShowContent.indexOf(mapAttr.KeyOfEn + ",") != -1 || mobileShowContent.indexOf(mapAttr.KeyOfEn + "@") != -1) { mapAttr.IsCR = 0; showField.push(mapAttr); } }); } if (mobileShowModel == 2 && mobileShowContent != "") { $.each(mapAttrs, function (i, mapAttr) { if (mapAttr.UIVisible == 0 || mapAttr.KeyOfEn == "OID" || mapAttr.KeyOfEn == "WorkID" || mapAttr.KeyOfEn == "NodeID" || mapAttr.KeyOfEn == "MyNum" || mapAttr.KeyOfEn == "MyPK") return true; if (mobileShowContent.indexOf("{"+mapAttr.KeyOfEn + "}") != -1) showField.push(mapAttr); }); } } function ShowPageInfo(pageType) { pageType = pageType || "search"; var pageData = InitData(); GetShowFields(); //判断字段中存在的主键 var table = document.body.querySelector('.mui-table-view'); //加载数据 var _html = ""; var val = ""; $.each(pageData, function (i, item) { var li = document.createElement('li'); if (pageType == "batch") { li.className = 'mui-table-view-cell'; li.style.paddingRight = "0px"; } else li.className = 'mui-table-view-cell mui-collapse'; li.id = item[pkFiled]; _html = ""; if (pageType == "batch") { _html += '

'; _html += ''; _html += ''; _html += '
'; _html += '
'; _html += ""; _html += '
'; //_html += ''; } else { _html = ''; _html += '
'; _html += GetRowInfo(item); _html += '
'; _html += '
'; _html += ''; } li.innerHTML = _html; table.appendChild(li); }); } function GetRowInfo(row) { var _html = ""; if (mobileShowModel == 0 || mobileShowContent == "") { showField.forEach(attr => { val = GetFieldValue(attr, row); _html += '
' + attr.Name + ':' + val + '
'; }) } if (mobileShowModel == 1 && mobileShowContent != "") { //mobileShowContent遇到@就换行 showField.forEach(attr => { val = GetFieldValue(attr, row); if (attr.IsCR == 1) _html += "
"; _html += '
' + attr.Name + ':' + val + '
'; }) } if (mobileShowModel == 2 && mobileShowContent != "") { showField.forEach(attr => { val = GetFieldValue(attr, row); mobileShowContent = mobileShowContent.replace(attr.KeyOfEn, val); }) _html += mobileShowContent; } return _html; } function GetFieldValue(attr, row) { val = row[attr.KeyOfEn] || ""; if (attr.UIContralType == 1) { val = row[attr.KeyOfEn + "T"] || ""; if (val == "") val = row[attr.KeyOfEn + "Text"] || ""; } if (attr.UIContralType == 2) { if (val == "0") val = "否"; if (val == "1") val = "是"; } if (attr.MyDataType == "6") { if (val != "") val = FormatDate(new Date(val), "yyyy-MM-dd"); } return val; } /** * 数据显示 * @param {any} mapAttrs * @param {any} data */ function ShowInfoByMapAttr(mapAttrs, data) { var lab = ""; var val = ""; _html = ""; var i = 0; $.each(mapAttrs, function (idx, mapAttr) { if (mapAttr.UIVisible == 0 || mapAttr.KeyOfEn == "OID" || mapAttr.KeyOfEn == "WorkID" || mapAttr.KeyOfEn == "NodeID" || mapAttr.KeyOfEn == "MyNum" || mapAttr.KeyOfEn == "MyPK") { return true; } lab = mapAttr.Name; val = data[mapAttr.KeyOfEn] || ""; if (mapAttr.UIContralType == 1) { val = data[mapAttr.KeyOfEn + "T"] || ""; if (val == "") val = data[mapAttr.KeyOfEn + "Text"] || ""; } if (mapAttr.UIContralType == 2) { if (val == "0") val = "否"; if (val == "1") val = "是"; } if (mapAttr.MyDataType == "6") { if (val != "") val = FormatDate(new Date(val), "yyyy-MM-dd"); } if (mapAttr.IsRichText == "1") { _html += '
'; _html += ''; _html += '
'; _html += '
'; _html += ''; _html += '
'; i++; return true; } _html += '
'; _html += ''; if (i == 0) { _html += ""; _html += ''; } else { _html += ''; } _html += '
'; i++; }) return _html; } function OpenEn(pkval) { url = cfg.UrlExt; var urlOpenType = cfg.GetPara("SearchUrlOpenType"); if (urlOpenType == 0 || urlOpenType == undefined) url = "./RefFunc/En.htm?EnName=" + ensName.substr(0, ensName.length - 1) + "&PKVal=" + pkval; if (urlOpenType == 1) url = "./RefFunc/EnOnly.htm?EnName=" + ensName.substr(0, ensName.length - 1) + "&PKVal=" + pkval; if (urlOpenType == 2) url = "../FrmViw.htm?FK_MapData=" + GetQueryString("EnsName") + "&PKVal=" + pkval; if (urlOpenType == 3) url = "../FrmViw.htm?FK_MapData=" + GetQueryString("EnsName") + "&PKVal=" + pkval; if (urlOpenType == 9) { if (url.indexOf('?') == -1) url = url + "?1=1"; if (url.indexOf('FrmID') != -1) url = url + "&WorkID=" + pkval + "&OID=" + pkval; else url = url + "&EnsName=" + ensName + "&EnName=" + enName + "&PKVal=" + pkval; } window.parent.location.href = url; }