function getUrlParam(name){ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURI(r[2]); return null; } function parseDate(date){ var y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(), h = date.getHours(), i = date.getMinutes(); var now = new Date(), _y = now.getFullYear(), _m = now.getMonth() + 1, _d = now.getDate(); if(_y != y) { return y + '-' + m + '-' + d + ' ' + h + ':' + i; } else { if(_m != m) { return m + '月' + d + '号' + h + '点' + i + '分'; } else { if(_d != d) { return d + '号' + h + '点' + i + '分'; } else { return (h < 12 ? '上午' : '下午' ) + h + '点' + i + '分'; } } } } /* * 锁定表头和列 * * 参数定义 * table - 要锁定的表格元素或者表格ID * freezeRowNum - 要锁定的前几行行数,如果行不锁定,则设置为0 * freezeColumnNum - 要锁定的前几列列数,如果列不锁定,则设置为0 * width - 表格的滚动区域宽度 */ function freezeTable(table, freezeRowNum, freezeColumnNum, width) { if (typeof(freezeRowNum) == 'string') freezeRowNum = parseInt(freezeRowNum); if (typeof(freezeColumnNum) == 'string') freezeColumnNum = parseInt(freezeColumnNum); var tableId; if (typeof(table) == 'string') { tableId = table; table = $('#' + tableId); } else tableId = table.attr('id'); if(table.width() <= width) return; height = table.height() + 10; var divTableLayout = $("#" + tableId + "_tableLayout"); if (divTableLayout.length != 0) { divTableLayout.before(table); divTableLayout.empty(); } else { table.after("
"); divTableLayout = $("#" + tableId + "_tableLayout"); } var html = ''; if (freezeRowNum > 0 && freezeColumnNum > 0) html += ''; if (freezeRowNum > 0) html += ''; if (freezeColumnNum > 0) html += ''; html += ''; $(html).appendTo("#" + tableId + "_tableLayout"); var divTableFix = freezeRowNum > 0 && freezeColumnNum > 0 ? $("#" + tableId + "_tableFix") : null; var divTableHead = freezeRowNum > 0 ? $("#" + tableId + "_tableHead") : null; var divTableColumn = freezeColumnNum > 0 ? $("#" + tableId + "_tableColumn") : null; var divTableData = $("#" + tableId + "_tableData"); divTableData.append(table); if (divTableFix != null) { var tableFixClone = table.clone(true); tableFixClone.attr("id", tableId + "_tableFixClone"); divTableFix.append(tableFixClone); } if (divTableHead != null) { var tableHeadClone = table.clone(true); tableHeadClone.attr("id", tableId + "_tableHeadClone"); divTableHead.append(tableHeadClone); } if (divTableColumn != null) { var tableColumnClone = table.clone(true); tableColumnClone.attr("id", tableId + "_tableColumnClone"); divTableColumn.append(tableColumnClone); } $("#" + tableId + "_tableLayout table").css("margin", "0"); if (freezeRowNum > 0) { var HeadHeight = 0; var ignoreRowNum = 0; $("#" + tableId + "_tableHead tr:lt(" + freezeRowNum + ")").each(function () { if (ignoreRowNum > 0) ignoreRowNum--; else { var td = $(this).find('td:first, th:first'); HeadHeight += td.outerHeight(true); ignoreRowNum = td.attr('rowSpan'); if (typeof(ignoreRowNum) == 'undefined') ignoreRowNum = 0; else ignoreRowNum = parseInt(ignoreRowNum) - 1; } }); HeadHeight += 2; divTableHead.css("height", HeadHeight); divTableFix != null && divTableFix.css("height", HeadHeight); } if (freezeColumnNum > 0) { var ColumnsWidth = 0; var ColumnsNumber = 0; $("#" + tableId + "_tableColumn tr:eq(" + freezeRowNum + ")").find("td:lt(" + freezeColumnNum + "), th:lt(" + freezeColumnNum + ")").each(function () { if (ColumnsNumber >= freezeColumnNum) return; ColumnsWidth += $(this).outerWidth(true); ColumnsNumber += $(this).attr('colSpan') ? parseInt($(this).attr('colSpan')) : 1; }); ColumnsWidth += 2; divTableColumn.css("width", ColumnsWidth); divTableFix != null && divTableFix.css("width", ColumnsWidth); } divTableData.scroll(function () { divTableHead != null && divTableHead.scrollLeft(divTableData.scrollLeft()); divTableColumn != null && divTableColumn.scrollTop(divTableData.scrollTop()); }); divTableFix != null && divTableFix.css({ "overflow": "hidden", "position": "absolute", "z-index": "50" }); divTableHead != null && divTableHead.css({ "overflow": "hidden", "width": width, "position": "absolute", "z-index": "45" });// - 17 divTableColumn != null && divTableColumn.css({ "overflow": "hidden", "height": height, "position": "absolute", "z-index": "40" });// - 17 divTableData.css({ "overflow": "scroll", "width": width, "height": height, "position": "absolute" }); divTableFix != null && divTableFix.offset(divTableLayout.offset()); divTableHead != null && divTableHead.offset(divTableLayout.offset()); divTableColumn != null && divTableColumn.offset(divTableLayout.offset()); divTableData.offset(divTableLayout.offset()); } /* * 调整锁定表的宽度和高度,这个函数在resize事件中调用 * * 参数定义 * table - 要锁定的表格元素或者表格ID * width - 表格的滚动区域宽度 */ function adjustTableSize(table, width) { var tableId; if (typeof(table) == 'string') tableId = table; else tableId = table.attr('id'); height = $("#" + tableId).height() + 10; $("#" + tableId + "_tableLayout").width(width).height(height); $("#" + tableId + "_tableHead").width(width);// - 17 $("#" + tableId + "_tableColumn").height(height);// - 17 $("#" + tableId + "_tableData").width(width).height(height); } //返回当前页面宽度 function pageWidth() { if ($.browser.msie) { return document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth; } else { // - padding return self.innerWidth - 30; } }; // close page function closePage() { top.window.opener = top; top.window.open('','_self',''); top.window.close(); } $(document).ready(function() { //init custom event(trigger when tabpane active for the first time) $.event.special.boxready = { /** * 初始化事件处理器 - this指向元素 * @param 附加的数据 * @param 事件类型命名空间 * @param 回调函数 */ setup: function(data, namespaces, eventHandle) { var elem = this; $.event.add(elem, 'click', function (event) { if ($.data(elem, '@loaded') !== true) { $.event.trigger('boxready', null, elem); $.data(elem, '@loaded', true); } }); }, /** * 卸载事件处理器 - this指向元素 * @param 事件类型命名空间 */ teardown: function(namespaces) { var elem = this; $.event.remove(elem, 'click'); $.removeData(elem, '@loaded'); } }; var cls = 'active', instance = null, current = null, readyTime = new Date(); // toggle tabs $('.nav-tabs>li>a').click(function(){ if(!$(this).hasClass(cls)) { var nav = $(this).parent().parent(), bd = nav.next(), old = nav.children('.' + cls).index(), index = $(this).parent().index(); $('.tab-pane:eq(' + old + ')', bd).removeClass(cls); $('.tab-pane:eq(' + index + ')', bd).addClass(cls); nav.children('.' + cls).removeClass(cls); $(this).parent().addClass(cls); } }); // modal dialog var dialog = { show: function(title, content, timeout, callback){ var back = $('.modal-backdrop'), modal = $('.modal'), tt = $('.modal-title', modal), tb = $('.modal-body', modal); back.css('display', 'block'); modal.css('display', 'block'); tt.text(title); if(timeout && timeout > 0) { content = '| ' + k + ' | |
| ' + b + ' | '; html += '' + g[b] + ' | '; html += '
| ' + b + ' | '; html += '' + bill[b] + ' | '; html += '
| ' + c + ' | '; if(detail[c] && detail[c].length > 0) { $.each(detail[c], function(i, p){ html += '' + p + ' | '; }); } else { html += '(无) | '; } html += '
'; html += '' + h.jn_dealManName + ''; html += ''; if(h.jn_operatedDescription || h.jn_nodeDescription || h.jn_infoReceiver) { html += ''; html += '' + h.jn_dealResult + ''; html += ''; html += ''; html += '
' + h.jn_infoReceiver + '
'; if(h.jn_operatedDescription) { if(h.jn_operatedDescription.indexOf('(是)') > 0 || h.jn_operatedDescription.indexOf('(否)') > 0) { html += ''; html += "下一步审批节点有多位处理人,请指定一位:"; html += '
'; html += ''; dialog.show('下一步', html); // choose one to handle next node $('#confirm').click(function(){ appointNext(result.actorUsers[0].JP_NODEID, getBoxValue('form input[type="radio"]'), callback); }); // notice evenyone to receive next node $('#cancel').click(function(){ noticeNext(result.actorUsers[0].JP_NODEID, result.actorUsers[0].JP_CANDIDATES, callback); }); } else { callback && callback.call(); } } }); }; // appoint one to deal next var appointNext = function(nodeId, user, callback) { // $.post(basePath + 'common/takeOverTask.action', { // em_code: user.substring(user.lastIndexOf('(') + 1, user.length - 1), // nodeId: nodeId, // _noc: 1 // }, function(result, text) { // if(result.success) // callback && callback.call(); // else // dialog.show('错误', '指派失败,请稍后再试!'); // }); $.ajax({ url:basePath + 'common/takeOverTask.action', type: 'POST', data: {em_code: user.substring(user.lastIndexOf('(') + 1, user.length - 1), nodeId: nodeId, _noc: 1}, success: function(result){ if(result.success) callback && callback.call(); }, error: function(xhr){ if(xhr.responseText) { var response =$.evalJSON(xhr.responseText); if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') { dialog.show('获取信息失败', '请先登录!'); } else { dialog.show('指派失败', response.exceptionInfo); } } } }); }; // notice next users var noticeNext = function(nodeId, users, callback) { // $.post(basePath + 'common/processpaging.action', { // persons: unescape(users.join(',')), // nodeId: nodeId, // _noc: 1 // }, function(result, text) { // if(result.success) // callback && callback.call(); // }); $.ajax({ url:basePath + 'common/processpaging.action', type: 'POST', data: {persons: unescape(users.join(',')), nodeId: nodeId, _noc: 1}, success: function(result){ if(result.success) callback && callback.call(); }, error: function(xhr){ if(xhr.responseText) { var response =$.evalJSON(xhr.responseText); if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') { dialog.show('获取信息失败', '请先登录!'); } else { dialog.show('错误', response.exceptionInfo); } } } }); }; // load next process var processNext = function(id) { if(id != '-1') { var url = window.location.href; window.location.href = url.substr(0, url.indexOf('?') + 1) + 'nodeId=' + id; } else { dialog.show('提示', '暂时没有新的审批任务了!'); } }; // is valid var isValid = function() { var deals = $('#points input'); if(deals.length > 0) { $.each(deals, function(i, d){ var e = $(d), type = e.attr('type'), val = e.val(); if((type === 'text' || type === 'date') && !val) return false; }); } return true; }; // get your points var getDealPoints = function() { var deals = $('#points input'); if(deals.length > 0) { var points = []; $.each(deals, function(i, d){ var e = $(d), text = e.attr('title'), type = e.attr('type'), val = e.val(), lg = e.attr('logic'); val = type == 'checkbox' ? (e.is(':checked') ? '是' : '否') : val; points.push(text + '(' + val + ')' + (lg ? '@' + lg + '@' : '')); }); return points.join(';'); } return null; }; // agree var agree = function() { if(!isValid()) { dialog.show(' 警告', '您还有审批要点问题没处理!', -1); return; } setLoading(true); // $.post(basePath + 'common/review.action', { // taskId: nodeId, // nodeName: current.jp_nodeName, // nodeLog: $('#deal-msg').val(), // holdtime: ((new Date() - readyTime) / 1000).toFixed(0), // customDes: getDealPoints(), // result: true, // _noc: 1 // }, function(result, text) { // setLoading(false); // if(result.success) { // if (result.nextnode == '0') { // dialog.show('审批成功', '您暂时没有其它的审批任务了。'); // } else { // if(result.after) { // if (result.after.trim().substr(0, 12) == 'AFTERSUCCESS') { // dialog.show('审批出现提示:' + result.after.replace('AFTERSUCCESS', ''), // '自动为您跳转到下一条...', 5, function(){ // nextStep(function(){ // processNext(result.nextnode); // }); // }); // } else { // dialog.show('审批出现异常', result.after); // } // } else { // dialog.show('审批成功', '自动为您跳转到下一条...', 1, function(){ // nextStep(function(){ // processNext(result.nextnode); // }); // }); // } // } // } else if (result.exceptionInfo){ // dialog.show('无法审批', result.exceptionInfo); // } else { // dialog.show('处理结果', "该任务已处理,不能重复操作!"); // } // }); $.ajax({ url:basePath + 'common/review.action', type: 'POST', data: {taskId: nodeId, nodeName: current.jp_nodeName, nodeLog: $('#deal-msg').val(), holdtime: ((new Date() - readyTime) / 1000).toFixed(0),customDes: getDealPoints(),result: true,_noc: 1}, success: function(result){ setLoading(false); if(result.success) { if (result.nextnode == '0') { dialog.show('审批成功', '您暂时没有其它的审批任务了。'); } else { if(result.after) { if (result.after.trim().substr(0, 12) == 'AFTERSUCCESS') { dialog.show('审批出现提示:' + result.after.replace('AFTERSUCCESS', ''), '自动为您跳转到下一条...', 5, function(){ nextStep(function(){ processNext(result.nextnode); }); }); } else { dialog.show('审批出现异常', result.after); } } else { dialog.show('审批成功', '自动为您跳转到下一条...', 1, function(){ nextStep(function(){ processNext(result.nextnode); }); }); } } } }, error: function(xhr){ setLoading(false); if(xhr.responseText) { var response =$.evalJSON(xhr.responseText); if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') { dialog.show('获取用户信息失败', '请先登录!'); } else { dialog.show('无法审批', response.exceptionInfo); } } } }); }; $('#agree').click(function(){ agree(); }); // disagree -> return back var disagree = function(backNode, msg){ setLoading(true); // $.post(basePath + 'common/review.action', { // taskId: nodeId, // nodeName: current.jp_nodeName, // backTaskName: backNode, // nodeLog: msg, // holdtime: ((new Date() - readyTime) / 1000).toFixed(0), // result: false, // _noc: 1 // }, function(result, text) { // setLoading(false); // if(result.success) { // if(result.after) { // dialog.show('回退过程出现提示:' + result.after); // } else { // dialog.show('回退成功', '自动为您跳转到下一条...', 1, function(){ // nextStep(function(){ // processNext(result.nextnode); // }); // }); // } // } else { // dialog.show('处理结果', "该任务已处理,不能重复操作!"); // } // }); $.ajax({ url:basePath + 'common/review.action', type: 'POST', data: {taskId: nodeId, nodeName: current.jp_nodeName, backTaskName: backNode, nodeLog: msg, holdtime: ((new Date() - readyTime) / 1000).toFixed(0), result: false, _noc: 1}, success: function(result){ setLoading(false); if(result.success) { if(result.after) { dialog.show('回退过程出现提示:' + result.after); } else { dialog.show('回退成功', '自动为您跳转到下一条...', 1, function(){ nextStep(function(){ processNext(result.nextnode); }); }); } } else { dialog.show('处理结果', "该任务已处理,不能重复操作!"); } }, error: function(xhr){ setLoading(false); if(xhr.responseText) { var response =$.evalJSON(xhr.responseText); if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') { dialog.show('获取用户信息失败', '请先登录!'); } else { dialog.show('错误', response.exceptionInfo); } } } }); }; $('#disagree').click(function(){ getHistory(instance, function(nodes){ var html = ''; dialog.show('回退到节点', html); // choose one to back $('#back').click(function(){ var msg = $('#back-msg').val(); if (!msg) { $('#back_err').text('请填写您不同意的原因!'); $('#back-msg').focus(); } else { disagree(getBoxValue('form input[type="radio"]'), msg); } }); // cancel $('#cancel2').click(function(){ dialog.hide(); }); }); }); // end var end = function(){ setLoading(true); // $.post(basePath + 'common/endProcessInstance.action', { // processInstanceId: instance, // holdtime: ((new Date() - readyTime) / 1000).toFixed(0), // nodeId: nodeId, // _noc: 1 // }, function(result, text) { // setLoading(false); // if(result.success) { // dialog.show('流程已结束', '自动为您跳转到下一条...', 1, function(){ // nextStep(function(){ // processNext(result.nextnode); // }); // }); // } else { // dialog.show('警告', "流程实例不存在!"); // } // }); $.ajax({ url:basePath + 'common/endProcessInstance.action', type: 'POST', data: {processInstanceId: instance, holdtime: ((new Date() - readyTime) / 1000).toFixed(0), nodeId: nodeId, _noc: 1}, success: function(result){ setLoading(false); if(result.success) { dialog.show('流程已结束', '自动为您跳转到下一条...', 1, function(){ nextStep(function(){ processNext(result.nextnode); }); }); } else { dialog.show('警告', "流程实例不存在!"); } }, error: function(xhr){ setLoading(false); if(xhr.responseText) { var response =$.evalJSON(xhr.responseText); if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') { dialog.show('获取用户信息失败', '请先登录!'); } else { dialog.show('错误', response.exceptionInfo); } } } }); }; $('#end').click(function(){ end(); }); // change var change = function(user, msg){ if(!user) { $('#change_err').text('您还没选择变更人!'); return; } if(!isValid()) { $('#change_err').text('您还有审批要点问题没处理!'); return; } setLoading(true); // $.post(basePath + 'common/setAssignee.action', { // taskId: nodeId, // assigneeId: user, // processInstanceId: instance, // customDes: getDealPoints(), // description: msg, // _noc: 1 // }, function(result, text) { // setLoading(false); // if(result.result) { // dialog.show('处理结果', '节点已成功变更'); // } else { // dialog.show('处理结果', "任务不存在,无法变更!"); // } // }); $.ajax({ url:basePath + 'common/setAssignee.action', type: 'POST', data: {taskId: nodeId, assigneeId: user, processInstanceId: instance, ncustomDes: getDealPoints(), description: msg, _noc: 1}, success: function(result){ setLoading(false); if(result.result) { dialog.show('处理结果', '节点已成功变更'); } else { dialog.show('处理结果', "任务不存在,无法变更!"); } }, error: function(xhr){ setLoading(false); if(xhr.responseText) { var response =$.evalJSON(xhr.responseText); if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') { dialog.show('获取用户信息失败', '请先登录!'); } else { dialog.show('错误', response.exceptionInfo); } } } }); }; $('#change').click(function(){ var html = ''; dialog.show('变更办理人', html); // search deal man $('#em_new').bind('focus', function(){ if($(this).val()) { $(this).parent().children('.dropdown-menu').css('display', 'block'); } }); $('#em_new').bind('change', function(){// 点击获取变更的候选人 var v = $(this).val(); var view = $(this).parent().children('.dropdown-menu'); if(v) { view.css('display', 'block'); getSearchResult(v); } else { view.css('display', 'none'); } }); $('#em_new').bind('keyup', function(event){// 回车获取变更的候选人 if(event.keyCode == 13) { event.preventDefault(); var v = $(this).val(); var view = $(this).parent().children('.dropdown-menu'); if(v) { view.css('display', 'block'); getSearchResult(v); } else { view.css('display', 'none'); } } }); $('#change_search_icon').bind('click', function(event){// 变更查询放大镜图标点击获取变更的候选人 var v = $('#em_new').val(); var view = $('#em_new').parent().parent().children('.dropdown-menu'); if(v) { view.css('display', 'block'); getSearchResult(v); } else { view.css('display', 'none'); } }); // change $('#change3').click(function(){ var msg = $('#change-msg').val(); change($('#em_code').text(), msg); }); // cancel $('#cancel3').click(function(){ dialog.hide(); }); }); // get search result var getSearchResult = function(input) { setLoading(true); $.post(basePath + 'hr/emplmana/search.action', { keyword: input }, function(result, text){ setLoading(false); if(result.length > 0) { parseSearchResult(result); } }); }; // parse search result var parseSearchResult = function(datas){ var html = ''; $.each(datas, function(i, d){ var e = d.split('\n'); html += ''; html += '' + (e[0] || '(空)') + ''; html += '' + e[2] + '(' + e[1] + ')'; html += ''; }); $('#em_search').html(html); }; //关联查询 var dealRelative = function(caller) { $('#expand').html('展开 '); $('#expand').click(function(){ $('#expand').addClass('hidden'); $('#re-content').removeClass('hidden'); $('#shrink').removeClass('hidden'); }); $('#expand').bind('boxready', function(){ setLoading(true); // $.post(basePath + 'common/form/relativeSearchMobile.action', { // caller: caller // }, function(result){ // setLoading(false); // if(result.exceptionInfo) { // dialog.show('错误', '数据加载错误,请重试', 1, function(){dialog.hide();}) // } else { // $('#relative .title .text').css('width', (138+result.data[0].form.title.length*18)+'px'); // $('#relative .title .text').append('-'+result.data[0].form.title); // var html = ''; // html += '