leave-todo.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /**
  2. * 请假流程任务办理
  3. */
  4. $(function() {
  5. // 签收
  6. $('.claim').button({
  7. icons: {
  8. primary: 'ui-icon-person'
  9. }
  10. });
  11. // 办理
  12. $('.handle').button({
  13. icons: {
  14. primary: 'ui-icon-comment'
  15. }
  16. }).click(handle);
  17. // 跟踪
  18. $('.trace').click(graphTrace);
  19. });
  20. // 用于保存加载的详细信息
  21. var detail = {};
  22. /**
  23. * 加载详细信息
  24. * @param {Object} id
  25. */
  26. function loadDetail(id, withVars, callback) {
  27. var dialog = this;
  28. $.getJSON(ctx + '/oa/leave/detail/' + id, function(data) {
  29. detail = data;
  30. $.each(data, function(k, v) {
  31. // 格式化日期
  32. if (k == 'applyTime' || k == 'startTime' || k == 'endTime') {
  33. $('.view-info td[name=' + k + ']', dialog).text(new Date(v).format('yyyy-MM-dd hh:mm'));
  34. } else {
  35. $('.view-info td[name=' + k + ']', dialog).text(v);
  36. }
  37. });
  38. if ($.isFunction(callback)) {
  39. callback(data);
  40. }
  41. });
  42. }
  43. /**
  44. * 加载详细信息,同时读取流程任务变量
  45. * @param {Object} id
  46. */
  47. function loadDetailWithTaskVars(leaveId, taskId, callback) {
  48. var dialog = this;
  49. $.getJSON(ctx + '/oa/leave/detail-with-vars/' + leaveId + "/" + taskId, function(data) {
  50. detail = data;
  51. $.each(data, function(k, v) {
  52. // 格式化日期
  53. if (k == 'applyTime' || k == 'startTime' || k == 'endTime') {
  54. $('.view-info td[name=' + k + ']', dialog).text(new Date(v).format('yyyy-MM-dd hh:mm'));
  55. } else {
  56. $('.view-info td[name=' + k + ']', dialog).text(v);
  57. }
  58. });
  59. if ($.isFunction(callback)) {
  60. callback(data);
  61. }
  62. });
  63. }
  64. /**
  65. * 完成任务
  66. * @param {Object} taskId
  67. */
  68. function complete(taskId, variables) {
  69. var dialog = this;
  70. // 转换JSON为字符串
  71. var keys = "", values = "", types = "";
  72. if (variables) {
  73. $.each(variables, function() {
  74. if (keys != "") {
  75. keys += ",";
  76. values += ",";
  77. types += ",";
  78. }
  79. keys += this.key;
  80. values += this.value;
  81. types += this.type;
  82. });
  83. }
  84. $.blockUI({
  85. message: '<h2><img src="' + ctx + '/images/ajax/loading.gif" align="absmiddle"/>正在提交请求……</h2>'
  86. });
  87. // 发送任务完成请求
  88. $.post(ctx + '/oa/leave/complete/' + taskId, {
  89. keys: keys,
  90. values: values,
  91. types: types
  92. }, function(resp) {
  93. $.unblockUI();
  94. if (resp == 'success') {
  95. alert('任务完成');
  96. location.reload();
  97. } else {
  98. alert('操作失败!');
  99. }
  100. });
  101. }
  102. /*
  103. * 使用json方式定义每个节点的按钮
  104. * 以及按钮的功能
  105. *
  106. * open:打开对话框的时候需要处理的任务
  107. * btns:对话框显示的按钮
  108. */
  109. var handleOpts = {
  110. deptLeaderAudit: {
  111. width: 300,
  112. height: 300,
  113. open: function(id) {
  114. // 打开对话框的时候读取请假内容
  115. loadDetail.call(this, id);
  116. },
  117. btns: [{
  118. text: '同意',
  119. click: function() {
  120. var taskId = $(this).data('taskId');
  121. // 设置流程变量
  122. complete(taskId, [{
  123. key: 'deptLeaderPass',
  124. value: true,
  125. type: 'B'
  126. }]);
  127. }
  128. }, {
  129. text: '驳回',
  130. click: function() {
  131. var taskId = $(this).data('taskId');
  132. $('<div/>', {
  133. title: '填写驳回理由',
  134. html: "<textarea id='leaderBackReason' style='width: 250px; height: 60px;'></textarea>"
  135. }).dialog({
  136. modal: true,
  137. open: function() {
  138. },
  139. buttons: [{
  140. text: '驳回',
  141. click: function() {
  142. var leaderBackReason = $('#leaderBackReason').val();
  143. if (leaderBackReason == '') {
  144. alert('请输入驳回理由!');
  145. return;
  146. }
  147. // 设置流程变量
  148. complete(taskId, [{
  149. key: 'deptLeaderPass',
  150. value: false,
  151. type: 'B'
  152. }, {
  153. key: 'leaderBackReason',
  154. value: leaderBackReason,
  155. type: 'S'
  156. }]);
  157. }
  158. }, {
  159. text: '取消',
  160. click: function() {
  161. $(this).dialog('close');
  162. $('#deptLeaderAudit').dialog('close');
  163. }
  164. }]
  165. });
  166. }
  167. }, {
  168. text: '取消',
  169. click: function() {
  170. $(this).dialog('close');
  171. }
  172. }]
  173. },
  174. hrAudit: {
  175. width: 300,
  176. height: 300,
  177. open: function(id) {
  178. // 打开对话框的时候读取请假内容
  179. loadDetail.call(this, id);
  180. },
  181. btns: [{
  182. text: '同意',
  183. click: function() {
  184. var taskId = $(this).data('taskId');
  185. // 设置流程变量
  186. complete(taskId, [{
  187. key: 'hrPass',
  188. value: true,
  189. type: 'B'
  190. }]);
  191. }
  192. }, {
  193. text: '驳回',
  194. click: function() {
  195. var taskId = $(this).data('taskId');
  196. $('<div/>', {
  197. title: '填写驳回理由',
  198. html: "<textarea id='hrBackReason' style='width: 250px; height: 60px;'></textarea>"
  199. }).dialog({
  200. modal: true,
  201. buttons: [{
  202. text: '驳回',
  203. click: function() {
  204. var hrBackReason = $('#hrBackReason').val();
  205. if (hrBackReason == '') {
  206. alert('请输入驳回理由!');
  207. return;
  208. }
  209. // 设置流程变量
  210. complete(taskId, [{
  211. key: 'hrPass',
  212. value: false,
  213. type: 'B'
  214. }, {
  215. key: 'hrBackReason',
  216. value: hrBackReason,
  217. type: 'S'
  218. }]);
  219. }
  220. }, {
  221. text: '取消',
  222. click: function() {
  223. $(this).dialog('close');
  224. $('#deptLeaderAudit').dialog('close');
  225. }
  226. }]
  227. });
  228. }
  229. }, {
  230. text: '取消',
  231. click: function() {
  232. $(this).dialog('close');
  233. }
  234. }]
  235. },
  236. modifyApply: {
  237. width: 500,
  238. height: 470,
  239. open: function(id, taskId) {
  240. var dialog = this;
  241. $('#startTime,#endTime', this).datetimepicker({
  242. stepMinute: 5
  243. });
  244. // 打开对话框的时候读取请假内容
  245. loadDetailWithTaskVars.call(this, id, taskId, function(data) {
  246. // 显示驳回理由
  247. $('.info').show().html("<b>领导:</b>" + (data.variables.leaderBackReason || "") + "<br/><b>HR:</b>" + (data.variables.hrBackReason || ""));
  248. // 读取原请假信息
  249. $('#modifyApplyContent #leaveType option[value=' + data.leaveType + ']').attr('selected', true);
  250. $('#modifyApplyContent #startTime').val(new Date(data.startTime).format('yyyy-MM-dd hh:mm'));
  251. $('#modifyApplyContent #endTime').val(new Date(data.endTime).format('yyyy-MM-dd hh:mm'));
  252. $('#modifyApplyContent #reason').val(data.reason);
  253. });
  254. // 切换状态
  255. $("#radio").buttonset().change(function(){
  256. var type = $(':radio[name=reApply]:checked').val();
  257. if (type == 'true') {
  258. $('#modifyApplyContent').show();
  259. } else {
  260. $('#modifyApplyContent').hide();
  261. }
  262. });
  263. },
  264. btns: [{
  265. text: '提交',
  266. click: function() {
  267. var taskId = $(this).data('taskId');
  268. var reApply = $(':radio[name=reApply]:checked').val();
  269. // 提交的时候把变量
  270. complete(taskId, [{
  271. key: 'reApply',
  272. value: reApply,
  273. type: 'B'
  274. }, {
  275. key: 'leaveType',
  276. value: $('#modifyApplyContent #leaveType').val(),
  277. type: 'S'
  278. }, {
  279. key: 'startTime',
  280. value: $('#modifyApplyContent #startTime').val(),
  281. type: 'D'
  282. }, {
  283. key: 'endTime',
  284. value: $('#modifyApplyContent #endTime').val(),
  285. type: 'D'
  286. }, {
  287. key: 'reason',
  288. value: $('#modifyApplyContent #reason').val(),
  289. type: 'S'
  290. }]);
  291. }
  292. },{
  293. text: '取消',
  294. click: function() {
  295. $(this).dialog('close');
  296. }
  297. }]
  298. },
  299. reportBack: {
  300. width: 400,
  301. height: 400,
  302. open: function(id, taskId) {
  303. // 打开对话框的时候读取请假内容
  304. loadDetail.call(this, id, taskId);
  305. $('#realityStartTime,#realityEndTime').datetimepicker({
  306. stepMinute: 5
  307. });
  308. },
  309. btns: [{
  310. text: '提交',
  311. click: function() {
  312. var realityStartTime = $('#realityStartTime').val();
  313. var realityEndTime = $('#realityEndTime').val();
  314. if (realityStartTime == '') {
  315. alert('请选择实际开始时间!');
  316. return;
  317. }
  318. if (realityEndTime == '') {
  319. alert('请选择实际结束时间!');
  320. return;
  321. }
  322. var taskId = $(this).data('taskId');
  323. complete(taskId, [{
  324. key: 'realityStartTime',
  325. value: realityStartTime,
  326. type: 'D'
  327. }, {
  328. key: 'realityEndTime',
  329. value: realityEndTime,
  330. type: 'D'
  331. }]);
  332. }
  333. },{
  334. text: '取消',
  335. click: function() {
  336. $(this).dialog('close');
  337. }
  338. }]
  339. }
  340. };
  341. /**
  342. * 办理流程
  343. */
  344. function handle() {
  345. // 当前节点的英文名称
  346. var tkey = $(this).attr('tkey');
  347. // 当前节点的中文名称
  348. var tname = $(this).attr('tname');
  349. // 请假记录ID
  350. var rowId = $(this).parents('tr').attr('id');
  351. // 任务ID
  352. var taskId = $(this).parents('tr').attr('tid');
  353. // 使用对应的模板
  354. $('#' + tkey).data({
  355. taskId: taskId
  356. }).dialog({
  357. title: '流程办理[' + tname + ']',
  358. modal: true,
  359. width: handleOpts[tkey].width,
  360. height: handleOpts[tkey].height,
  361. open: function() {
  362. handleOpts[tkey].open.call(this, rowId, taskId);
  363. },
  364. buttons: handleOpts[tkey].btns
  365. });
  366. }
  367. Date.prototype.format = function(format) {
  368. var o = {
  369. "M+": this.getMonth() + 1, //month
  370. "d+": this.getDate(), //day
  371. "h+": this.getHours(), //hour
  372. "m+": this.getMinutes(), //minute
  373. "s+": this.getSeconds(), //second
  374. "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
  375. "S": this.getMilliseconds() //millisecond
  376. }
  377. if (/(y+)/.test(format))
  378. format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  379. for (var k in o)
  380. if (new RegExp("(" + k + ")").test(format))
  381. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  382. return format;
  383. }