jprocand.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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. $.ajax({
  268. url:basePath + 'common/getProcessInstanceId.action',
  269. type: 'POST',
  270. data: {jp_nodeId: id, _noc: 1},
  271. success: function(result){
  272. instance = result.processInstanceId;
  273. callback && callback.call(null, instance);
  274. },
  275. error: function(xhr){
  276. if(xhr.responseJSON) {
  277. var response = xhr.responseJSON;
  278. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  279. dialog.show('获取信息失败', '请先登录!');
  280. } else {
  281. dialog.show('错误', response.exceptionInfo);
  282. }
  283. }
  284. }
  285. });
  286. };
  287. // get process
  288. var getProcess = function(id) {
  289. setLoading(true);
  290. // $.post(basePath + 'common/getCurrentNode.action', {
  291. // jp_nodeId: id,
  292. // _noc: 1
  293. // }, function(result, text) {
  294. // setLoading(false);
  295. // var e = result.exceptionInfo;
  296. // if(e) {
  297. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  298. // dialog.show('错误', '请先登录!');
  299. // } else {
  300. // dialog.show('出现异常', '请稍后再试...');
  301. // }
  302. // } else {
  303. // instance = result.info.InstanceId;
  304. // parseNode(result.info.currentnode);
  305. // // result.info.button 额外的按钮,以供修改单据(例如客户拜访),在这里不考虑
  306. // }
  307. // });
  308. $.ajax({
  309. url:basePath + 'common/getCurrentNode.action',
  310. type: 'POST',
  311. data: {jp_nodeId: id, _noc: 1},
  312. success: function(result){
  313. setLoading(false);
  314. instance = result.info.InstanceId;
  315. parseNode(result.info.currentnode);
  316. // // result.info.button 额外的按钮,以供修改单据(例如客户拜访),在这里不考虑
  317. },
  318. error: function(xhr){
  319. setLoading(false);
  320. if(xhr.responseJSON) {
  321. var response = xhr.responseJSON;
  322. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  323. dialog.show('获取用户信息失败', '请先登录!');
  324. } else {
  325. dialog.show('错误', response.exceptionInfo);
  326. }
  327. }
  328. }
  329. });
  330. };
  331. // get main point
  332. var getMainPoint = function(id) {
  333. $.post(basePath + 'common/getCustomSetupOfTask.action', {
  334. nodeId: id,
  335. _noc: 1
  336. }, function(result, text) {
  337. if(result.cs) {
  338. var points = [], data = result.data ? result.data.split(';') : [];
  339. $.each(result.cs, function(i, c){
  340. var m = c.indexOf('^'), n = c.indexOf('$'), q = c.indexOf('@');
  341. points.push({
  342. type: c.substring(m + 1, n),
  343. text: c.substring(0, m),
  344. required: c.substr(n + 1, 1) === 'Y',
  345. value: data[i] ? data[i].substring(data[i].lastIndexOf("(") + 1, data[i].lastIndexOf(")")) : null,
  346. logic: q > 0 ? c.substring(q + 1) : null
  347. });
  348. });
  349. if(points.length > 0)
  350. parseMainPoint(points);
  351. }
  352. });
  353. };
  354. // get history
  355. var getHistory = function(instanceId, callback) {
  356. setLoading(true);
  357. // $.post(basePath + 'common/getAllHistoryNodes.action', {
  358. // processInstanceId: instanceId,
  359. // _noc: 1
  360. // }, function(result, text) {
  361. // setLoading(false);
  362. // var e = result.exceptionInfo;
  363. // if(e) {
  364. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  365. // dialog.show('错误', '请先登录!');
  366. // } else {
  367. // dialog.show('出现异常', '请稍后再试...');
  368. // }
  369. // } else {
  370. // if(callback)
  371. // callback.call(null, result.nodes);
  372. // if(result.nodes && result.nodes.length > 0) {
  373. // parseHistory(result.nodes);
  374. // }
  375. // }
  376. // });
  377. $.ajax({
  378. url:basePath + 'common/getAllHistoryNodes.action',
  379. type: 'POST',
  380. data: {processInstanceId: instanceId, _noc: 1},
  381. success: function(result){
  382. setLoading(false);
  383. if(callback)
  384. callback.call(null, result.nodes);
  385. if(result.nodes && result.nodes.length > 0) {
  386. parseHistory(result.nodes);
  387. }
  388. },
  389. error: function(xhr){
  390. setLoading(false);
  391. if(xhr.responseJSON) {
  392. var response = xhr.responseJSON;
  393. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  394. dialog.show('获取用户信息失败', '请先登录!');
  395. } else {
  396. dialog.show('错误', response.exceptionInfo);
  397. }
  398. }
  399. }
  400. });
  401. };
  402. // get bill main
  403. var getBillMain = function(caller, url, cond, billId) {
  404. // $.post(basePath + 'common/rsForm.action', {
  405. // caller: caller,
  406. // condition: cond,
  407. // url: url,
  408. // _noc: 1
  409. // }, function(result, text) {
  410. // var e = result.exceptionInfo;
  411. // if(e) {
  412. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  413. // dialog.show('错误', '请先登录!');
  414. // } else {
  415. // dialog.show('出现异常', '请稍后再试...');
  416. // }
  417. // } else {
  418. // if(result.data) {
  419. // parseBillMain(result);
  420. // if(caller == 'VisitRecord') {
  421. // initVisitRecord(result, billId);
  422. // }
  423. // }
  424. // }
  425. // });
  426. $.ajax({
  427. url:basePath + 'common/rsForm.action',
  428. type: 'POST',
  429. data: {caller: caller, condition: cond, condition: cond, url: url, _noc: 1},
  430. success: function(result){
  431. if(result.data) {
  432. parseBillMain(result);
  433. if(caller == 'VisitRecord') {
  434. initVisitRecord(result, billId);
  435. }
  436. }
  437. },
  438. error: function(xhr){
  439. if(xhr.responseJSON) {
  440. var response = xhr.responseJSON;
  441. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  442. dialog.show('获取用户信息失败', '请先登录!');
  443. } else {
  444. dialog.show('错误', response.exceptionInfo);
  445. }
  446. }
  447. }
  448. });
  449. };
  450. // get bill detail
  451. var getBillDetail = function(caller, url, cond){
  452. setLoading(true);
  453. // $.post(basePath + 'common/rsGrid.action', {
  454. // caller: caller,
  455. // condition: cond,
  456. // url: url,
  457. // start: 0,
  458. // end: 100,
  459. // _noc: 1
  460. // }, function(result, text) {
  461. // setLoading(false);
  462. // var e = result.exceptionInfo;
  463. // if(e) {
  464. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  465. // dialog.show('错误', '请先登录!');
  466. // } else {
  467. // dialog.show('出现异常', '请稍后再试...');
  468. // }
  469. // } else {
  470. // if(result.data)
  471. // parseBillDetail(result.data);
  472. // }
  473. // });
  474. $.ajax({
  475. url:basePath + 'common/rsGrid.action',
  476. type: 'POST',
  477. data: {caller: caller, condition: cond, url: url, start: 0, end: 100, _noc: 1},
  478. success: function(result){
  479. setLoading(false);
  480. if(result.data)
  481. parseBillDetail(result.data);
  482. },
  483. error: function(xhr){
  484. setLoading(false);
  485. if(xhr.responseJSON) {
  486. var response = xhr.responseJSON;
  487. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  488. dialog.show('获取用户信息失败', '请先登录!');
  489. } else {
  490. dialog.show('错误', response.exceptionInfo);
  491. }
  492. }
  493. }
  494. });
  495. };
  496. // parse current node
  497. var parseNode = function(node) {
  498. current = node;
  499. $('#jp_name').html('[接管] ' + node.jp_name);
  500. $('#jp_name').css('margin-left', "-" + node.jp_name.replace(/[^\x00-\xff]/g, 'xx').length * 7 + "px");
  501. $('#jp_nodeName').text( node.jp_nodeName);
  502. $('#jp_launcherName').text(node.jp_launcherName);
  503. $('#jp_launchTime').text(parseDate(new Date(node.jp_launchTime)));
  504. $('#jp_codevalue').text(node.jp_codevalue);
  505. // get bill main data
  506. if(node.jp_keyName && node.jp_keyValue) {
  507. getBillMain(node.jp_caller, node.jp_url, node.jp_keyName + '=\'' + node.jp_keyValue + '\'', node.jp_keyValue);
  508. }
  509. // has detail
  510. if(node.jp_formDetailKey) {
  511. $('#detail-header').bind('boxready', function(){
  512. getBillDetail(node.jp_caller, node.jp_url, node.jp_formDetailKey + '=\'' + node.jp_keyValue + '\'');
  513. });
  514. } else {
  515. $('#detail-header').css('display', 'none');
  516. }
  517. // main point
  518. getMainPoint(node.jp_nodeId);
  519. };
  520. // parse main point
  521. var parseMainPoint = function(points) {
  522. var html = '<ul class="list-group">';
  523. html += '<li class="list-group-item disabled"><strong>问题要点</strong></li>';
  524. $.each(points, function(i, p){
  525. html += '<li class="list-group-item">';
  526. html += '<span>' + p.text + '</span>';
  527. if(p.type === 'B') {
  528. 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>';
  529. } else if(p.type === 'S' || p.type === 'N') {
  530. 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>';
  531. } else if(p.type === 'D') {
  532. 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>';
  533. }
  534. html += '</li>';
  535. });
  536. html += '</ul>';
  537. $('#points').html(html);
  538. // toggle switch
  539. $('#points .has-switch').click(function(){
  540. var e = $(this), box = e.find('input'), checked = box.is(':checked');
  541. if(checked)
  542. box.removeAttr('checked');
  543. else
  544. box.attr('checked','checked');
  545. e.find('>div').removeClass(checked ? 'switch-on' : 'switch-off');
  546. e.find('>div').addClass(checked ? 'switch-off' : 'switch-on');
  547. });
  548. };
  549. // parse bill main
  550. var parseBillMain = function(main) {
  551. var bill = main.data, html = '<table class="table table-condensed table-bordered table-striped">', g = null;
  552. if(main.group) {
  553. for(k in bill) {
  554. g = bill[k];
  555. html += '<tr><td colspan="2" class="text-center text-success"><strong>' + k + '</strong>&nbsp;<span class="glyphicon glyphicon-chevron-down"></span></td></tr>';
  556. for(b in g) {
  557. html += '<tr>';
  558. html += '<td class="text-right special"><strong>' + b + '</strong></td>';
  559. html += '<td class="text-center">' + g[b] + '</td>';
  560. html += '</tr>';
  561. };
  562. }
  563. } else {
  564. for(b in bill) {
  565. html += '<tr>';
  566. html += '<td class="text-right special"><strong>' + b + '</strong></td>';
  567. html += '<td class="text-center">' + bill[b] + '</td>';
  568. html += '</tr>';
  569. };
  570. }
  571. html += '</table>';
  572. $('#bill-main').html(html);
  573. };
  574. // parse bill detail
  575. var parseBillDetail = function(detail){
  576. var html = '<table id="bill-detail-table" class="table table-condensed table-bordered table-striped">';
  577. for(c in detail) {
  578. html += '<tr>';
  579. html += '<td class="text-right special"><strong>' + c + '</strong></td>';
  580. if(detail[c] && detail[c].length > 0) {
  581. $.each(detail[c], function(i, p){
  582. html += '<td class="text-center">' + p + '</td>';
  583. });
  584. } else {
  585. html += '<td class="text-center text-muted">(无)</td>';
  586. }
  587. html += '</tr>';
  588. }
  589. html += '</table>';
  590. $('#bill-detail').html(html);
  591. var table = $('#bill-detail table');
  592. freezeTable(table, 0, 1, pageWidth());
  593. var flag = false;
  594. $(window).resize(function() {
  595. if (flag)
  596. return ;
  597. setTimeout(function() {
  598. adjustTableSize(table.attr('id'), pageWidth());
  599. flag = false;
  600. }, 100);
  601. flag = true;
  602. });
  603. };
  604. // parse history
  605. var parseHistory = function(hist) {
  606. var html = '<ul class="list-unstyled list-inline">';
  607. $.each(hist, function(i, h){
  608. var res = h.jn_dealResult == '同意' ? 'success' : (h.jn_dealResult == '不同意' ? 'error' : 'warning');
  609. html += '<li>';
  610. html += '<div class="text-top">';
  611. html += '<span>' + h.jn_name + '</span>';
  612. html += '</div>';
  613. html += '<blockquote>';
  614. html += '<strong>' + h.jn_dealManName + '</strong>';
  615. html += '<div class="text-trans ' + res + '">';
  616. html += '<span>' + h.jn_dealResult + '</span>';
  617. html += '</div>';
  618. html += '<footer>' + h.jn_dealTime + '</footer>';
  619. html += '</blockquote>';
  620. if(h.jn_operatedDescription || h.jn_nodeDescription || h.jn_infoReceiver) {
  621. html += '<div class="highlight">';
  622. if(h.jn_nodeDescription)
  623. html += '<div>' + h.jn_nodeDescription + '</div>';
  624. if(h.jn_infoReceiver)
  625. html += '<p class="text-muted"><i>' + h.jn_infoReceiver + '</i></p>';
  626. if(h.jn_operatedDescription) {
  627. if(h.jn_operatedDescription.indexOf('(是)') > 0 ||
  628. h.jn_operatedDescription.indexOf('(否)') > 0) {
  629. html += '<ul class="list-group">';
  630. var descs = h.jn_operatedDescription.split(';');
  631. $.each(descs, function(j, d){
  632. res = d.substr(d.length - 3) == '(是)' ? 'glyphicon glyphicon-ok text-success' :
  633. 'glyphicon glyphicon-remove text-warning';
  634. html += '<li class="list-group-item"><span class="pull-right ' + res + '"></span>' + d.substr(0, d.length-3) + '</li>';
  635. });
  636. html += '</ul>';
  637. } else {
  638. html += '<div>' + h.jn_operatedDescription + '</div>';
  639. }
  640. }
  641. html += '</div>';
  642. }
  643. html += '</li>';
  644. });
  645. html += '</ul>';
  646. $('#history').html(html);
  647. };
  648. // get process by node id
  649. var nodeId = getUrlParam('nodeId');
  650. if (nodeId) {
  651. getProcess(nodeId);
  652. // get history by instance id
  653. $('#history-header').bind('boxready', function(){
  654. if(instance) {
  655. getHistory(instance);
  656. } else {
  657. getInstance(nodeId, function(instanceId){
  658. getHistory(instanceId);
  659. });
  660. }
  661. });
  662. }
  663. // get radio,checkbox value
  664. var getBoxValue = function(selector) {
  665. var value = null;
  666. $(selector).each(function(){
  667. var t = $(this);
  668. if(t.is(":checked")) {
  669. value = t.val();
  670. }
  671. });
  672. return value;
  673. };
  674. // accept接管按钮
  675. var accept = function() {
  676. setLoading(true);
  677. // $.post(basePath + 'common/takeOverTask.action', {
  678. // nodeId: nodeId,
  679. // em_code: em_code,
  680. // needreturn: true,
  681. // _noc: 1
  682. // }, function(result, text) {
  683. // setLoading(false);
  684. // if(result.success) {
  685. // $('.modal .modal-header').css('color', '#27ad60');
  686. // dialog.show('接管成功', '正在为您跳转至单据操作界面...', 1, function(){
  687. // window.location.href = basePath + 'jsps/mobile/process.jsp?nodeId=' + nodeId;
  688. // });
  689. // } else if (result.exceptionInfo){
  690. // $('.modal .modal-header').css('color', '#f50');
  691. // dialog.show('接管失败', result.exceptionInfo + '<br>请返回应用界面');
  692. // } else {
  693. // $('.modal .modal-header').css('color', '#f50');
  694. // dialog.show('处理结果', "出现错误,请联系管理员。");
  695. // }
  696. // });
  697. $.ajax({
  698. url:basePath + 'common/takeOverTask.action',
  699. type: 'POST',
  700. data: {nodeId: nodeId, em_code: em_code, needreturn: true, _noc: 1},
  701. success: function(result){
  702. setLoading(false);
  703. if(result.success) {
  704. $('.modal .modal-header').css('color', '#27ad60');
  705. dialog.show('接管成功', '正在为您跳转至单据操作界面...', 1, function(){
  706. window.location.href = basePath + 'jsps/mobile/process.jsp?nodeId=' + nodeId;
  707. });
  708. }
  709. },
  710. error: function(xhr){
  711. setLoading(false);
  712. $('.modal .modal-header').css('color', '#f50');
  713. if(xhr.responseJSON) {
  714. var response = xhr.responseJSON;
  715. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  716. dialog.show('获取信息失败', '请先登录!');
  717. } else {
  718. dialog.show('接管失败', response.exceptionInfo + '<br>请返回应用界面');
  719. }
  720. }
  721. }
  722. });
  723. };
  724. $('#accept').click(function(){
  725. accept();
  726. });
  727. // close 跳转至首页
  728. $('#close').click(function(){
  729. window.location.href = basePath;
  730. });
  731. // get search result
  732. var getSearchResult = function(input) {
  733. setLoading(true);
  734. // $.post(basePath + 'hr/emplmana/search.action', {
  735. // keyword: input
  736. // }, function(result, text){
  737. // setLoading(false);
  738. // if(result.length > 0) {
  739. // parseSearchResult(result);
  740. // }
  741. // });
  742. $.ajax({
  743. url:basePath + 'hr/emplmana/search.action',
  744. type: 'POST',
  745. data: {keyword: input},
  746. success: function(result){
  747. setLoading(false);
  748. if(result.length > 0) {
  749. parseSearchResult(result);
  750. }
  751. },
  752. error: function(xhr){
  753. setLoading(false);
  754. if(xhr.responseJSON) {
  755. var response = xhr.responseJSON;
  756. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  757. dialog.show('获取信息失败', '请先登录!');
  758. } else {
  759. dialog.show('错误', response.exceptionInfo);
  760. }
  761. }
  762. }
  763. });
  764. };
  765. // parse search result
  766. var parseSearchResult = function(datas){
  767. var html = '';
  768. $.each(datas, function(i, d){
  769. var e = d.split('\n');
  770. html += '<a href="javascript:onItemClick(\'' + e[1] + '\',\'' + e[2] + '\');" class="list-group-item">';
  771. html += '<span>' + e[0] + '</span>';
  772. html += '<span class="right">' + e[1] + '(' + e[2] + ')</span>';
  773. html += '</a>';
  774. });
  775. $('#em_search').html(html);
  776. };
  777. // touch on mobile need jquery-mobile.js & event 'tap'
  778. window.onItemClick = function(code, name) {
  779. $('#em_search').parent().css('display', 'none');
  780. $('#em_code').text(code);
  781. };
  782. });