task.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. //读取链接参数
  2. function getUrlParam(name, link){
  3. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  4. var search;
  5. if (link) {search = link.substr(link.indexOf("?"),link.length);}
  6. else { search = window.location.search;}
  7. var r = search.substr(1).match(reg);
  8. if (r != null)
  9. return decodeURI(r[2]);
  10. return null;
  11. }
  12. //处理日期
  13. function parseDate(date){
  14. var y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(),
  15. h = date.getHours(), i = date.getMinutes();
  16. var now = new Date(), _y = now.getFullYear(), _m = now.getMonth() + 1, _d = now.getDate();
  17. if(_y != y) {
  18. return y + '-' + m + '-' + d + ' ' + h + ':' + i;
  19. } else {
  20. if(_m != m) {
  21. return m + '月' + d + '号' + h + '点' + i + '分';
  22. } else {
  23. if(_d != d) {
  24. return d + '号' + h + '点' + i + '分';
  25. } else {
  26. return (h < 12 ? '上午' : '下午' ) + h + '点' + i + '分';
  27. }
  28. }
  29. }
  30. }
  31. /**
  32. * 锁定表头和列
  33. *
  34. * 参数定义
  35. * table - 要锁定的表格元素或者表格ID
  36. * freezeRowNum - 要锁定的前几行行数,如果行不锁定,则设置为0
  37. * freezeColumnNum - 要锁定的前几列列数,如果列不锁定,则设置为0
  38. * width - 表格的滚动区域宽度
  39. */
  40. function freezeTable(table, freezeRowNum, freezeColumnNum, width) {
  41. if (typeof(freezeRowNum) == 'string')
  42. freezeRowNum = parseInt(freezeRowNum);
  43. if (typeof(freezeColumnNum) == 'string')
  44. freezeColumnNum = parseInt(freezeColumnNum);
  45. var tableId;
  46. if (typeof(table) == 'string') {
  47. tableId = table;
  48. table = $('#' + tableId);
  49. } else
  50. tableId = table.attr('id');
  51. if(table.width() <= width) return;
  52. height = table.height() + 10;
  53. var divTableLayout = $("#" + tableId + "_tableLayout");
  54. if (divTableLayout.length != 0) {
  55. divTableLayout.before(table);
  56. divTableLayout.empty();
  57. } else {
  58. table.after("<div id='" + tableId + "_tableLayout' style='overflow:hidden;height:" + height + "px; width:" + width + "px;'></div>");
  59. divTableLayout = $("#" + tableId + "_tableLayout");
  60. }
  61. var html = '';
  62. if (freezeRowNum > 0 && freezeColumnNum > 0)
  63. html += '<div id="' + tableId + '_tableFix" style="padding: 0px;"></div>';
  64. if (freezeRowNum > 0)
  65. html += '<div id="' + tableId + '_tableHead" style="padding: 0px;"></div>';
  66. if (freezeColumnNum > 0)
  67. html += '<div id="' + tableId + '_tableColumn" style="padding: 0px;"></div>';
  68. html += '<div id="' + tableId + '_tableData" style="padding: 0px;"></div>';
  69. $(html).appendTo("#" + tableId + "_tableLayout");
  70. var divTableFix = freezeRowNum > 0 && freezeColumnNum > 0 ? $("#" + tableId + "_tableFix") : null;
  71. var divTableHead = freezeRowNum > 0 ? $("#" + tableId + "_tableHead") : null;
  72. var divTableColumn = freezeColumnNum > 0 ? $("#" + tableId + "_tableColumn") : null;
  73. var divTableData = $("#" + tableId + "_tableData");
  74. divTableData.append(table);
  75. if (divTableFix != null) {
  76. var tableFixClone = table.clone(true);
  77. tableFixClone.attr("id", tableId + "_tableFixClone");
  78. divTableFix.append(tableFixClone);
  79. }
  80. if (divTableHead != null) {
  81. var tableHeadClone = table.clone(true);
  82. tableHeadClone.attr("id", tableId + "_tableHeadClone");
  83. divTableHead.append(tableHeadClone);
  84. }
  85. if (divTableColumn != null) {
  86. var tableColumnClone = table.clone(true);
  87. tableColumnClone.attr("id", tableId + "_tableColumnClone");
  88. divTableColumn.append(tableColumnClone);
  89. }
  90. $("#" + tableId + "_tableLayout table").css("margin", "0");
  91. if (freezeRowNum > 0) {
  92. var HeadHeight = 0;
  93. var ignoreRowNum = 0;
  94. $("#" + tableId + "_tableHead tr:lt(" + freezeRowNum + ")").each(function () {
  95. if (ignoreRowNum > 0)
  96. ignoreRowNum--;
  97. else {
  98. var td = $(this).find('td:first, th:first');
  99. HeadHeight += td.outerHeight(true);
  100. ignoreRowNum = td.attr('rowSpan');
  101. if (typeof(ignoreRowNum) == 'undefined')
  102. ignoreRowNum = 0;
  103. else
  104. ignoreRowNum = parseInt(ignoreRowNum) - 1;
  105. }
  106. });
  107. HeadHeight += 2;
  108. divTableHead.css("height", HeadHeight);
  109. divTableFix != null && divTableFix.css("height", HeadHeight);
  110. }
  111. if (freezeColumnNum > 0) {
  112. var ColumnsWidth = 0;
  113. var ColumnsNumber = 0;
  114. $("#" + tableId + "_tableColumn tr:eq(" + freezeRowNum + ")").find("td:lt(" + freezeColumnNum + "), th:lt(" + freezeColumnNum + ")").each(function () {
  115. if (ColumnsNumber >= freezeColumnNum)
  116. return;
  117. ColumnsWidth += $(this).outerWidth(true);
  118. ColumnsNumber += $(this).attr('colSpan') ? parseInt($(this).attr('colSpan')) : 1;
  119. });
  120. ColumnsWidth += 2;
  121. divTableColumn.css("width", ColumnsWidth);
  122. divTableFix != null && divTableFix.css("width", ColumnsWidth);
  123. }
  124. divTableData.scroll(function () {
  125. divTableHead != null && divTableHead.scrollLeft(divTableData.scrollLeft());
  126. divTableColumn != null && divTableColumn.scrollTop(divTableData.scrollTop());
  127. });
  128. divTableFix != null && divTableFix.css({ "overflow": "hidden", "position": "absolute", "z-index": "50" });
  129. divTableHead != null && divTableHead.css({ "overflow": "hidden", "width": width, "position": "absolute", "z-index": "45" });// - 17
  130. divTableColumn != null && divTableColumn.css({ "overflow": "hidden", "height": height, "position": "absolute", "z-index": "40" });// - 17
  131. divTableData.css({ "overflow": "scroll", "width": width, "height": height, "position": "absolute" });
  132. divTableFix != null && divTableFix.offset(divTableLayout.offset());
  133. divTableHead != null && divTableHead.offset(divTableLayout.offset());
  134. divTableColumn != null && divTableColumn.offset(divTableLayout.offset());
  135. divTableData.offset(divTableLayout.offset());
  136. }
  137. /**
  138. * 调整锁定表的宽度和高度,这个函数在resize事件中调用
  139. *
  140. * 参数定义
  141. * table - 要锁定的表格元素或者表格ID
  142. * width - 表格的滚动区域宽度
  143. */
  144. function adjustTableSize(table, width) {
  145. var tableId;
  146. if (typeof(table) == 'string')
  147. tableId = table;
  148. else
  149. tableId = table.attr('id');
  150. height = $("#" + tableId).height() + 10;
  151. $("#" + tableId + "_tableLayout").width(width).height(height);
  152. $("#" + tableId + "_tableHead").width(width);// - 17
  153. $("#" + tableId + "_tableColumn").height(height);// - 17
  154. $("#" + tableId + "_tableData").width(width).height(height);
  155. }
  156. //返回当前页面宽度
  157. function pageWidth() {
  158. if ($.browser.msie) {
  159. return document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth;
  160. } else {
  161. // - padding
  162. return self.innerWidth - 30;
  163. }
  164. };
  165. $(document).ready(function() {
  166. //自定义事件类型 boxready(当第一次点击时触发,当Tab页面第一次打开时触发)
  167. $.event.special.boxready = {
  168. /**
  169. * 初始化事件处理器 - this指向元素
  170. * @param 附加的数据
  171. * @param 事件类型命名空间
  172. * @param 回调函数
  173. */
  174. setup: function(data, namespaces, eventHandle) {
  175. var elem = this;
  176. $.event.add(elem, 'click', function (event) {
  177. if ($.data(elem, '@loaded') !== true) {
  178. $.event.trigger('boxready', null, elem);
  179. $.data(elem, '@loaded', true);
  180. }
  181. });
  182. },
  183. /**
  184. * 卸载事件处理器 - this指向元素
  185. * @param 事件类型命名空间
  186. */
  187. teardown: function(namespaces) {
  188. var elem = this;
  189. $.event.remove(elem, 'click');
  190. $.removeData(elem, '@loaded');
  191. }
  192. };
  193. var cls = 'active', instance = null, current = null, readyTime = new Date();
  194. // Tab切换开关增加点击事件
  195. $('.nav-tabs>li>a').click(function(){
  196. if(!$(this).hasClass(cls)) {
  197. var nav = $(this).parent().parent(), bd = nav.parent().next(),
  198. old = nav.children('.' + cls).index(),
  199. index = $(this).parent().index();
  200. $('.tab-pane:eq(' + old + ')', bd).removeClass(cls);
  201. $('.tab-pane:eq(' + index + ')', bd).addClass(cls);
  202. nav.children('.' + cls).removeClass(cls);
  203. $(this).parent().addClass(cls);
  204. }
  205. });
  206. // 模态对话框
  207. var dialog = {
  208. show: function(title, content, timeout, callback){
  209. var back = $('.modal-backdrop'), modal = $('.modal'),
  210. tt = $('.modal-title', modal), tb = $('.modal-body', modal);
  211. back.css('display', 'block');
  212. modal.css('display', 'block');
  213. tt.text(title);
  214. if(timeout && timeout > 0) {
  215. content = '<div><strong class="text-success text-xl" id="timeout">' + timeout + '</strong>&nbsp;秒后,' + content + '</div>';
  216. }
  217. tb.html(content);
  218. if(timeout) {
  219. var pre = 1000;
  220. if(timeout <=0 ) {// auto close
  221. pre = 1500;
  222. if(!callback)
  223. callback = dialog.hide;
  224. }
  225. var timer = function(t) {
  226. setTimeout(function(){
  227. if(t > -1) {
  228. $('#timeout').text(t--);
  229. timer(t);
  230. } else {
  231. callback && callback.call();
  232. }
  233. }, pre);
  234. };
  235. timer(timeout);
  236. }
  237. },
  238. hide: function() {
  239. var back = $('.modal-backdrop'), modal = $('.modal');
  240. back.css('display', 'none');
  241. modal.css('display', 'none');
  242. }
  243. };
  244. // 加载框
  245. var setLoading = function(isLoading) {
  246. $('.loading-container').css('display', isLoading ? 'block' : 'none');
  247. };
  248. //处理singleFormItems.action结果请求,返回parseBillMain处理的格式
  249. var dealForm = function(result) {
  250. var taskInfo = {data:{}, group:false};
  251. var data = eval('(' + result.data + ')');
  252. for(i in result.items) {
  253. var item = result.items[i];
  254. if(item.group == 0) {
  255. taskInfo.data[$(item.html).text()] = {};
  256. taskInfo.group = true;
  257. } else {
  258. if(item.groupName) {
  259. if(item.xtype!='hidden'){
  260. if(data[item.dataIndex]!='')
  261. taskInfo.data[item.groupName][item.fieldLabel] =
  262. (data[item.dataIndex]||data[item.dataIndex]==0)?data[item.dataIndex]:
  263. ((item.value||item.value==0)?item.value:'无');
  264. }
  265. } else {
  266. if (item.xtype!='hidden') {
  267. if(data[item.dataIndex]!='')
  268. taskInfo.data[item.fieldLabel]=
  269. (data[item.dataIndex]||data[item.dataIndex]==0)?data[item.dataIndex]:
  270. ((item.value||item.value==0)?item.value:'无');
  271. };
  272. }
  273. }
  274. }
  275. return taskInfo;
  276. };
  277. //处理singleGridPanel.action的结果,返回parseBillDetail处理的格式
  278. var dealGrid = function(result) {
  279. var resultData = {};
  280. var data = eval('(' + result.data + ')');
  281. for(i in result.columns) {
  282. var column = result.columns[i];
  283. if(!column.hidden){
  284. resultData[column.header] = [];
  285. for (d in data) {
  286. resultData[column.header].push(data[d][column.dataIndex])
  287. };
  288. }
  289. }
  290. return resultData;
  291. };
  292. //获取相关单据的明细
  293. var getRelationDetail = function(caller, gridCondition, container){
  294. setLoading(true);
  295. // $.post(basePath + 'common/singleGridPanel.action', {
  296. // caller: caller,
  297. // condition: gridCondition,
  298. // _m: 0
  299. // }, function(result, text) {
  300. // setLoading(false);
  301. // var e = result.exceptionInfo;
  302. // if(e) {
  303. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  304. // dialog.show('获取用户信息失败', '请先登录!');
  305. // } else {
  306. // dialog.show('出现异常', '请稍后再试...');
  307. // }
  308. // } else {
  309. // parseBillDetail(dealGrid(result), container);
  310. // }
  311. // });
  312. $.ajax({
  313. url:basePath + 'common/singleGridPanel.action',
  314. type: 'POST',
  315. data: {caller: caller, condition: gridCondition, _m: 0},
  316. success: function(result){
  317. setLoading(false);
  318. parseBillDetail(dealGrid(result), container);
  319. },
  320. error: function(xhr){
  321. setLoading(false);
  322. if(xhr.responseJSON) {
  323. var response = xhr.responseJSON;
  324. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  325. dialog.show('获取用户信息失败', '请先登录!');
  326. } else {
  327. dialog.show('错误', response.exceptionInfo);
  328. }
  329. }
  330. }
  331. });
  332. };
  333. //收缩监听事件
  334. $('#shrink').click(function(){
  335. setLoading(true);
  336. $('#relative #relation').addClass('hidden');
  337. $('#relative #expand').removeClass('hidden');
  338. setLoading(false);
  339. });
  340. //获取相关单据
  341. var getRelation = function(billLink) {
  342. $('#relation').removeClass('hidden');
  343. var c = getUrlParam('whoami', billLink);
  344. var fc = getUrlParam('formCondition', billLink).replace('IS', '=');
  345. var gc = getUrlParam('gridCondition', billLink).replace('IS', '=');
  346. setLoading(true);
  347. // $.post(basePath + 'common/singleFormItems.action', {
  348. // caller: c,
  349. // condition: fc,
  350. // _noc: 1
  351. // }, function(result, text) {
  352. // setLoading(false);
  353. // var e = result.exceptionInfo;
  354. // if(e) {
  355. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  356. // dialog.show('获取用户信息失败', '请先登录!');
  357. // } else {
  358. // dialog.show('出现异常', '请稍后再试...');
  359. // }
  360. // } else {
  361. // parseBillMain(dealForm(result), $('#relation-main'));
  362. // $('#relation-detail-header').bind('boxready', function(){
  363. // getRelationDetail(c, gc, $('#relation-detail'));
  364. // });
  365. // }
  366. // });
  367. $.ajax({
  368. url:basePath + 'common/singleFormItems.action',
  369. type: 'POST',
  370. data: {caller: c, condition: fc, _noc: 1},
  371. success: function(result){
  372. setLoading(false);
  373. parseBillMain(dealForm(result), $('#relation-main'));
  374. $('#relation-detail-header').bind('boxready', function(){
  375. getRelationDetail(c, gc, $('#relation-detail'));
  376. });
  377. },
  378. error: function(xhr){
  379. setLoading(false);
  380. if(xhr.responseJSON) {
  381. var response = xhr.responseJSON;
  382. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  383. dialog.show('获取用户信息失败', '请先登录!');
  384. } else {
  385. dialog.show('错误', response.exceptionInfo);
  386. }
  387. }
  388. }
  389. });
  390. };
  391. //get record 获取任务的操作记录
  392. var getRecord = function(id) {
  393. // $.post(basePath + 'common/getFieldsDatas.action', {
  394. // caller: 'WorkRecord',
  395. // fields: 'wr_recorder,wr_recorddate,wr_redcord',
  396. // condition: 'wr_raid='+ id + ' order by wr_recorddate'
  397. // }, function(result){
  398. // var e = result.exceptionInfo;
  399. // if(e) {
  400. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  401. // dialog.show('获取用户信息失败', '请先登录!');
  402. // } else {
  403. // dialog.show('出现异常', '请稍后再试...');
  404. // }
  405. // } else {
  406. // parseRecord(result);
  407. // }
  408. // });
  409. $.ajax({
  410. url:basePath + 'common/getFieldsDatas.action',
  411. type: 'POST',
  412. data: {
  413. caller: 'WorkRecord',
  414. fields: 'wr_recorder,wr_recorddate,wr_redcord',
  415. condition: 'wr_raid='+ id + ' order by wr_recorddate'
  416. },
  417. success: function(result){
  418. parseRecord(result);
  419. },
  420. error: function(xhr){
  421. if(xhr.responseJSON) {
  422. var response = xhr.responseJSON;
  423. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  424. dialog.show('获取用户信息失败', '请先登录!');
  425. } else {
  426. dialog.show('错误', response.exceptionInfo);
  427. }
  428. }
  429. }
  430. });
  431. };
  432. //parseRecord 显示任务记录的信息
  433. var parseRecord = function(result){
  434. var data = eval('(' + result.data + ')');
  435. var html = '';
  436. for(d in data) {
  437. var datetime = new Date(data[d].WR_RECORDDATE);
  438. if(isNaN(datetime)) {
  439. datetime = new Date(data[d].WR_RECORDDATE.replace(' ','T'))
  440. }
  441. html += '<div class="record">' +
  442. '<div><span class="recorder">' + data[0].WR_RECORDER + '</span>&nbsp;&nbsp;' +
  443. '<span class="recorddate">' + parseDate(datetime) + '<span></div>' +
  444. '<div class="record-content">' + data[0].WR_REDCORD + '</div>' +
  445. '</div>'
  446. };
  447. $('#record').html(html);
  448. };
  449. //get task 获取task
  450. var getTask = function(caller, id) {
  451. setLoading(true);
  452. var url = basePath + 'common/singleFormItems.action';
  453. if(caller == 'WorkRecord') url = basePath + 'plm/RecordFormItemsAndData.action';
  454. // $.post(url, {
  455. // caller: caller,
  456. // condition: 'ra_id=' + id,
  457. // _noc:1
  458. // }, function(result, text){
  459. // setLoading(false);
  460. // var e = result.exceptionInfo;
  461. // if(e) {
  462. // if(e == 'ERR_NETWORK_SESSIONOUT') {
  463. // dialog.show('获取用户信息失败', '请先登录!');
  464. // } else {
  465. // dialog.show('出现异常', e + ',请稍后再试...');
  466. // }
  467. // } else {
  468. // parseTask(result);
  469. // }
  470. // });
  471. $.ajax({
  472. url:url,
  473. type: 'POST',
  474. data: {caller: caller, condition: 'ra_id=' + id, _noc:1},
  475. success: function(result){
  476. setLoading(false);
  477. parseTask(result);
  478. },
  479. error: function(xhr){
  480. setLoading(false);
  481. if(xhr.responseJSON) {
  482. var response = xhr.responseJSON;
  483. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  484. dialog.show('获取用户信息失败', '请先登录!');
  485. } else {
  486. dialog.show('错误', response.exceptionInfo);
  487. }
  488. }
  489. }
  490. });
  491. };
  492. // 增加被指定任务处理人回复任务的按钮
  493. var addReplyButton = function() {
  494. $('#deal .form').append('<textarea id="deal-msg" rows="2" placeholder="回复您的任务完成情况..."' +
  495. 'class="form-control"></textarea>');
  496. $('#buttons').append('<div class="btn-group">' +
  497. '<button id="reply" type="button" class="btn btn-default line">' +
  498. '<span class="glyphicon glyphicon-edit"></span>&nbsp;回复' +
  499. '</button>' +
  500. '</div>');
  501. $('#reply').click(function(){
  502. replyTask($('#deal-msg').val());
  503. });
  504. }
  505. // 被指定任务处理人回复任务处理情况
  506. var replyTask = function(record) {
  507. if(record) {
  508. setLoading(true);
  509. $.ajax({
  510. url: basePath + 'plm/record/endBillTask.action',
  511. type: 'POST',
  512. dataType: 'json',
  513. data: {caller:'ResourceAssignment!Bill', ra_id: id, record: record, _noc: 1},
  514. success: function(data){
  515. setLoading(false);
  516. if(data.success) {
  517. dialog.show('任务回复成功', '回复内容已提交任务发起人确认,请关闭页面');
  518. }
  519. },
  520. error: function(xhr){
  521. if(xhr.responseJSON) {
  522. var response = xhr.responseJSON;
  523. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  524. dialog.show('获取信息失败', '请先登录!');
  525. } else {
  526. dialog.show('错误', response.exceptionInfo);
  527. }
  528. }
  529. }
  530. });
  531. } else {
  532. dialog.show('提示', '回复前请先填写任务完成情况', 1);
  533. }
  534. };
  535. // 增加任务发起人确认和驳回任务的按钮
  536. var addConfirmButton = function() {
  537. $('#deal .form').append('<textarea id="deal-msg" rows="2" placeholder="请说说您对任务完成情况的意见..."' +
  538. 'class="form-control"></textarea>');
  539. $('#buttons').append('<div class="btn-group">' +
  540. '<button id="confirm" type="button" class="btn btn-default line">' +
  541. '<span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;确认' +
  542. '</button>' +
  543. '</div>' +
  544. '<div class="btn-group">' +
  545. '<button id="noConfirm" type="button" class="btn btn-default line">' +
  546. '<span class="glyphicon glyphicon-thumbs-down"></span>&nbsp;驳回' +
  547. '</button>' +
  548. '</div>');
  549. $('#confirm').click(function(){
  550. confirmTask($('#deal-msg').val());
  551. });
  552. $('#noConfirm').click(function(){
  553. noConfirmTask($('#deal-msg').val());
  554. });
  555. }
  556. // 任务发起人确认任务
  557. var confirmTask = function(record) {
  558. if(record) {
  559. setLoading(true);
  560. $.ajax({
  561. url: basePath + 'plm/record/confirmBillTask.action',
  562. type: 'POST',
  563. dataType: 'json',
  564. data: {caller:'ResourceAssignment!Bill', ra_id: id, record: record, _noc: 1},
  565. success: function(data){
  566. setLoading(false);
  567. if(data.success) {
  568. dialog.show('任务确认成功', '任务已成功结束,正在刷新...', 1, function(){
  569. location.reload();
  570. });
  571. }
  572. },
  573. error: function(xhr){
  574. if(xhr.responseJSON) {
  575. var response = xhr.responseJSON;
  576. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  577. dialog.show('获取信息失败', '请先登录!');
  578. } else {
  579. dialog.show('错误', response.exceptionInfo);
  580. }
  581. }
  582. }
  583. });
  584. } else {
  585. dialog.show('提示', '确认前请先填写你的意见', 1);
  586. }
  587. };
  588. // 任务发起人驳回任务
  589. var noConfirmTask = function(record) {
  590. if(record) {
  591. setLoading(true);
  592. $.ajax({
  593. url: basePath + 'plm/record/noConfirmBillTask.action',
  594. type: 'POST',
  595. dataType: 'json',
  596. data: {caller:'ResourceAssignment!Bill', ra_id: id, record: record, _noc: 1},
  597. success: function(data){
  598. setLoading(false);
  599. if(data.success) {
  600. dialog.show('任务驳回成功', '任务处理人将接收到您的意见,并重新处理任务,请关闭页面');
  601. }
  602. },
  603. error: function(xhr){
  604. if(xhr.responseJSON) {
  605. var response = xhr.responseJSON;
  606. if(response.exceptionInfo == 'ERR_NETWORK_SESSIONOUT') {
  607. dialog.show('获取信息失败', '请先登录!');
  608. } else {
  609. dialog.show('错误', response.exceptionInfo);
  610. }
  611. }
  612. }
  613. });
  614. } else {
  615. dialog.show('提示', '驳回前请先填写你的意见', 1);
  616. }
  617. };
  618. // 展现任务数据
  619. var parseTask = function(task) {
  620. if(task.title && task.title!='') {
  621. $('#jp_name').text(task.title);
  622. } else {
  623. $('#jp_name').text('任务处理');
  624. }
  625. $('#jp_name').css('margin-left', "-" + $('#jp_name').text().replace(/[^\x00-\xff]/g, 'xx').length * 7 + "px");
  626. var taskInfo = dealForm(task);
  627. var data = eval('(' + task.data + ')');
  628. var buttons = task.buttons;
  629. parseBillMain(taskInfo, $('#bill-main'));
  630. if(data.sourcelink) {
  631. var caller = getUrlParam('whoami', data.sourcelink);
  632. if(!caller || caller=='') {
  633. $('#relative #expand').text('无法显示任务相关单据');
  634. }else {
  635. $('#relative #expand').click(function(){
  636. $('#relative #expand').addClass('hidden');
  637. getRelation(data.sourcelink);
  638. });
  639. };
  640. } else {
  641. $('#relative #expand').text('本任务无相关单据');
  642. }
  643. if(data.ra_statuscode == 'START') {// 进行中的任务,被指定的处理人可以回复任务
  644. addReplyButton();
  645. } else if(data.ra_statuscode == 'UNCONFIRMED') {// 待确认的任务,发起人可以确认或驳回
  646. addConfirmButton();
  647. } else {// 已结束的任务,不能做处理
  648. console.log('已结束');
  649. }
  650. // if(buttons.indexOf('erpOverButton') != -1) {//添加结束处理
  651. // addEndButoon();
  652. // }
  653. // 不加关闭按钮,2015年9月28日15:32:37
  654. }
  655. // parse bill main 把相关单据主表信息展现到页面中
  656. var parseBillMain = function(main, container) {
  657. var bill = main.data, html = '<table class="table table-condensed table-bordered table-striped">', g = null;
  658. if(main.group) {
  659. for(k in bill) {
  660. g = bill[k];
  661. html += '<tr><td colspan="2" class="text-center text-success"><strong>' + k + '</strong>&nbsp;<span class="glyphicon glyphicon-chevron-down"></span></td></tr>';
  662. for(b in g) {
  663. html += '<tr>';
  664. html += '<td class="text-right special"><strong>' + b + '</strong></td>';
  665. html += '<td class="text-center">' + g[b] + '</td>';
  666. html += '</tr>';
  667. };
  668. }
  669. } else {
  670. for(b in bill) {
  671. html += '<tr>';
  672. html += '<td class="text-right special"><strong>' + b + '</strong></td>';
  673. html += '<td class="text-center">' + bill[b] + '</td>';
  674. html += '</tr>';
  675. };
  676. }
  677. html += '</table>';
  678. container.html(html);
  679. };
  680. // parse bill detail 把相关单据明细表数据展现到页面中
  681. var parseBillDetail = function(detail, container){
  682. var html = '<table id="bill-detail-table" class="table table-condensed table-bordered table-striped">';
  683. for(c in detail) {
  684. html += '<tr>';
  685. html += '<td class="text-right special"><strong>' + c + '</strong></td>';
  686. if(detail[c] && detail[c].length > 0) {
  687. $.each(detail[c], function(i, p){
  688. html += '<td class="text-center">' + p + '</td>';
  689. });
  690. } else {
  691. html += '<td class="text-center text-muted">(无)</td>';
  692. }
  693. html += '</tr>';
  694. }
  695. html += '</table>';
  696. container.html(html);
  697. var table = container.children('table');
  698. freezeTable(table, 0, 1, pageWidth());
  699. var flag = false;
  700. $(window).resize(function() {
  701. if (flag)
  702. return ;
  703. setTimeout(function() {
  704. adjustTableSize(table.attr('id'), pageWidth());
  705. flag = false;
  706. }, 100);
  707. flag = true;
  708. });
  709. };
  710. //id参数,对应allprocess_view_undo视图中的id字段,resourceAssignment表中的ra_id字段
  711. var id = getUrlParam('id');
  712. // caller参数,billtask\mrptask\kbitask 类型的任务为ResourceAssignment!Bill , projecttask\worktask 为 WorkRecord
  713. var caller = getUrlParam('caller');
  714. if(id && caller) {
  715. getTask(caller, id);// 获取任务的信息和(如有)相关单据
  716. }
  717. if(id) {
  718. getRecord(id);// 获取任务的操作记录
  719. }
  720. });