(function (w) { var Common = function(){ } // 定时刷新列表时间 Common.prototype.setIntervalTimes = 3 * 60 * 1000; /** * 加载层 */ Common.prototype.loading = function(){ $("#loading-tips").addClass("showPrompt"); } /** * 去除加载层 */ Common.prototype.closeload = function(){ $("#loading-tips").removeClass("showPrompt"); } /** * 初始化表格事件 */ Common.prototype.initTabEvent = function(tabId){ // dataTable 默认错误提示是alert,这里做处理 $.fn.dataTable.ext.errMode = function( settings, tn, msg){ //打印msg,和tn来判断,进了这个方法都是ajax走了error才会到这里来 console.log(msg); } var $tab = $("#"+tabId); // 当Ajax请求完成时触发 $tab.on('xhr.dt', function ( e, settings, json, xhr ){ // json 为空 可能是登陆超时,刷新页面 if(json == null){ console.error("请求错误"); // window.location.reload (true); } } ); var dom;// 一个节点对象 // 选中行保存行节点对象 $tab.find("tbody").on( 'click', 'tr', function () { if(dom){ //上一次选中行颜色恢复 $(dom).css("background-color", ""); } //选中行变色 $( this ).css("background-color", "#B0BED9"); dom = this; }); var $tablebody = $('#'+tabId+' tbody'); //单击选择该数据返回ID $tablebody.on( 'click', 'tr', function () { if(!$(this)[0].hasAttribute("clicheckedid")){ $tablebody.find("[clicheckedid]").removeAttr("clicheckedid"); var data = $tab.DataTable().row(this).data(); var id = ""; if(data) id = data.id; $(this).attr("clicheckedid", id); } } ); } /** * 获取表格选中行的id */ Common.prototype.getTabCheckedTrId = function(tabId){ var $tab = $("#"+tabId); var dom = $('#'+tabId+' tbody').find("[clicheckedid]"); var id = ""; if(dom) id = dom.attr("clicheckedid"); return id; } /** * 表格刷新 */ Common.prototype.tabRefresh = function(tabId){ var $tab = $("#"+tabId); $tab.dataTable().api().ajax.reload( null, false ); // 刷新表格数据,分页信息不会重置 } /** * 加载委托方下拉框控件数据 */ Common.prototype.initWtfdata = function(id){ $.ajax({ url: "ht/findWtfAll", type: "post", contentType:"application/json;charset=utf-8", // async: false,// 同步请求 防止编辑时延迟 data: JSON.stringify({}), success: function(data){ if (data.success) { var list = data.data; if(list && list.length>0){ var html=""; $.each(list,function (i,obj) { if(obj.name != ""){ html+=""; } $.each(list,function (i,obj) { if(obj.name != ""){ html+=""; } $.each(list,function (i,obj) { if(obj.name != ""){ html+=""; $.each(list,function (i,obj) { if(obj.name != ""){ html+=""; $.each(list,function (i,obj) { if(obj.name != ""){ html+=""; $.each(list,function (i,obj) { if(obj.name != ""){ html+=""); if(pinpai != "") $('#'+ modalId +" select[name='pinpai']").html(""); if(chexi != "") $('#'+ modalId +" select[name='chexi']").html(""); // $('#'+ modalId +" select[name='chexing']").html(""); $('#'+ modalId +" input[name='chexing']").val(chexing); } /** * 模态框 关闭时 里面的 清除内容 (解决模态框只请求一次服务器页面,内容不好刷新) */ Common.prototype.modalHideDelHtml = function(modalId) { $('#'+modalId).on('hide.bs.modal', function () { $(this).removeData("bs.modal"); //清除html $(this).find("div.modal-content").html(""); }) } /** * 初始化省市区下拉框数据 */ Common.prototype.initCitySelect = function(id, pid, async) { if(pid === undefined) pid = "1"; if(async === undefined) async = true; $.ajax({ url: "common/findCity", type: "post", contentType:"application/json;charset=utf-8", async: async,// 同步请求 防止编辑时延迟 data: JSON.stringify({pid: pid}), success: function(data){ if (data.success) { var list = data.data; if(list && list.length>0){ var html=""; $.each(list,function (i,obj) { if(obj.name != ""){ html+=""; } for(var k in data){ html+="