- ',
'
var Public = Public || {}; var Business = Business || {}; Public.isIE6 = !window.XMLHttpRequest; //ie6 $(function(){ //菜单按钮 $('.ui-btn-menu .menu-btn').on('mouseenter.menuEvent',function(e){ if($(this).hasClass("ui-btn-dis")) { return false; } $(this).parent().addClass('ui-btn-menu-cur'); $(this).blur(); e.preventDefault(); }); $('.ui-btn-menu').on('mouseleave.menuEvent',function(e){ $(this).removeClass('ui-btn-menu-cur'); }); $(document).on('click.menu',function(e){ var target = e.target || e.srcElement; $('.ui-btn-menu').each(function(){ var menu = $(this); if($(target).closest(menu).length == 0 && $('.con',menu).is(':visible')){ menu.removeClass('ui-btn-menu-cur'); } }) }); }); //设置表格宽高 Public.setGrid = function(adjustH, adjustW){ var defaultPage = Public.getDefaultPage(); if(defaultPage.SYSTEM.skin === 'green'){ var adjustH = adjustH || 70; } else { var adjustH = adjustH || 65; }; var adjustW = adjustW || 20; var gridW = $(window).width() - adjustW, gridH = $(window).height() - $(".grid-wrap").offset().top - adjustH; return { w : gridW, h : gridH } }; //重设表格宽高 Public.resizeGrid = function(adjustH, adjustW){ var grid = $("#grid"); var gridWH = Public.setGrid(adjustH, adjustW); grid.jqGrid('setGridHeight', gridWH.h); grid.jqGrid('setGridWidth', gridWH.w); }; //表格宽度自适应 Public.autoGrid = function($grid){ $grid.jqGrid('setGridWidth', $grid.closest('.grid-wrap').innerWidth() -2 );//去掉border的宽度 } //自定义报表宽高初始化以及自适应 Public.initCustomGrid = function(tableObj){ //去除报表原始定义的宽度 $(tableObj).css("width") && $(tableObj).attr("width","auto"); //获取报表宽度当做最小宽度 var _minWidth = $(tableObj).outerWidth(); $(tableObj).css("min-width",_minWidth+"px"); //获取当前window对象的宽度作为报表原始的宽度 $(tableObj).width($(window).width() - 74); $(tableObj).closest('.mod-report').height($(window).height() - 66); //设置resize事件 var _throttle = function(method,context){ clearTimeout(method.tid); method.tid = setTimeout(function(){ method.call(context); },100) }; var _resize = function(){ $(tableObj).width($(window).width() - 74); $(tableObj).closest('.mod-report').height($(window).height() - 66); }; $(window).resize(function() { _throttle(_resize); }); } /** * 节点赋100%高度 * * @param {object} obj 赋高的对象 */ Public.setAutoHeight = function(obj){ if(!obj || obj.length < 1){ return ; } Public._setAutoHeight(obj); $(window).bind('resize', function(){ Public._setAutoHeight(obj); }); } Public._setAutoHeight = function(obj){ obj = $(obj); //parent = parent || window; var winH = $(window).height(); var h = winH - obj.offset().top - (obj.outerHeight() - obj.height()); obj.height(h); } //操作项格式化,适用于有“修改、删除”操作的表格 Public.operFmatter = function (val, opt, row) { var html_con = '
'; return html_con; }; Public.billsOper = function (val, opt, row) { var html_con = ''; return html_con; }; Public.billsOper_goods = function (val, opt, row) { var html_con = ''; return html_con; }; Public.dateCheck = function(){ $('.ui-datepicker-input').bind('focus', function(e){ $(this).data('original', $(this).val()); }).bind('blur', function(e){ var reg = /((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/; var _self = $(this); setTimeout(function(){ if(!reg.test(_self.val())) { parent.Public.tips({type:1, content : '日期格式有误!如:2013-08-08。'}); _self.val(_self.data('original')); }; }, 10) }); } //日期格式化 Date.prototype.format = function(format){ if(!format){ format = 'yyyy-MM-dd';//默认1997-01-01这样的格式 } var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); } } return format; } Date.prototype.addMonths= function(m) { var d = this.getDate(); this.setMonth(this.getMonth() + m); if (this.getDate() < d) this.setDate(0); }; Date.prototype.addDays = function(d) { this.setDate(this.getDate() + d); }; Public.getHostName = function(){ var defaultPage = Public.getDefaultPage(); var result = defaultPage.location.hostname; if(!/.com/.test(result)){ //是IP形式的,兼容内网 result += ':'+defaultPage.location.port; } return result }; //根据之前的编码生成下一个编码 Public.getSuggestNum = function(prevNum){ if (prevNum == '' || !prevNum) { return ''; } var reg = /^([a-zA-Z0-9\-_]*[a-zA-Z\-_]+)?(\d+)$/; var match = prevNum.match(reg); if (match) { var prefix = match[1] || ''; var prevNum = match[2]; var num = parseInt(prevNum, 10) + 1; var delta = prevNum.toString().length - num.toString().length; if (delta > 0) { for (var i = 0; i < delta; i++) { num = '0' + num; } } return prefix + num; } else { return ''; } }; Public.bindEnterSkip = function(obj, func){ var args = arguments; $(obj).on('keydown', 'input:visible:not(:disabled)', function(e){ if (e.keyCode == '13') { var inputs = $(obj).find('input:visible:not(:disabled)'); var idx = inputs.index($(this)); idx = idx + 1; if (idx >= inputs.length) { if (typeof func == 'function') { var _args = Array.prototype.slice.call(args, 2 ); func.apply(null,_args); } } else { inputs.eq(idx).focus(); } } }); }; /*获取URL参数值*/ Public.getRequest = Public.urlParam = function() { var param, url = location.search, theRequest = {}; if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0, len = strs.length; i < len; i ++) { param = strs[i].split("="); theRequest[param[0]]=decodeURIComponent(param[1]); } } return theRequest; }; /** * [ajax description] * @param {[type]} ajaxOpts [description] * 默认json格式 * 默认post方式 * @return {[type]} [description] */ Public.ajax = function(ajaxOpts){ var opts = { type: "POST", dataType: "json", error: function(err){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); } }; $.extend(true, opts, ajaxOpts); var success = ajaxOpts.success; opts.success = function(data, status){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ success && success(data, status); } $.ajax(opts); }; /* 通用post请求,返回json url:请求地址, params:传递的参数{...}, callback:请求成功回调 */ Public.ajaxPost = function(url, params, callback, errCallback){ $.ajax({ type: "POST", url: url, data: params, dataType: "json", success: function(data, status){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ callback(data); }, error: function(err,ms){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); errCallback && errCallback(err); } }); }; //扩展对象方法 $.fn.extend({ //为对象新增ajaxPost方法 ajaxPost:function(url, params, callback, errCallback){ var $this = $(this); var loading; var myTimer; var preventTooFast = 'ui-btn-dis'; var ajaxOpts = { type: "POST", url: url, data: params, dataType: "json", success: function(data, status){ callback(data); }, error: function(err){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); errCallback && errCallback(err); } } $.extend(true, ajaxOpts, { timeout : 20000, beforeSend : function(){ $this.addClass(preventTooFast); myTimer = setTimeout(function(){ $this.removeClass(preventTooFast); },2000) loading = $.dialog.tips('提交中,请稍候...', 1000, 'loading.gif', true); }, success : function(data){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ callback(data); }, complete : function(){ loading.close(); }, error: function(err){ parent.Public.tips({type: 2, content : '操作无法成功,请稍后重试!'}); errCallback && errCallback(err); } }); if($this.hasClass(preventTooFast)){ return; } $.ajax(ajaxOpts); } }); Public.ajaxGet = function(url, params, callback, errCallback){ $.ajax({ type: "GET", url: url, dataType: "json", data: params, success: function(data, status){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ callback(data); }, error: function(err){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); errCallback && errCallback(err); } }); }; /*操作提示*/ Public.tips = function(options){ return new Public.Tips(options); } Public.Tips = function(options){ var defaults = { renderTo: 'body', type : 0, autoClose : true, removeOthers : true, time : undefined, top : 10, onClose : null, onShow : null } this.options = $.extend({},defaults,options); this._init(); !Public.Tips._collection ? Public.Tips._collection = [this] : Public.Tips._collection.push(this); } Public.Tips.removeAll = function(){ try { for(var i=Public.Tips._collection.length-1; i>=0; i--){ Public.Tips._collection[i].remove(); } }catch(e){} } Public.Tips.prototype = { _init : function(){ var self = this,opts = this.options,time; if(opts.removeOthers){ Public.Tips.removeAll(); } this._create(); if(opts.autoClose){ time = opts.time || opts.type == 1 ? 5000 : 3000; window.setTimeout(function(){ self.remove(); },time); } }, _create : function(){ var opts = this.options, self = this; if(opts.autoClose) { this.obj = $('谢谢您使用本产品,您的当前服务已经到期,到期3个月后数据将被自动清除,如需继续使用请购买/续费!
', '(续费后请刷新页面或重新登录。)
', '请联系管理员为您授权!
', '