process.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. function getUrlParam(name){
  2. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  3. var r = window.location.search.substr(1).match(reg);
  4. if (r != null)
  5. return decodeURI(r[2]);
  6. return null;
  7. }
  8. function parseDate(date){
  9. var y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(),
  10. h = date.getHours(), i = date.getMinutes();
  11. var now = new Date(), _y = now.getFullYear(), _m = now.getMonth() + 1, _d = now.getDate();
  12. if(_y != y) {
  13. return y + '-' + m + '-' + d + ' ' + h + ':' + i;
  14. } else {
  15. if(_m != m) {
  16. return m + '月' + d + '号' + h + '点' + i + '分';
  17. } else {
  18. if(_d != d) {
  19. return d + '号' + h + '点' + i + '分';
  20. } else {
  21. return (h < 12 ? '上午' : '下午' ) + h + '点' + i + '分';
  22. }
  23. }
  24. }
  25. }
  26. /*
  27. * 锁定表头和列
  28. *
  29. * 参数定义
  30. * table - 要锁定的表格元素或者表格ID
  31. * freezeRowNum - 要锁定的前几行行数,如果行不锁定,则设置为0
  32. * freezeColumnNum - 要锁定的前几列列数,如果列不锁定,则设置为0
  33. * width - 表格的滚动区域宽度
  34. */
  35. function freezeTable(table, freezeRowNum, freezeColumnNum, width) {
  36. if (typeof(freezeRowNum) == 'string')
  37. freezeRowNum = parseInt(freezeRowNum);
  38. if (typeof(freezeColumnNum) == 'string')
  39. freezeColumnNum = parseInt(freezeColumnNum);
  40. var tableId;
  41. if (typeof(table) == 'string') {
  42. tableId = table;
  43. table = $('#' + tableId);
  44. } else
  45. tableId = table.attr('id');
  46. if(table.width() <= width) return;
  47. height = table.height() + 10;
  48. var divTableLayout = $("#" + tableId + "_tableLayout");
  49. if (divTableLayout.length != 0) {
  50. divTableLayout.before(table);
  51. divTableLayout.empty();
  52. } else {
  53. table.after("<div id='" + tableId + "_tableLayout' style='overflow:hidden;height:" + height + "px; width:" + width + "px;'></div>");
  54. divTableLayout = $("#" + tableId + "_tableLayout");
  55. }
  56. var html = '';
  57. if (freezeRowNum > 0 && freezeColumnNum > 0)
  58. html += '<div id="' + tableId + '_tableFix" style="padding: 0px;"></div>';
  59. if (freezeRowNum > 0)
  60. html += '<div id="' + tableId + '_tableHead" style="padding: 0px;"></div>';
  61. if (freezeColumnNum > 0)
  62. html += '<div id="' + tableId + '_tableColumn" style="padding: 0px;"></div>';
  63. html += '<div id="' + tableId + '_tableData" style="padding: 0px;"></div>';
  64. $(html).appendTo("#" + tableId + "_tableLayout");
  65. var divTableFix = freezeRowNum > 0 && freezeColumnNum > 0 ? $("#" + tableId + "_tableFix") : null;
  66. var divTableHead = freezeRowNum > 0 ? $("#" + tableId + "_tableHead") : null;
  67. var divTableColumn = freezeColumnNum > 0 ? $("#" + tableId + "_tableColumn") : null;
  68. var divTableData = $("#" + tableId + "_tableData");
  69. divTableData.append(table);
  70. if (divTableFix != null) {
  71. var tableFixClone = table.clone(true);
  72. tableFixClone.attr("id", tableId + "_tableFixClone");
  73. divTableFix.append(tableFixClone);
  74. }
  75. if (divTableHead != null) {
  76. var tableHeadClone = table.clone(true);
  77. tableHeadClone.attr("id", tableId + "_tableHeadClone");
  78. divTableHead.append(tableHeadClone);
  79. }
  80. if (divTableColumn != null) {
  81. var tableColumnClone = table.clone(true);
  82. tableColumnClone.attr("id", tableId + "_tableColumnClone");
  83. divTableColumn.append(tableColumnClone);
  84. }
  85. $("#" + tableId + "_tableLayout table").css("margin", "0");
  86. if (freezeRowNum > 0) {
  87. var HeadHeight = 0;
  88. var ignoreRowNum = 0;
  89. $("#" + tableId + "_tableHead tr:lt(" + freezeRowNum + ")").each(function () {
  90. if (ignoreRowNum > 0)
  91. ignoreRowNum--;
  92. else {
  93. var td = $(this).find('td:first, th:first');
  94. HeadHeight += td.outerHeight(true);
  95. ignoreRowNum = td.attr('rowSpan');
  96. if (typeof(ignoreRowNum) == 'undefined')
  97. ignoreRowNum = 0;
  98. else
  99. ignoreRowNum = parseInt(ignoreRowNum) - 1;
  100. }
  101. });
  102. HeadHeight += 2;
  103. divTableHead.css("height", HeadHeight);
  104. divTableFix != null && divTableFix.css("height", HeadHeight);
  105. }
  106. if (freezeColumnNum > 0) {
  107. var ColumnsWidth = 0;
  108. var ColumnsNumber = 0;
  109. $("#" + tableId + "_tableColumn tr:eq(" + freezeRowNum + ")").find("td:lt(" + freezeColumnNum + "), th:lt(" + freezeColumnNum + ")").each(function () {
  110. if (ColumnsNumber >= freezeColumnNum)
  111. return;
  112. ColumnsWidth += $(this).outerWidth(true);
  113. ColumnsNumber += $(this).attr('colSpan') ? parseInt($(this).attr('colSpan')) : 1;
  114. });
  115. ColumnsWidth += 2;
  116. divTableColumn.css("width", ColumnsWidth);
  117. divTableFix != null && divTableFix.css("width", ColumnsWidth);
  118. }
  119. divTableData.scroll(function () {
  120. divTableHead != null && divTableHead.scrollLeft(divTableData.scrollLeft());
  121. divTableColumn != null && divTableColumn.scrollTop(divTableData.scrollTop());
  122. });
  123. divTableFix != null && divTableFix.css({ "overflow": "hidden", "position": "absolute", "z-index": "50" });
  124. divTableHead != null && divTableHead.css({ "overflow": "hidden", "width": width, "position": "absolute", "z-index": "45" });// - 17
  125. divTableColumn != null && divTableColumn.css({ "overflow": "hidden", "height": height, "position": "absolute", "z-index": "40" });// - 17
  126. divTableData.css({ "overflow": "scroll", "width": width, "height": height, "position": "absolute" });
  127. divTableFix != null && divTableFix.offset(divTableLayout.offset());
  128. divTableHead != null && divTableHead.offset(divTableLayout.offset());
  129. divTableColumn != null && divTableColumn.offset(divTableLayout.offset());
  130. divTableData.offset(divTableLayout.offset());
  131. }
  132. /*
  133. * 调整锁定表的宽度和高度,这个函数在resize事件中调用
  134. *
  135. * 参数定义
  136. * table - 要锁定的表格元素或者表格ID
  137. * width - 表格的滚动区域宽度
  138. */
  139. function adjustTableSize(table, width) {
  140. var tableId;
  141. if (typeof(table) == 'string')
  142. tableId = table;
  143. else
  144. tableId = table.attr('id');
  145. height = $("#" + tableId).height() + 10;
  146. $("#" + tableId + "_tableLayout").width(width).height(height);
  147. $("#" + tableId + "_tableHead").width(width);// - 17
  148. $("#" + tableId + "_tableColumn").height(height);// - 17
  149. $("#" + tableId + "_tableData").width(width).height(height);
  150. }
  151. //返回当前页面宽度
  152. function pageWidth() {
  153. if ($.browser.msie) {
  154. return document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth;
  155. } else {
  156. // - padding
  157. return self.innerWidth - 30;
  158. }
  159. };
  160. // close page
  161. function closePage() {
  162. top.window.opener = top;
  163. top.window.open('','_self','');
  164. top.window.close();
  165. }
  166. $(document).ready(function() {
  167. //init custom event(trigger when tabpane active for the first time)
  168. $.event.special.boxready = {
  169. /**
  170. * 初始化事件处理器 - this指向元素
  171. * @param 附加的数据
  172. * @param 事件类型命名空间
  173. * @param 回调函数
  174. */
  175. setup: function(data, namespaces, eventHandle) {
  176. var elem = this;
  177. $.event.add(elem, 'click', function (event) {
  178. if ($.data(elem, '@loaded') !== true) {
  179. $.event.trigger('boxready', null, elem);
  180. $.data(elem, '@loaded', true);
  181. }
  182. });
  183. },
  184. /**
  185. * 卸载事件处理器 - this指向元素
  186. * @param 事件类型命名空间
  187. */
  188. teardown: function(namespaces) {
  189. var elem = this;
  190. $.event.remove(elem, 'click');
  191. $.removeData(elem, '@loaded');
  192. }
  193. };
  194. var cls = 'active', instance = null, current = null, readyTime = new Date();
  195. // toggle tabs
  196. $('.nav-tabs>li>a').click(function(){
  197. if(!$(this).hasClass(cls)) {
  198. var nav = $(this).parent().parent(), bd = nav.next(),
  199. old = nav.children('.' + cls).index(),
  200. index = $(this).parent().index();
  201. $('.tab-pane:eq(' + old + ')', bd).removeClass(cls);
  202. $('.tab-pane:eq(' + index + ')', bd).addClass(cls);
  203. nav.children('.' + cls).removeClass(cls);
  204. $(this).parent().addClass(cls);
  205. }
  206. });
  207. // modal dialog
  208. var dialog = {
  209. show: function(title, content, timeout, callback){
  210. var back = $('.modal-backdrop'), modal = $('.modal'),
  211. tt = $('.modal-title', modal), tb = $('.modal-body', modal);
  212. back.css('display', 'block');
  213. modal.css('display', 'block');
  214. tt.text(title);
  215. if(timeout && timeout > 0) {
  216. content = '<div><strong class="text-success text-xl" id="timeout">' + timeout + '</strong>&nbsp;秒后,' + content + '</div>';
  217. }
  218. tb.html(content);
  219. if(timeout) {
  220. var pre = 1000;
  221. if(timeout <=0 ) {// auto close
  222. pre = 1500;
  223. if(!callback)
  224. callback = dialog.hide;
  225. }
  226. var timer = function(t) {
  227. setTimeout(function(){
  228. if(t > -1) {
  229. $('#timeout').text(t--);
  230. timer(t);
  231. } else {
  232. callback && callback.call();
  233. }
  234. }, pre);
  235. };
  236. timer(timeout);
  237. }
  238. },
  239. hide: function() {
  240. var back = $('.modal-backdrop'), modal = $('.modal');
  241. back.css('display', 'none');
  242. modal.css('display', 'none');
  243. }
  244. };
  245. // loading
  246. var setLoading = function(isLoading) {
  247. $('.loading-container').css('display', isLoading ? 'block' : 'none');
  248. };
  249. // get instance
  250. var getInstance = function(id, callback) {
  251. $.post(basePath + 'common/getProcessInstanceId.action', {
  252. jp_nodeId: id,
  253. _noc: 1
  254. }, function(result, text) {
  255. var e = result.exceptionInfo;
  256. if(e) {
  257. if(e == 'ERR_NETWORK_SESSIONOUT') {
  258. dialog.show('错误', '请先登录!');
  259. } else {
  260. dialog.show('出现异常', '请稍后再试...');
  261. }
  262. } else {
  263. instance = result.processInstanceId;
  264. callback && callback.call(null, instance);
  265. }
  266. });
  267. };
  268. // get process
  269. var getProcess = function(id) {
  270. setLoading(true);
  271. $.post(basePath + 'common/getCurrentNode.action', {
  272. jp_nodeId: id,
  273. _noc: 1
  274. }, function(result, text) {
  275. setLoading(false);
  276. var e = result.exceptionInfo;
  277. if(e) {
  278. if(e == 'ERR_NETWORK_SESSIONOUT') {
  279. dialog.show('错误', '请先登录!');
  280. } else {
  281. dialog.show('出现异常', '请稍后再试...');
  282. }
  283. } else {
  284. instance = result.info.InstanceId;
  285. parseNode(result.info.currentnode);
  286. // result.info.button 额外的按钮,以供修改单据(例如客户拜访),在这里不考虑
  287. }
  288. });
  289. };
  290. // get main point
  291. var getMainPoint = function(id) {
  292. $.post(basePath + 'common/getCustomSetupOfTask.action', {
  293. nodeId: id,
  294. _noc: 1
  295. }, function(result, text) {
  296. if(result.cs) {
  297. var points = [], data = result.data ? result.data.split(';') : [];
  298. $.each(result.cs, function(i, c){
  299. var m = c.indexOf('^'), n = c.indexOf('$'), q = c.indexOf('@');
  300. points.push({
  301. type: c.substring(m + 1, n),
  302. text: c.substring(0, m),
  303. required: c.substr(n + 1, 1) === 'Y',
  304. value: data[i] ? data[i].substring(data[i].lastIndexOf("(") + 1, data[i].lastIndexOf(")")) : null,
  305. logic: q > 0 ? c.substring(q + 1) : null
  306. });
  307. });
  308. if(points.length > 0)
  309. parseMainPoint(points);
  310. }
  311. });
  312. };
  313. // get history
  314. var getHistory = function(instanceId, callback) {
  315. setLoading(true);
  316. $.post(basePath + 'common/getAllHistoryNodes.action', {
  317. processInstanceId: instanceId,
  318. _noc: 1
  319. }, function(result, text) {
  320. setLoading(false);
  321. var e = result.exceptionInfo;
  322. if(e) {
  323. if(e == 'ERR_NETWORK_SESSIONOUT') {
  324. dialog.show('错误', '请先登录!');
  325. } else {
  326. dialog.show('出现异常', '请稍后再试...');
  327. }
  328. } else {
  329. if(callback)
  330. callback.call(null, result.nodes);
  331. if(result.nodes && result.nodes.length > 0) {
  332. parseHistory(result.nodes);
  333. }
  334. }
  335. });
  336. };
  337. // get bill main
  338. var getBillMain = function(caller, url, cond, billId) {
  339. $.post(basePath + 'common/rsForm.action', {
  340. caller: caller,
  341. condition: cond,
  342. url: url,
  343. _noc: 1
  344. }, function(result, text) {
  345. var e = result.exceptionInfo;
  346. if(e) {
  347. if(e == 'ERR_NETWORK_SESSIONOUT') {
  348. dialog.show('错误', '请先登录!');
  349. } else {
  350. dialog.show('出现异常', '请稍后再试...');
  351. }
  352. } else {
  353. if(result.data) {
  354. parseBillMain(result);
  355. if(caller == 'VisitRecord' || caller == 'VisitRecord!Vender') {
  356. initVisitRecord(result, billId);
  357. }
  358. }
  359. }
  360. });
  361. };
  362. //init extra element when VisitRecord
  363. var initVisitRecord = function(main, billId) {
  364. $('#ex').css('display', 'block');
  365. var data = main.data['评价'], title = data ? (data['评分'] || '良') : '良',
  366. msg = data ? data['评语'] : '';
  367. if(title) {
  368. $('#ex-rating button[title="' + title + '"]').addClass('active');
  369. }
  370. $('#ex-msg').val(msg);
  371. $('#ex-rating button').click(function(){
  372. $('#ex-rating button').each(function(){
  373. $(this).removeClass('active');
  374. });
  375. $(this).addClass('active');
  376. });
  377. $('#ex-confirm').click(function(){
  378. msg = $('#ex-msg').val() || '-';
  379. title = '';
  380. $('#ex-rating button').each(function(){
  381. if($(this).hasClass('active'))
  382. title = $(this).attr('title');
  383. });
  384. setLoading(true);
  385. $.post(basePath + 'crm/customermgr/updateVisitRecordPingjia.action', {
  386. id: billId,
  387. vr_newtitle: title,
  388. vr_purpose: msg,
  389. _noc: 1
  390. }, function(result, text) {
  391. setLoading(false);
  392. var e = result.exceptionInfo;
  393. if(e) {
  394. if(e == 'ERR_NETWORK_SESSIONOUT') {
  395. dialog.show('错误', '请先登录!');
  396. } else {
  397. dialog.show('出现异常', '请稍后再试...');
  398. }
  399. } else {
  400. dialog.show('提示', '评价成功', -1);
  401. }
  402. });
  403. });
  404. };
  405. // get bill detail
  406. var getBillDetail = function(caller, url, cond){
  407. setLoading(true);
  408. $.post(basePath + 'common/rsGrid.action', {
  409. caller: caller,
  410. condition: cond,
  411. url: url,
  412. start: 0,
  413. end: 100,
  414. _noc: 1
  415. }, function(result, text) {
  416. setLoading(false);
  417. var e = result.exceptionInfo;
  418. if(e) {
  419. if(e == 'ERR_NETWORK_SESSIONOUT') {
  420. dialog.show('错误', '请先登录!');
  421. } else {
  422. dialog.show('出现异常', '请稍后再试...');
  423. }
  424. } else {
  425. if(result.data)
  426. parseBillDetail(result.data, $('#bill-detail'));
  427. }
  428. });
  429. };
  430. // parse current node
  431. var parseNode = function(node) {
  432. current = node;
  433. $('#jp_name').text(node.jp_name);
  434. $('#jp_name').css('margin-left', "-" + node.jp_name.replace(/[^\x00-\xff]/g, 'xx').length * 7 + "px");
  435. $('#jp_nodeName').text(node.jp_nodeName);
  436. $('#jp_launcherName').text(node.jp_launcherName);
  437. $('#jp_launchTime').text(parseDate(new Date(node.jp_launchTime)));
  438. $('#jp_codevalue').text(node.jp_codevalue);
  439. // get bill main data
  440. if(node.jp_keyName && node.jp_keyValue) {
  441. getBillMain(node.jp_caller, node.jp_url, node.jp_keyName + '=\'' + node.jp_keyValue + '\'', node.jp_keyValue);
  442. }
  443. // has detail
  444. if(node.jp_formDetailKey) {
  445. $('#detail-header').bind('boxready', function(){
  446. getBillDetail(node.jp_caller, node.jp_url, node.jp_formDetailKey + '=\'' + node.jp_keyValue + '\'');
  447. });
  448. } else {
  449. $('#detail-header').css('display', 'none');
  450. }
  451. // main point
  452. getMainPoint(node.jp_nodeId);
  453. // deal relative
  454. if(true){
  455. dealRelative(node.jp_caller);
  456. }
  457. };
  458. // parse main point
  459. var parseMainPoint = function(points) {
  460. var html = '<ul class="list-group">';
  461. html += '<li class="list-group-item disabled"><strong>问题要点</strong></li>';
  462. $.each(points, function(i, p){
  463. html += '<li class="list-group-item">';
  464. html += '<span>' + p.text + '</span>';
  465. if(p.type === 'B') {
  466. html += '<div class="pull-right"><div class="has-switch switch-small"><div class="' + (p.value && p.value != '是' ? 'switch-off' : 'switch-on') + ' switch-animate"><input type="checkbox" ' + (p.value && p.value != '是' ? '' : 'checked') + ' title="' + p.text + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') + '> <span class="switch-left switch-success switch-small">是</span> <label class="switch-small">&nbsp;</label> <span class="switch-right switch-warning switch-small">否</span></div></div></div>';
  467. } else if(p.type === 'S' || p.type === 'N') {
  468. html += '<div class="pull-right"><input class="form-control input-xs" type="text" placeholder="..." value="' + (p.value || '') + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') + ' title="' + p.text + '" ' + (p.required ? 'required' : '') + '></div>';
  469. } else if(p.type === 'D') {
  470. html += '<div class="pull-right"><input class="form-control input-xs" type="date" placeholder="..." value="' + (p.value || '') + '" ' + (p.logic ? 'logic="' + p.logic + '"' : '') + ' title="' + p.text + '" ' + (p.required ? 'required' : '') + '></div>';
  471. }
  472. html += '</li>';
  473. });
  474. html += '</ul>';
  475. $('#points').html(html);
  476. // toggle switch
  477. $('#points .has-switch').click(function(){
  478. var e = $(this), box = e.find('input'), checked = box.is(':checked');
  479. if(checked)
  480. box.removeAttr('checked');
  481. else
  482. box.attr('checked','checked');
  483. e.find('>div').removeClass(checked ? 'switch-on' : 'switch-off');
  484. e.find('>div').addClass(checked ? 'switch-off' : 'switch-on');
  485. });
  486. };
  487. // parse bill main
  488. var parseBillMain = function(main) {
  489. var bill = main.data, html = '<table class="table table-condensed table-bordered table-striped">', g = null;
  490. if(main.group) {
  491. for(k in bill) {
  492. g = bill[k];
  493. html += '<tr><td colspan="2" class="text-center text-success"><strong>' + k + '</strong>&nbsp;<span class="glyphicon glyphicon-chevron-down"></span></td></tr>';
  494. for(b in g) {
  495. html += '<tr>';
  496. html += '<td class="text-right special"><strong>' + b + '</strong></td>';
  497. html += '<td class="text-center">' + g[b] + '</td>';
  498. html += '</tr>';
  499. };
  500. }
  501. } else {
  502. for(b in bill) {
  503. html += '<tr>';
  504. html += '<td class="text-right special"><strong>' + b + '</strong></td>';
  505. html += '<td class="text-center">' + bill[b] + '</td>';
  506. html += '</tr>';
  507. };
  508. }
  509. html += '</table>';
  510. $('#bill-main').html(html);
  511. };
  512. // parse bill detail
  513. var parseBillDetail = function(detail, content){
  514. var html = '<table id="bill-detail-table" class="table table-condensed table-bordered table-striped">';
  515. for(c in detail) {
  516. html += '<tr>';
  517. html += '<td class="text-right special"><strong>' + c + '</strong></td>';
  518. if(detail[c] && detail[c].length > 0) {
  519. $.each(detail[c], function(i, p){
  520. html += '<td class="text-center">' + p + '</td>';
  521. });
  522. } else {
  523. html += '<td class="text-center text-muted">(无)</td>';
  524. }
  525. html += '</tr>';
  526. }
  527. html += '</table>';
  528. content.html(html);
  529. var table = $('table', content);
  530. freezeTable(table, 0, 1, pageWidth());
  531. var flag = false;
  532. $(window).resize(function() {
  533. if (flag)
  534. return ;
  535. setTimeout(function() {
  536. adjustTableSize(table.attr('id'), pageWidth());
  537. flag = false;
  538. }, 100);
  539. flag = true;
  540. });
  541. };
  542. // parse history
  543. var parseHistory = function(hist) {
  544. var html = '<ul class="list-unstyled list-inline">';
  545. $.each(hist, function(i, h){
  546. var res = h.jn_dealResult == '同意' ? 'success' : (h.jn_dealResult == '不同意' ? 'error' : 'warning');
  547. html += '<li>';
  548. html += '<div class="text-top">';
  549. html += '<span>' + h.jn_name + '</span>';
  550. html += '</div>';
  551. html += '<blockquote>';
  552. html += '<strong>' + h.jn_dealManName + '</strong>';
  553. html += '<div class="text-trans ' + res + '">';
  554. html += '<span>' + h.jn_dealResult + '</span>';
  555. html += '</div>';
  556. html += '<footer>' + h.jn_dealTime + '</footer>';
  557. html += '</blockquote>';
  558. if(h.jn_operatedDescription || h.jn_nodeDescription || h.jn_infoReceiver) {
  559. html += '<div class="highlight">';
  560. if(h.jn_nodeDescription)
  561. html += '<div>' + h.jn_nodeDescription + '</div>';
  562. if(h.jn_infoReceiver)
  563. html += '<p class="text-muted"><i>' + h.jn_infoReceiver + '</i></p>';
  564. if(h.jn_operatedDescription) {
  565. if(h.jn_operatedDescription.indexOf('(是)') > 0 ||
  566. h.jn_operatedDescription.indexOf('(否)') > 0) {
  567. html += '<ul class="list-group">';
  568. var descs = h.jn_operatedDescription.split(';');
  569. $.each(descs, function(j, d){
  570. res = d.substr(d.length - 3) == '(是)' ? 'glyphicon glyphicon-ok text-success' :
  571. 'glyphicon glyphicon-remove text-warning';
  572. html += '<li class="list-group-item"><span class="pull-right ' + res + '"></span>' + d.substr(0, d.length-3) + '</li>';
  573. });
  574. html += '</ul>';
  575. } else {
  576. html += '<div>' + h.jn_operatedDescription + '</div>';
  577. }
  578. }
  579. html += '</div>';
  580. }
  581. html += '</li>';
  582. });
  583. html += '</ul>';
  584. $('#history').html(html);
  585. };
  586. // get process by node id
  587. var nodeId = getUrlParam('nodeId');
  588. if (nodeId) {
  589. getProcess(nodeId);
  590. // get history by instance id
  591. $('#history-header').bind('boxready', function(){
  592. if(instance) {
  593. getHistory(instance);
  594. } else {
  595. getInstance(nodeId, function(instanceId){
  596. getHistory(instanceId);
  597. });
  598. }
  599. });
  600. }
  601. // get radio,checkbox value
  602. var getBoxValue = function(selector) {
  603. var value = null;
  604. $(selector).each(function(){
  605. var t = $(this);
  606. if(t.is(":checked")) {
  607. value = t.val();
  608. }
  609. });
  610. return value;
  611. };
  612. // node next step
  613. var nextStep = function(callback) {
  614. $.post(basePath + 'common/dealNextStepOfPInstance.action', {
  615. processInstanceId: instance,
  616. _noc: 1
  617. }, function(result, text) {
  618. if(result.hasNext) {
  619. var len = result.actorUsers.length;
  620. if (len > 0) {
  621. var html = '<p>';
  622. html += "流程下一步有<strong>" + len + "</strong>个可选审批人,请指定其中一位:";
  623. html += '</p>';
  624. html += '<form>';
  625. html += '<div class="form-group" style="max-height:200px;overflow-y:auto;">';
  626. $.each(result.actorUsers, function(i, u){
  627. html += '<label class="radio-inline" style="margin-bottom:10px;margin-right:20px;">';
  628. html += '<input type="radio" name="user" value="' + u + '"' +
  629. (i == 0 ? ' checked="checked"' : '') + ' style="position:static;"> ' + u;
  630. html += '</label>';
  631. });
  632. html += '</div>';
  633. html += '<div class="btn-group btn-group-xs btn-group-justified">';
  634. html += '<div class="btn-group"><button type="button" class="btn btn-primary" id="confirm">指定</button></div>';
  635. html += '<div class="btn-group"><button type="button" class="btn btn-default" id="cancel">暂不指定</button></div>';
  636. html += '</div>';
  637. html += '</form>';
  638. dialog.show('下一步', html);
  639. // choose one to handle next node
  640. $('#confirm').click(function(){
  641. appointNext(result.nodeId, getBoxValue('form input[type="radio"]'), callback);
  642. });
  643. // notice evenyone to receive next node
  644. $('#cancel').click(function(){
  645. noticeNext(result.nodeId, result.actorUsers, callback);
  646. });
  647. } else {
  648. callback && callback.call();
  649. }
  650. }
  651. });
  652. };
  653. // appoint one to deal next
  654. var appointNext = function(nodeId, user, callback) {
  655. $.post(basePath + 'common/takeOverTask.action', {
  656. em_code: user.substring(user.lastIndexOf('(') + 1, user.length - 1),
  657. nodeId: nodeId,
  658. _noc: 1
  659. }, function(result, text) {
  660. if(result.success)
  661. callback && callback.call();
  662. else
  663. dialog.show('错误', '指派失败,请稍后再试!');
  664. });
  665. };
  666. // notice next users
  667. var noticeNext = function(nodeId, users, callback) {
  668. $.post(basePath + 'common/processpaging.action', {
  669. persons: unescape(users.join(',')),
  670. nodeId: nodeId,
  671. _noc: 1
  672. }, function(result, text) {
  673. if(result.success)
  674. callback && callback.call();
  675. });
  676. };
  677. // load next process
  678. var processNext = function(id) {
  679. if(id != '-1') {
  680. var url = window.location.href;
  681. window.location.href = url.substr(0, url.indexOf('?') + 1) + 'nodeId=' + id;
  682. } else {
  683. dialog.show('提示', '暂时没有新的审批任务了!');
  684. }
  685. };
  686. // is valid
  687. var isValid = function() {
  688. var deals = $('#points input');
  689. if(deals.length > 0) {
  690. $.each(deals, function(i, d){
  691. var e = $(d), type = e.attr('type'), val = e.val();
  692. if((type === 'text' || type === 'date') && !val)
  693. return false;
  694. });
  695. }
  696. return true;
  697. };
  698. // get your points
  699. var getDealPoints = function() {
  700. var deals = $('#points input');
  701. if(deals.length > 0) {
  702. var points = [];
  703. $.each(deals, function(i, d){
  704. var e = $(d), text = e.attr('title'), type = e.attr('type'), val = e.val(),
  705. lg = e.attr('logic');
  706. val = type == 'checkbox' ? (e.is(':checked') ? '是' : '否') : val;
  707. points.push(text + '(' + val + ')' + (lg ? '@' + lg + '@' : ''));
  708. });
  709. return points.join(';');
  710. }
  711. return null;
  712. };
  713. // agree
  714. var agree = function() {
  715. if(!isValid()) {
  716. dialog.show(' 警告', '您还有审批要点问题没处理!', -1);
  717. return;
  718. }
  719. setLoading(true);
  720. $.post(basePath + 'common/review.action', {
  721. taskId: nodeId,
  722. nodeName: current.jp_nodeName,
  723. nodeLog: $('#deal-msg').val(),
  724. holdtime: ((new Date() - readyTime) / 1000).toFixed(0),
  725. customDes: getDealPoints(),
  726. result: true,
  727. _noc: 1
  728. }, function(result, text) {
  729. setLoading(false);
  730. if(result.success) {
  731. if (result.nextnode == '0') {
  732. dialog.show('审批成功', '您暂时没有其它的审批任务了。');
  733. } else {
  734. if(result.after) {
  735. if (result.after.trim().substr(0, 12) == 'AFTERSUCCESS') {
  736. dialog.show('审批出现提示:' + result.after.replace('AFTERSUCCESS', ''),
  737. '自动为您跳转到下一条...', 5, function(){
  738. nextStep(function(){
  739. processNext(result.nextnode);
  740. });
  741. });
  742. } else {
  743. dialog.show('审批出现异常', result.after);
  744. }
  745. } else {
  746. dialog.show('审批成功', '自动为您跳转到下一条...', 1, function(){
  747. nextStep(function(){
  748. processNext(result.nextnode);
  749. });
  750. });
  751. }
  752. }
  753. } else if (result.exceptionInfo){
  754. dialog.show('无法审批', result.exceptionInfo);
  755. } else {
  756. dialog.show('处理结果', "该任务已处理,不能重复操作!");
  757. }
  758. });
  759. };
  760. $('#agree').click(function(){
  761. agree();
  762. });
  763. // disagree -> return back
  764. var disagree = function(backNode, msg){
  765. setLoading(true);
  766. $.post(basePath + 'common/review.action', {
  767. taskId: nodeId,
  768. nodeName: current.jp_nodeName,
  769. backTaskName: backNode,
  770. nodeLog: msg,
  771. holdtime: ((new Date() - readyTime) / 1000).toFixed(0),
  772. result: false,
  773. _noc: 1
  774. }, function(result, text) {
  775. setLoading(false);
  776. if(result.success) {
  777. if(result.after) {
  778. dialog.show('回退过程出现提示:' + result.after);
  779. } else {
  780. dialog.show('回退成功', '自动为您跳转到下一条...', 1, function(){
  781. nextStep(function(){
  782. processNext(result.nextnode);
  783. });
  784. });
  785. }
  786. } else {
  787. dialog.show('处理结果', "该任务已处理,不能重复操作!");
  788. }
  789. });
  790. };
  791. $('#disagree').click(function(){
  792. getHistory(instance, function(nodes){
  793. var html = '<form>';
  794. html += '<div class="form-group">';
  795. html += '<label class="radio-inline">';
  796. html += '<input type="radio" name="node" value="RECORDER" checked="checked"> 制单人';
  797. html += '</label>';
  798. $.each(nodes, function(i, n){
  799. html += '<label class="radio-inline">';
  800. html += '<input type="radio" name="node" value="' + n.jn_name + '"> ' + n.jn_name;
  801. html += '</label>';
  802. });
  803. html += '</div>';
  804. html += '<div class="form-group"><textarea id="back-msg" rows="2" placeholder="填写您不同意的原因..." class="form-control">' + $('#deal-msg').val() + '</textarea><span class="help-block text-lg text-error" id="back_err"></span></div>';
  805. html += '<div class="btn-group btn-group-xs btn-group-justified">';
  806. html += '<div class="btn-group"><button type="button" class="btn btn-primary" id="back">回退</button></div>';
  807. html += '<div class="btn-group"><button type="button" class="btn btn-default" id="cancel2">取消</button></div>';
  808. html += '</div>';
  809. html += '</form>';
  810. dialog.show('回退到节点', html);
  811. // choose one to back
  812. $('#back').click(function(){
  813. var msg = $('#back-msg').val();
  814. if (!msg) {
  815. $('#back_err').text('请填写您不同意的原因!');
  816. $('#back-msg').focus();
  817. } else {
  818. disagree(getBoxValue('form input[type="radio"]'), msg);
  819. }
  820. });
  821. // cancel
  822. $('#cancel2').click(function(){
  823. dialog.hide();
  824. });
  825. });
  826. });
  827. // end
  828. var end = function(){
  829. setLoading(true);
  830. $.post(basePath + 'common/endProcessInstance.action', {
  831. processInstanceId: instance,
  832. holdtime: ((new Date() - readyTime) / 1000).toFixed(0),
  833. nodeId: nodeId,
  834. _noc: 1
  835. }, function(result, text) {
  836. setLoading(false);
  837. if(result.success) {
  838. dialog.show('流程已结束', '自动为您跳转到下一条...', 1, function(){
  839. nextStep(function(){
  840. processNext(result.nextnode);
  841. });
  842. });
  843. } else {
  844. dialog.show('警告', "流程实例不存在!");
  845. }
  846. });
  847. };
  848. $('#end').click(function(){
  849. end();
  850. });
  851. // change
  852. var change = function(user, msg){
  853. if(!user) {
  854. $('#change_err').text('您还没选择变更人!');
  855. return;
  856. }
  857. if(!isValid()) {
  858. $('#change_err').text('您还有审批要点问题没处理!');
  859. return;
  860. }
  861. setLoading(true);
  862. $.post(basePath + 'common/setAssignee.action', {
  863. taskId: nodeId,
  864. assigneeId: user,
  865. processInstanceId: instance,
  866. customDes: getDealPoints(),
  867. description: msg,
  868. _noc: 1
  869. }, function(result, text) {
  870. setLoading(false);
  871. if(result.result) {
  872. dialog.show('处理结果', '节点已成功变更');
  873. } else {
  874. dialog.show('处理结果', "任务不存在,无法变更!");
  875. }
  876. });
  877. };
  878. $('#change').click(function(){
  879. var html = '<form>';
  880. html += '<div class="form-group has-feedback dropdown"><input id="em_new" name="em_new" class="form-control dropdown-toggle" type="text" placeholder="新的处理人,点击搜索"/><span id="change_search_icon" class="glyphicon glyphicon-search form-control-feedback"></span><div class="dropdown-menu"><div id="em_search" class="list-group"></div></div>' +
  881. '<span class="help-block text-lg">' +
  882. '<span id="change_name"></span>' +
  883. '<span id="em_code"></span>' +
  884. '</span></div>';
  885. html += '<div class="form-group"><textarea id="change-msg" rows="2" placeholder="填写您要变更的原因..." class="form-control">' + $('#deal-msg').val() + '</textarea><span class="help-block text-lg text-error" id="change_err"></span></div>';
  886. html += '<div class="btn-group btn-group-xs btn-group-justified">';
  887. html += '<div class="btn-group"><button type="button" class="btn btn-primary" id="change3">变更</button></div>';
  888. html += '<div class="btn-group"><button type="button" class="btn btn-default" id="cancel3">取消</button></div>';
  889. html += '</div>';
  890. html += '</form>';
  891. dialog.show('变更办理人', html);
  892. // search deal man
  893. $('#em_new').bind('focus', function(){
  894. if($(this).val()) {
  895. $(this).parent().children('.dropdown-menu').css('display', 'block');
  896. }
  897. });
  898. $('#em_new').bind('change', function(){// 点击获取变更的候选人
  899. var v = $(this).val();
  900. var view = $(this).parent().children('.dropdown-menu');
  901. if(v) {
  902. view.css('display', 'block');
  903. getSearchResult(v);
  904. } else {
  905. view.css('display', 'none');
  906. }
  907. });
  908. $('#em_new').bind('keyup', function(event){// 回车获取变更的候选人
  909. if(event.keyCode == 13) {
  910. event.preventDefault();
  911. var v = $(this).val();
  912. var view = $(this).parent().children('.dropdown-menu');
  913. if(v) {
  914. view.css('display', 'block');
  915. getSearchResult(v);
  916. } else {
  917. view.css('display', 'none');
  918. }
  919. }
  920. });
  921. $('#change_search_icon').bind('click', function(event){// 变更查询放大镜图标点击获取变更的候选人
  922. var v = $('#em_new').val();
  923. var view = $('#em_new').parent().parent().children('.dropdown-menu');
  924. if(v) {
  925. view.css('display', 'block');
  926. getSearchResult(v);
  927. } else {
  928. view.css('display', 'none');
  929. }
  930. });
  931. // change
  932. $('#change3').click(function(){
  933. var msg = $('#change-msg').val();
  934. change($('#em_code').text(), msg);
  935. });
  936. // cancel
  937. $('#cancel3').click(function(){
  938. dialog.hide();
  939. });
  940. });
  941. // get search result
  942. var getSearchResult = function(input) {
  943. setLoading(true);
  944. $.post(basePath + 'hr/emplmana/search.action', {
  945. keyword: input
  946. }, function(result, text){
  947. setLoading(false);
  948. if(result.length > 0) {
  949. parseSearchResult(result);
  950. }
  951. });
  952. };
  953. // parse search result
  954. var parseSearchResult = function(datas){
  955. var html = '';
  956. $.each(datas, function(i, d){
  957. var e = d.split('\n');
  958. html += '<a href="javascript:onItemClick(\'' + e[1] + '\',\'' + e[2] + '\');" class="list-group-item">';
  959. html += '<span class="left">' + (e[0] || '(空)') + '</span>';
  960. html += '<span class="right">' + e[2] + '(' + e[1] + ')</span>';
  961. html += '</a>';
  962. });
  963. $('#em_search').html(html);
  964. };
  965. //关联查询
  966. var dealRelative = function(caller) {
  967. $('#expand').html('展开&nbsp;<span '+
  968. 'class="glyphicon glyphicon-share-alt"></span>');
  969. $('#expand').click(function(){
  970. $('#expand').addClass('hidden');
  971. $('#re-content').removeClass('hidden');
  972. $('#shrink').removeClass('hidden');
  973. });
  974. $('#expand').bind('boxready', function(){
  975. setLoading(true);
  976. $.post(basePath + 'common/form/relativeSearchMobile.action', {
  977. caller: caller
  978. }, function(result){
  979. setLoading(false);
  980. if(result.exceptionInfo) {
  981. dialog.show('错误', '数据加载错误,请重试', 1, function(){dialog.hide();})
  982. } else {
  983. $('#relative .title .text').css('width', (138+result.data[0].form.title.length*18)+'px');
  984. $('#relative .title .text').append('-'+result.data[0].form.title);
  985. var html = '';
  986. html += '<div class="control-group">'+
  987. '<label class="control-lable" for="'+result.data[0].form.items[0].name+'">'+
  988. result.data[0].form.items[0].fieldLabel+':</label>'+
  989. '<select type="text" id="'+result.data[0].form.items[0].name+'" name="'+
  990. result.data[0].form.items[0].name+'" class="form-control"></select>'+
  991. '<button id="re-search" type="button" class="btn btn-success">筛选</button>'+
  992. '</div>';
  993. $('#re-filtrate').html(html);
  994. }
  995. });
  996. });
  997. $('#shrink').click(function(){
  998. $('#expand').removeClass('hidden');
  999. $('#re-content').addClass('hidden');
  1000. $('#shrink').addClass('hidden');
  1001. });
  1002. };
  1003. // touch on mobile need jquery-mobile.js & event 'tap'
  1004. window.onItemClick = function(code, name) {
  1005. $('#em_search').parent().css('display', 'none');
  1006. $('#change_name').text(name + ' - ')
  1007. $('#em_code').text(code);
  1008. };
  1009. });