/** * ligerUI BUG修复和重写 */ (function ($, win) { /***************** 字典相关扩展 *************************/ //字典数据 $.ehrDict = { dictDataUrl: window.root + "/basedict/getDict", //字典数据获取路径 dictCodeName: "code", //字典code字段 dictValueName: "value", //字典Value字段 dictExtendName: "extend", //字典扩展字段 sysDict: {}, //系统字典 orgDict: {}, //机构字典 stdDitc: {}, //标准字典 //后台加载数据 loadDictData: function (dictName, type, where, callBack) { var me = this; $.post( me.dictDataUrl, {type: type, name: dictName, where: where}, function (data, status) { try { if (data.successFlg) { var list = data.detailModelList; if (type == "1") //机构字典 { me.orgDict[dictName] = list; } else if (type == "2") { //标准字典 me.stdDitc[dictName] = list; } else { //系统字典 me.sysDict[dictName] = list; } if ($.isFunction(callBack)) { callBack(me.listToDict(list)); } } } catch (e) { return; } }); }, //格式转化 listToDict: function (list) { var me = this; var dictItem = {}; for (var item in list) { dictItem[list[item][me.dictCodeName]] = { value: list[item][me.dictValueName], extend: list[item][me.dictExtendName] }; } return dictItem; }, //获取字典数据 getDictData: function (dictName, type, where, callBack) { var me = this; if (dictName != null && dictName.length > 0) { var re = null; if (type == "1") //机构字典 { re = me.orgDict[dictName]; } else if (type == "2") { //标准字典 re = me.stdDitc[dictName]; } else { //系统字典 re = me.sysDict[dictName]; } if (re != null) { if (re != "loading") { return re; } } else { if (type == "1") { me.orgDict[dictName] = "loading"; } else if (type == "2") { me.stdDitc[dictName] = "loading"; } else { me.sysDict[dictName] = "loading"; } //加载数据 me.loadDictData(dictName, type, where, callBack); } } return null; } }; /******************************************************/ //重写条件选择控件 add by hzp at 20160119 $.extend($.ligerui.controls.Filter.prototype, { getValue: function () { var me = this; var options = me.options; var datas = me.getData(); return datas; } }); //重写下拉控件 add by hzp at 20160108 $.extend($.ligerDefaults.ComboBox, { selectBoxWidth: 240, resize: false, valueField: 'code', textField: 'value', extendField: 'extend', dataParmName: 'detailModelList', dict: false, //是否下拉字典控件 dictName: null, //字典名称 dictType: null, //1机构字典 2标准字典 默认系统字典 dictWhere: "" //表字典附加SQL条件 }); $.extend($.ligerui.controls.ComboBox.prototype, { _setUrl: function (url, callback) { var g = this, p = this.options; /****************** 下拉字典 ***********************/ if (p.dict) { var dict = $.ehrDict.getDictData(p.dictName, p.dictType, p.dictWhere); if (dict != null) { g.setData(dict); return; } else { p.url = url = $.ehrDict.dictDataUrl; p.urlParms = {name: p.dictName, type: p.dictType, where: p.dictWhere}; } } /***************************************************/ if (!url) return; if (p.readonly) //只读状态不加载数据 { return; } if (p.delayLoad && !g.isAccessDelay && !g.triggerLoaded) { g.isAccessDelay = true;//已经有一次延时加载了 return; } url = $.isFunction(url) ? url.call(g) : url; var urlParms = $.isFunction(p.urlParms) ? p.urlParms.call(g) : p.urlParms; if (urlParms) { for (name in urlParms) { url += url.indexOf('?') == -1 ? "?" : "&"; url += name + "=" + urlParms[name]; } } var parms = $.isFunction(p.parms) ? p.parms.call(g) : p.parms; if (p.ajaxContentType == "application/json" && typeof (parms) != "string") { parms = liger.toJSON(parms); } var ajaxOp = { type: p.ajaxType, url: url, data: parms, cache: false, dataType: 'json', beforeSend: p.ajaxBeforeSend, complete: p.ajaxComplete, success: function (result) { var data = $.isFunction(p.dataGetter) ? data = p.dataGetter.call(g, result) : result; data = p.dataParmName && data ? data[p.dataParmName] : data; if (g.trigger('beforeSetData', [data]) == false) { return; } g.setData(data); g.trigger('success', [data]); if ($.isFunction(callback)) callback(data); }, error: function (XMLHttpRequest, textStatus) { g.trigger('error', [XMLHttpRequest, textStatus]); } }; if (p.ajaxContentType) { ajaxOp.contentType = p.ajaxContentType; } $.ajax(ajaxOp); }, /***** 获取选中BUG修复 add by hzp at 20160224 **************/ getSelected:function(){ if(this.selected!=null) { return this.selected; } else{ var me = this; var options = me.options; var selected = me.selectedValue; for (var i = 0; i < me.data.length; i++) { var item = me.data[i]; if (item[options.valueField] == selected) { return item; } } } }, _setDisabled: function (value) { //禁用样式 if (value) { this.wrapper.addClass('l-text-disabled'); $(".l-trigger-cancel").remove(); } else { this.wrapper.removeClass('l-text-disabled'); } }, //获取扩展字段 getExtendValue: function () { try { var me = this; var options = me.options; var selected = me.selectedValue; for (var i = 0; i < me.data.length; i++) { var item = me.data[i]; if (item[options.valueField] == selected) { return item[options.extendField]; } } } catch (e) { return ""; } }, /****** 下拉树宽度BUG修复 add by hzp at 20160602***********************/ bulidContent: function () { var g = this, p = this.options; this.clearContent(); if (g.select) { g.setSelect(); } else if (p.tree) { /*******/ p.tree.width=g.inputText.width(); /*******/ g.setTree(p.tree); } } }); //重写Grid控件 add by hzp at 20160107 $.extend($.ligerDefaults.Grid, { // 存储总记录数的字段名 record: 'totalCount', // 数据源字段名 root: 'detailModelList', // 每页记录数 pageSize: 20, // 页记录数参数名,(提交给服务器) pagesizeParmName: 'rows', // 高度补差,当设置height:100%时,可能会有高度的误差,可以通过这个属性调整 heightDiff: -14, height: '100%', // 是否显示行序号 rownumbers: true, // 表头行的高度 headerRowHeight: 40, // 行的高度 rowHeight: 40, // 编辑器位置误差调整 editorTopDiff: 1, allowAdjustColWidth: true }); $.extend($.ligerui.controls.Grid.prototype, { _setHeight: function (h) { var g = this, p = this.options; g.unbind("SysGridHeightChanged"); if (h == "auto") { g.bind("SysGridHeightChanged", function () { if (g.enabledFrozen()) g.gridview.height(Math.max(g.gridview1.height(), g.gridview2.height())); }); return; } h = g._calculateGridBodyHeight(h); if (h > 0) { /** 列表高度计算bug修改 **/ var gridHeaderHeight = (p.headerRowHeight+1) * (g._columnMaxLevel - 1) + p.headerRowHeight + 1; /***********************/ /******** 隐藏表头 add by hzp at 2016-05-05 ************/ if(p.hideHeader) { h += 41; g.gridheader.hide(); gridHeaderHeight = 0; } /*****************************************************/ g.gridbody.height(h); if (p.frozen) { /*** 滚动条样式修改 add by hzp at 20160215***/ //解决冻结列和活动列由上至下滚动错位的问题 var w = g.gridbody.width(), w2 = $(":first-child", g.gridbody).width(); if (w2 && (w2 + 6 >= w)) { if (h > 6) g.f.gridbody.height(h - 6); } else { g.f.gridbody.height(h); } /********************************************/ } g.gridview.height(h + gridHeaderHeight); } g._updateHorizontalScrollStatus.ligerDefer(g, 10); }, //是否固定列 _onResize: function () { var g = this, p = this.options; if (p.height && p.height != 'auto') { var windowHeight = $(window).height(); //if(g.windowHeight != undefined && g.windowHeight == windowHeight) return; var h = 0; var parentHeight = null; if (typeof (p.height) == "string" && p.height.indexOf('%') > 0) { var gridparent = g.grid.parent(); if (p.inWindow) { parentHeight = windowHeight; parentHeight -= parseInt($('body').css('paddingTop')); parentHeight -= parseInt($('body').css('paddingBottom')); } else { parentHeight = gridparent.height(); } h = parentHeight * parseInt(p.height) * 0.01; if (p.inWindow || gridparent[0].tagName.toLowerCase() == "body") h -= (g.grid.offset().top - parseInt($('body').css('paddingTop'))); } else { h = parseInt(p.height); } h += p.heightDiff; g.windowHeight = windowHeight; g._setHeight(h); } else { g._updateHorizontalScrollStatus.ligerDefer(g, 10); } if (g.enabledFrozen()) { var gridView1Width = g.gridview1.width(); var gridViewWidth = g.gridview.width(); g.gridview2.css({ width: gridViewWidth - gridView1Width }); if(gridView1Width>0) { g.gridview1.css({ position:"absolute", top:"0px", left:"0px" }).show(); g.gridview2.css({ position:"absolute", top:"0px" }); } } else{ var gridView1Width = g.gridview1.width(); var gridViewWidth = g.gridview.width(); if(gridView1Width>0) { g.gridview1.hide(); g.gridview2.css({ position:"absolute", left:"0px", width: gridViewWidth }); } } g.trigger('SysGridHeightChanged'); }, _calculateGridBodyHeight: function (h) { var g = this, p = this.options; if (typeof h == "string" && h.indexOf('%') > 0) { if (p.inWindow) h = $(window).height() * parseInt(h) * 0.01; else h = g.grid.parent().height() * parseInt(h) * 0.01; } if (p.title) h -= 24; /*** 隐藏分页 高度BUG修复 add by hzp at20160121 **/ if (p.usePager && (p.pagerRender || !p.scrollToPage)) h -= g.toolbar.outerHeight(); /******************************/ if (p.totalRender) h -= 25; if (p.toolbar) h -= g.topbar.outerHeight(); /** 列表高度计算bug修改 **/ var gridHeaderHeight = (p.headerRowHeight+1) * (g._columnMaxLevel - 1) + p.headerRowHeight + 1; /***********************/ h -= (gridHeaderHeight || 0); return h; }, getColumns: function (columnLevel) { var g = this, p = this.options; var columns = []; for (var id in g._columns) { var col = g._columns[id]; /********* 字典列翻译 ***********/ if (col['dict']) { var dictName = col.dictName; //提前加载字典 $.ehrDict.getDictData(dictName, col.dictType, col.dictWhere); //渲染字典字段 col.render = function (row, index, data, _col) { var dict = $.ehrDict.getDictData(_col.dictName, col.dictType, col.dictWhere, function (response) { g.refreshColumn(_col.dictName, response); }); dict = $.ehrDict.listToDict(dict); if (dict != null) { if (dict[data] != null) { return dict[data].value; } else { return data; } } else { return ""; } } } /********************/ if (columnLevel != undefined) { if (col['__level'] == columnLevel) columns.push(col); } else { if (col['__leaf']) columns.push(col); } } return columns; }, //字典返回后刷新列值 refreshColumn: function (dictName, dict) { try { var me = this; for (var i = 0; i < me.columns.length; i++) { var col = me.columns[i]; if (col.dict && col.dictName == dictName) { var colName = col.columnname; $.each($.find("td[id$='|" + col.__id + "']", me.gridbody[0]), function (index, obj) { var code = me.rows[index][colName]; var cell = $.find("div.l-grid-row-cell-inner", obj)[0]; if (dict[code] != null) { var val = dict[code].value; if (val != undefined && val != null) { $(cell).html(val); } } else { $(cell).html(code); } }); } } } catch (e) { return; } }, queryByText: function (filedName, text) { var data = this.data.detailModelList; for (var i = 0; i < data.length; i++) { var obj=JSON.stringify(data[i]); var r = eval("("+obj+"." + filedName+")"); if (r.indexOf(text) >= 0) { this.select(data[i]); break; } } } }); //重写树函数 add by hzp at 20160107 $.extend($.ligerDefaults.Tree, { checkbox:false, parentIcon:false, childIcon:false, treeLine:false, nodeWidth:180 }); $.extend($.ligerui.controls.Tree.prototype, { _upadteTreeWidth: function () { var g = this, p = this.options; var treeWidth = g.maxOutlineLevel * 22; if (p.checkbox) treeWidth += 22; if (p.parentIcon || p.childIcon) treeWidth += 22; treeWidth += p.nodeWidth; treeWidth = p.adjustToWidth? $(g.element).width(): treeWidth; // TODO [代码片段001][修复树宽度自适应问题][yezehua] g.tree.width(treeWidth); }, getDataByID: function (id) { var g = this, p = this.options; var data = null; if (g.data && g.data.length) { return find(g.data); } function find(items) { for (var i = 0; i < items.length; i++) { var dataItem = items[i]; if (dataItem[p.idFieldName] == id) return dataItem; if (dataItem.children && dataItem.children.length) { /*** BUG修复 ***/ var pre = find(dataItem.children); if (pre != null) return pre; /*************/ } } return null; } $("li", g.tree).each(function () { if (data) return; var treeitem = $(this); var treedataindex = parseInt(treeitem.attr("treedataindex")); var treenodedata = g._getDataNodeByTreeDataIndex(g.data, treedataindex); if (treenodedata[p.idFieldName].toString() == id.toString()) { data = treenodedata; } }); return data; }, /** * 扩展方法1: * queryByText: 根据名字找出树的节点,并且打开节点 */ queryByText: function (text) { var $g = this, p = this.options; var nodeText = $("span", $g.tree); for (var i = 0; i < nodeText.length; i++) { if ($(nodeText[i]).text().indexOf(text) >= 0) { var id = $(nodeText[i]).closest("li").attr("id"); $g.expandNode(id); $g.selectNode(id); break; } } }, queryByTextInRe: function (text) { var $g = this, p = this.options; //先清除颜色 var nodeText = $("span", $g.tree); for (var j = 0; j < nodeText.length;j++) { $(nodeText[j]).removeAttr('style'); $(nodeText[j]).closest("div").removeClass("l-selected"); } for (var i = 0; i < nodeText.length; i++) { if ($(nodeText[i]).text().indexOf(text) >= 0) { var id = $(nodeText[i]).closest("li").attr("id"); $g.expandNode(id); // $g.selectNode(id); $(nodeText[i]).attr('style','color:#3194d5'); } } }, /** * expandNode:根据id打开节点 * @param id */ expandNode: function (id) { var $li = $("#" + id, this.tree).closest("li"); var outlinelevel = $li.attr("outlinelevel"); for (var j = 0; j < outlinelevel; j++) { if (j == 0) { $li.parent().parent().children(".l-body").children(".l-expandable-close").removeClass("l-expandable-close").addClass("l-expandable-open"); $li = $li.parent().show(); } else { $li.parent().children(".l-body").children(".l-expandable-close").removeClass("l-expandable-close").addClass("l-expandable-open"); $li = $li.parent().parent().show(); } } }, /** * 扩展方法2:子节点是否全选 * @param treenodedata * @returns {boolean} */ isIncomplete: function (treenodedata) { var str = JSON.stringify(treenodedata.children); return (str.indexOf('"ischecked":null')!=-1 || str.indexOf('"ischecked":false')!=-1) && str.indexOf('"ischecked":true')!=-1; }, //根据data生成最终完整的tree html _getTreeHTMLByData: function (data, outlineLevel, isLast, isExpand) { var g = this, p = this.options; if (g.maxOutlineLevel < outlineLevel) g.maxOutlineLevel = outlineLevel; isLast = isLast || []; outlineLevel = outlineLevel || 1; var treehtmlarr = []; if (!isExpand) treehtmlarr.push('