You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1092 lines
56 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = 'OverTime_Qry',
  4. sEditPrgId = 'OverTime_Upd',
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckFlows: [], HandleFlows: [], OverTimes: [] },
  10. oForm = $('#form_main'),
  11. saCheckOrder_Push = [],
  12. saUsers = [],
  13. sCurAuditFlowId = null,
  14. sCurHandleFlowId = null,
  15. bGoNext = true,
  16. /**
  17. * 獲取當前審核人員
  18. * @param {Object} data 當前審核資料
  19. */
  20. fnGetCurAuditor = function (data) {
  21. var saCheckFlows = $.parseJSON(data.CheckFlows),
  22. saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray(),
  23. bAuditor = false,
  24. bHandle = false,
  25. bAllAudit = false;
  26. if ('B,E'.indexOf(data.Status) > -1) {//只有審核中或者待經辦的資料才可以出現審核區塊
  27. $.each(saNewList, function (idx, _data) {
  28. var sSignedWay = _data.source[0].SignedWay,
  29. iCount = Enumerable.From(_data.source).Where(function (e) { return (e.SignedDecision === 'Y' || e.SignedDecision === 'O'); }).Count(),
  30. sCurAuditor = Enumerable.From(_data.source).ToString(",", "$.SignedId");
  31. if ((('flow1,flow3'.indexOf(sSignedWay) > -1 && iCount === 0) || (sSignedWay === 'flow2' && iCount !== _data.source.length))) {
  32. if (sCurAuditor.indexOf(parent.UserID) > -1) {
  33. var oCurUser = Enumerable.From(_data.source).Where(function (e) { return e.SignedId === parent.UserID; }).First();
  34. if (sSignedWay === 'flow2' && iCount < _data.source.length - 1) {
  35. bGoNext = false;
  36. }
  37. if (!oCurUser.SignedDecision) {
  38. sCurAuditFlowId = oCurUser.FlowId;
  39. bAuditor = true;
  40. }
  41. }
  42. if (!bAllAudit) {//只要有需要審核的人,就不要檢核是否簽辦
  43. bAllAudit = true;
  44. }
  45. return false;
  46. }
  47. });
  48. if (!bAuditor && !bAllAudit) {//當沒有要審核的人員並且審核全部完成時才會檢核簽辦
  49. var saHandleFlows = $.parseJSON(data.HandleFlows),
  50. sCurAuditor = saHandleFlows[0].SignedId;
  51. if (saHandleFlows[0].SignedDecision !== 'Y' && sCurAuditor === parent.UserID) {
  52. sCurHandleFlowId = saHandleFlows[0].FlowId
  53. bHandle = true;
  54. }
  55. }
  56. }
  57. return {
  58. IsAuditor: bAuditor,
  59. IsHandler: bHandle
  60. };
  61. },
  62. /**
  63. * 註冊加簽事件
  64. * @param {Number} _grididx當前Gird 序號
  65. */
  66. fnRegisterAddFlows = function (_grididx) {
  67. $('.flowlink' + _grididx).on('click', function () {
  68. var oOption = {};
  69. oOption.SignedWay = $(this).data('id');
  70. oOption.Callback = function (data) {
  71. if (data.Users.length > 0) {
  72. var oFlow = {};
  73. if (data.FlowType === 'flow1') {
  74. $.each(data.Users, function (idx, user) {
  75. oFlow = {};
  76. oFlow.id = guid();
  77. oFlow.Order = saCheckOrder_Push.length + 1;
  78. oFlow.SignedWay = data.FlowType;
  79. oFlow.SignedMember = [{
  80. id: user.id,
  81. name: user.name,
  82. deptname: user.deptname,
  83. jobname: user.jobname
  84. }];
  85. saCheckOrder_Push.push(oFlow);
  86. });
  87. }
  88. else {
  89. var saSignedMembers = [];
  90. $.each(data.Users, function (idx, user) {
  91. saSignedMembers.push({
  92. id: user.id,
  93. name: user.name,
  94. deptname: user.deptname,
  95. jobname: user.jobname
  96. });
  97. });
  98. oFlow.id = guid();
  99. oFlow.Order = saCheckOrder_Push.length + 1;
  100. oFlow.SignedWay = data.FlowType;
  101. oFlow.SignedMember = saSignedMembers;
  102. saCheckOrder_Push.push(oFlow);
  103. }
  104. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  105. $("#jsGrid" + _grididx).jsGrid("loadData");
  106. }
  107. };
  108. oPenUserListPop(oOption);
  109. });
  110. },
  111. /**
  112. * 獲取資料
  113. */
  114. fnGet = function () {
  115. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  116. {
  117. Guid: sDataId
  118. },
  119. function (res) {
  120. if (res.RESULT) {
  121. var oRes = res.DATA.rel,
  122. saFlowsText = [],
  123. sStatus = '';
  124. if (oRes.Status === 'C-O') {
  125. sStatus = '(' + i18next.t("common.HasReEdited") + ')';// ╠common.HasReEdited⇒已抽單╣
  126. }
  127. else if (oRes.Status === 'D-O') {
  128. sStatus = '(' + i18next.t("common.HasReturned") + ')';// ╠common.HasReturned⇒已退件╣
  129. }
  130. else if (oRes.Status === 'X') {
  131. sStatus = '(' + i18next.t("common.HasVoid") + ')';// ╠common.HasVoid⇒已作廢╣
  132. }
  133. //根據帳單狀態,移除抽單按鈕(扣除已經辦只能admin抽單)
  134. fnCheckReEdit(oRes.Status, oRes.AskTheDummy);
  135. if (oRes.AskTheDummy !== parent.UserID) {
  136. $('#Toolbar_Copy').remove();
  137. }
  138. if ('B,Y'.indexOf(oRes.Status) === -1) {
  139. $('#Toolbar_Void').remove();
  140. }
  141. var oCheck = fnGetCurAuditor(oRes);
  142. if (oCheck.IsAuditor) {
  143. $('#IsAuditor').show();
  144. }
  145. if (oCheck.IsHandler) {
  146. $('#IsHandler').show();
  147. }
  148. if (oCheck.IsAuditor || oCheck.IsHandler) {
  149. $('.submitdecision').click(function () {
  150. var sSubmitAction = $(this).data('id');
  151. fnSubmitDecision(sSubmitAction);
  152. });
  153. }
  154. if (oRes.VoidReason) {
  155. $('#VoidReason').text(oRes.VoidReason);
  156. $('.VoidReason').show();
  157. }
  158. if (oRes.CrosssignTurn === 'N') {
  159. $('.crosssignturn').remove();
  160. }
  161. oCurData = oRes;
  162. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  163. oCurData.CheckFlows = $.parseJSON(oCurData.CheckFlows);
  164. oCurData.HandleFlows = $.parseJSON(oCurData.HandleFlows);
  165. oCurData.OverTimes = $.parseJSON(oCurData.OverTimes);
  166. setFormVal(oForm, oRes);
  167. $('.AskTheDummy').text(oCurData.AskTheDummyName + '(' + oCurData.AskTheDummy + ') ' + oCurData.DeptName);
  168. $('.eip-note').text(oCurData.KeyNote);
  169. $('#status').text(sStatus);
  170. $('#Applicant,#AskTheDummy').text(oCurData.DeptName + ' ' + oCurData.AskTheDummyName);
  171. $('#Handle_Person').text(oCurData.Handle_PersonName);// ╠common.Important_1⇒普通╣ ╠common.Important_2⇒重要╣ ╠common.Important_3⇒很重要╣
  172. $('#Important').text(oCurData.Important === '1' ? i18next.t("common.Important_1") : oCurData.Important === '2' ? i18next.t("common.Important_2") : i18next.t("common.Important_3"));
  173. $('#SignedNumber').text(oCurData.SignedNumber);
  174. $.each(oCurData.CheckOrder, function (idx, order) {
  175. var sFlowType = i18next.t('common.' + order.SignedWay);
  176. if (order.SignedWay !== 'flow1') {
  177. saFlowsText.push(sFlowType + '(' + Enumerable.From(order.SignedMember).ToString(",", "$.name") + ')');
  178. }
  179. else {
  180. saFlowsText.push(Enumerable.From(order.SignedMember).ToString(",", "$.name"));
  181. }
  182. });
  183. $('#Recipient').text(saFlowsText.join('->'));
  184. fnGetFiles($('#AdditionalFiles'), oCurData.Guid, oCurData.RelationId, oCurData.ExFeild1, sProgramId);//加載附件
  185. fnUpload();//初始化上傳控件(審批與簽辦)
  186. fnRead();//如果是被通知的人,則修改為已閱讀狀態
  187. $("#jsGrid").jsGrid("loadData");
  188. $("#jsGrid1").jsGrid("loadData");
  189. $("#jsGrid2").jsGrid("loadData");
  190. $('[name="SignedDecision"]').click(function () {
  191. if (this.value === 'O') {
  192. $('#addotheraudit').slideDown();
  193. }
  194. else {
  195. $('#addotheraudit').slideUp();
  196. }
  197. });
  198. $('[name="HandleDecision"]').click(function () {
  199. if (this.value === 'O') {
  200. $('#addotherhandle').slideDown();
  201. }
  202. else {
  203. $('#addotherhandle').slideUp();
  204. }
  205. });
  206. }
  207. });
  208. },
  209. /**
  210. * 複製
  211. */
  212. fnCopy = function () {
  213. var data = oCurData;
  214. data = packParams(data);
  215. if (data.Status === 'D-O') {
  216. data.RelationId = data.Guid;
  217. }
  218. else {
  219. delete data.RelationId;
  220. }
  221. data.OrgID = parent.OrgID;
  222. data.Guid = guid();
  223. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|OT|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  224. data.CheckFlows = fnCheckFlows(data, false, true, saUsers);
  225. data.HandleFlows = fnHandleFlows(data, saUsers);
  226. data.CheckOrder = JSON.stringify(data.CheckOrder);
  227. data.OverTimes = JSON.stringify(data.OverTimes);
  228. data.Status = 'A';
  229. data.IsHandled = 'N';
  230. data.Inspectors = '';
  231. data.Reminders = '';
  232. data.VoidReason = '';
  233. data.Flows_Lock = data.Flows_Lock || 'N';
  234. data.Handle_Lock = data.Handle_Lock || 'N';
  235. delete data.RowIndex;
  236. delete data.AskTheDummyName;
  237. delete data.Handle_PersonName;
  238. delete data.DeptName;
  239. delete data.CreateUserName;
  240. delete data.ModifyUserName;
  241. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  242. Params: {
  243. overtime: data
  244. }
  245. }, function (res) {
  246. if (res.d > 0) {
  247. showMsgAndGo(i18next.t("message.Copy_Success"), sEditPrgId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Copy_Success⇒複製成功╣
  248. }
  249. else {
  250. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  251. }
  252. }, function () {
  253. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  254. });
  255. },
  256. /**
  257. * 資料作廢
  258. */
  259. fnVoid = function () {
  260. layer.open({
  261. type: 1,
  262. title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
  263. shade: 0.75,
  264. maxmin: true, //开启最大化最小化按钮
  265. area: ['500px', '250px'],
  266. content: '<div class="pop-box">\
  267. <textarea name="VoidContent" id="VoidContent" style="min-width:300px;" class="form-control" rows="5" cols="20"></textarea>\
  268. </div>',
  269. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  270. success: function (layero, index) {
  271. },
  272. yes: function (index, layero) {
  273. var data = {
  274. Status: 'X',
  275. VoidReason: $('#VoidContent').val()
  276. };
  277. if (!$('#VoidContent').val()) {
  278. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  279. return false;
  280. }
  281. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  282. Params: {
  283. overtime: {
  284. values: data,
  285. keys: { Guid: sDataId }
  286. }
  287. }
  288. }, function (res) {
  289. if (res.d > 0) {
  290. DelTask(sDataId);
  291. showMsgAndGo(i18next.t('message.Void_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  292. }
  293. else {
  294. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  295. }
  296. });
  297. layer.close(index);
  298. }
  299. });
  300. },
  301. /**
  302. * 複製
  303. */
  304. fnRead = function () {
  305. var bToUpd = false;
  306. $.each(oCurData.CheckFlows, function (idx, _data) {
  307. if (_data.SignedId === parent.UserID && _data.SignedWay === 'flow4' && _data.SignedDecision === 'T') {
  308. _data.SignedDecision = 'R';
  309. bToUpd = true;
  310. return false;
  311. }
  312. });
  313. if (bToUpd) {
  314. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  315. Params: {
  316. overtime: {
  317. values: { CheckFlows: JSON.stringify(oCurData.CheckFlows) },
  318. keys: { Guid: sDataId }
  319. }
  320. }
  321. });
  322. }
  323. },
  324. /**
  325. * 抽單
  326. */
  327. fnReEdit = function () {
  328. var data = {};
  329. data.Status = 'C-O';
  330. data = packParams(data, 'upd');
  331. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  332. Params: {
  333. overtime: {
  334. values: data,
  335. keys: { Guid: sDataId }
  336. }
  337. }
  338. }, function (res) {
  339. if (res.d > 0) {
  340. showMsg(i18next.t("message.ReEdit_Success"), 'success'); // ╠message.ReEdit_Success⇒抽單成功╣
  341. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  342. Params: {
  343. task: {
  344. values: { Status: 'O' },
  345. keys: { SourceID: sDataId }
  346. }
  347. }
  348. });
  349. fnGet();
  350. }
  351. else {
  352. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  353. }
  354. }, function () {
  355. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  356. });
  357. },
  358. /**
  359. * 提交決定
  360. * @param {String} action 簽核 or 經辦
  361. */
  362. fnSubmitDecision = function (action) {
  363. var data = getFormSerialize(oForm),
  364. saNewCheckFlows = clone(oCurData.CheckFlows),
  365. saNewHandleFlows = clone(oCurData.HandleFlows),
  366. saNewCheckOrderPush = clone(saCheckOrder_Push),
  367. saAdds = [],//加簽核順序
  368. saNextUsers = [],//下組簽核人員
  369. saTipsUsers = [],//需要通知的人員
  370. saNextSignedWays = [],//下組需要處理的動作
  371. iCurOder = 0,//當前順序
  372. sHandlePerson = "";//經辦人
  373. if (action === 'Signed') {
  374. if (data.SignedDecision === 'N' && !data.SignedOpinion) {
  375. showMsg(i18next.t("message.SignedOpinion_required")); // ╠message.SignedOpinion_required⇒請填寫簽核意見╣
  376. return false;
  377. }
  378. else if (data.SignedDecision === 'O' && saCheckOrder_Push.length === 0) {
  379. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  380. return false;
  381. }
  382. var oCurFlow = Enumerable.From(oCurData.CheckFlows).Where(function (e) { return e.FlowId == sCurAuditFlowId; }).First(),
  383. oNewCurFlow = clone(oCurFlow);
  384. iCurOder = oCurFlow.Order;
  385. $.each(saNewCheckOrderPush, function (idx, _push) {
  386. _push.Order = idx + 1 + iCurOder;
  387. });
  388. $.each(saNewCheckFlows, function (idx, _flow) {
  389. if (sCurAuditFlowId === _flow.FlowId) {
  390. _flow.SignedDecision = data.SignedDecision;
  391. _flow.SignedOpinion = data.SignedOpinion;
  392. _flow.SignedDate = newDate();
  393. if (data.SignedDecision === 'O') {
  394. _flow.SignedPush = saCheckOrder_Push;
  395. }
  396. }
  397. if (data.SignedDecision === 'O' && _flow.Order > iCurOder) {
  398. _flow.Order = _flow.Order + saNewCheckOrderPush.length;
  399. if (data.NoreTurn) {//如果再回傳給自己的話排序再增加一個值
  400. _flow.Order++;
  401. }
  402. else {//如果加簽核流程最後一個是通知,並且原流程下一個也是通知的話就合併新舊排序
  403. if (saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay === 'flow4' && saNewCheckFlows[iCurOder + 1].SignedWay === saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay) {
  404. _flow.Order--;
  405. }
  406. }
  407. }
  408. });
  409. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  410. if (data.SignedDecision === 'O' && data.NoreTurn) {
  411. oNewCurFlow.Order = oNewCurFlow.Order + saNewCheckOrderPush.length + 1;
  412. oNewCurFlow.FlowId = guid();
  413. saAdds.push(oNewCurFlow);
  414. }
  415. }
  416. else {
  417. if (data.HandleDecision === 'O' && saCheckOrder_Push.length === 0) {
  418. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  419. return false;
  420. }
  421. iCurOder = saNewCheckFlows[saNewCheckFlows.length - 1].Order;//如果是签辦的話當前順序就是原本流程的最大順序
  422. $.each(saNewHandleFlows, function (idx, _flow) {
  423. if (sCurHandleFlowId === _flow.FlowId) {
  424. _flow.SignedDecision = data.HandleDecision;
  425. _flow.SignedOpinion = data.HnadleOpinion;
  426. _flow.SignedDate = newDate();
  427. if (data.HandleDecision === 'O') {
  428. _flow.SignedPush = saCheckOrder_Push;
  429. }
  430. if (data.HandleDecision === 'Y') {
  431. _flow.SignedPush = null;
  432. }
  433. }
  434. });
  435. if (data.HandleDecision === 'O') {
  436. $.each(saNewCheckOrderPush, function (idx, _push) {
  437. _push.Order = idx + saNewCheckFlows[saNewCheckFlows.length - 1].Order + 1;
  438. });
  439. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  440. }
  441. }
  442. saNewCheckFlows = saNewCheckFlows.concat(saAdds);
  443. saNewCheckFlows = Enumerable.From(saNewCheckFlows).OrderBy("$.Order").ToArray();
  444. var _List = Enumerable.From(saNewCheckFlows).GroupBy("$.Order").ToArray();
  445. saNewCheckFlows = [];
  446. $.each(_List, function (idx, _list) {
  447. //找到要通知的人
  448. var sSignedWay = _list.source[0].SignedWay;
  449. var LastOne = iCurOder >= _List.length
  450. if (idx === iCurOder && !LastOne) {
  451. switch (sSignedWay) {
  452. case "flow1":
  453. case "flow2":
  454. case "flow3":
  455. {
  456. saNextUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  457. saNextSignedWays.push(sSignedWay);
  458. }
  459. break;
  460. case "flow4":
  461. { //不能算通知到
  462. $.each(_list.source, function (i, _source) {
  463. _source.SignedDecision = 'T';
  464. _source.SignedDate = newDate();
  465. });
  466. saTipsUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  467. saNextSignedWays.push(sSignedWay);
  468. ++iCurOder
  469. }
  470. break;
  471. default:
  472. break;
  473. }
  474. }
  475. saNewCheckFlows = saNewCheckFlows.concat(_list.source);
  476. });
  477. //Flow => Handle => END
  478. if (action != 'Handle') {
  479. var CheckNextUser = saNextUsers.length === 0;
  480. if (CheckNextUser && iCurOder === _List.length) {
  481. sHandlePerson = saNewHandleFlows[0].SignedId;
  482. saNextSignedWays.push("flow5");
  483. }
  484. }
  485. g_api.ConnectLite(sEditPrgId, 'OverTimeAudit', {
  486. Guid: oCurData.Guid,
  487. Action: action,
  488. GoNext: bGoNext ? 'Y' : 'N',
  489. HandlePerson: sHandlePerson,
  490. NextSignedWays: JSON.stringify(saNextSignedWays),
  491. NextUsers: JSON.stringify(saNextUsers),
  492. TipsUsers: JSON.stringify(saTipsUsers),
  493. CheckFlows: JSON.stringify(saNewCheckFlows),
  494. HandleFlows: JSON.stringify(saNewHandleFlows),
  495. SignedDecision: data.SignedDecision,
  496. HandleDecision: data.HandleDecision
  497. }, function (res) {
  498. if (res.RESULT) {
  499. showMsgAndGo(i18next.t('message.' + action + '_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  500. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  501. }
  502. else {
  503. showMsg(i18next.t('message.' + action + '_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  504. }
  505. }, function () {
  506. showMsg(i18next.t('message.' + action + '_Failed'), 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  507. });
  508. },
  509. /**
  510. * 上傳附件
  511. * @param {Array} files 上傳的文件
  512. */
  513. fnUpload = function (files) {
  514. var option = {};
  515. option.input = $('#fileInput1');
  516. option.theme = 'dragdropbox';
  517. option.folder = 'OverTime';
  518. option.type = 'list';
  519. option.parentid = sCurAuditFlowId;
  520. if (files) {
  521. option.files = files;
  522. }
  523. fnUploadRegister(option);
  524. option.input = $('#fileInput2');
  525. option.parentid = sCurHandleFlowId;
  526. fnUploadRegister(option);
  527. },
  528. /**
  529. * ToolBar 按鈕事件 function
  530. * @param {Object}inst 按鈕物件對象
  531. * @param {Object} e 事件對象
  532. */
  533. fnButtonHandler = function (inst, e) {
  534. var sId = inst.id;
  535. switch (sId) {
  536. case "Toolbar_Qry":
  537. break;
  538. case "Toolbar_Save":
  539. break;
  540. case "Toolbar_ReAdd":
  541. break;
  542. case "Toolbar_Clear":
  543. clearPageVal();
  544. break;
  545. case "Toolbar_Leave":
  546. pageLeave();
  547. break;
  548. case "Toolbar_Add":
  549. break;
  550. case "Toolbar_Upd":
  551. break;
  552. case "Toolbar_Copy":
  553. fnRefreshFlowsThenCopy(oCurData, fnCopy);
  554. break;
  555. case "Toolbar_Void":
  556. fnVoid();
  557. break;
  558. case "Toolbar_ReEdit":
  559. // ╠message.CheckReEdit⇒確定要抽單嗎?╣ ╠common.Tips⇒提示╣
  560. layer.confirm(i18next.t('message.CheckReEdit'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  561. fnReEdit();
  562. layer.close(index);
  563. });
  564. break;
  565. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  566. break;
  567. case "Toolbar_Print":
  568. fnPrePrint($(".panel-info"));
  569. break;
  570. default:
  571. alert("No handle '" + sId + "'");
  572. break;
  573. }
  574. },
  575. /**
  576. * 初始化 function
  577. */
  578. init = function () {
  579. var saCusBtns = null;
  580. if (sAction === 'Upd') {
  581. saCusBtns = [
  582. {
  583. id: 'Toolbar_ReEdit',
  584. value: 'common.ReEdit'// ╠common.ReEdit⇒抽單╣
  585. },
  586. {
  587. id: 'Toolbar_Copy',
  588. value: 'common.Toolbar_Copy'// ╠common.Toolbar_Copy⇒複製╣
  589. }];
  590. }
  591. commonInit({
  592. PrgId: sProgramId,
  593. ButtonHandler: fnButtonHandler,
  594. Buttons: saCusBtns,
  595. GoTop: true
  596. });
  597. fnSetUserDrop([
  598. {
  599. CallBack: function (data) {
  600. saUsers = data;
  601. }
  602. }
  603. ]);
  604. fnGet();
  605. $("#jsGrid").jsGrid({
  606. width: "100%",
  607. height: "auto",
  608. autoload: true,
  609. filtering: false,
  610. pageLoading: true,
  611. pageIndex: 1,
  612. pageSize: 10000,
  613. fields: [
  614. {
  615. name: "Index", title: '#', width: 20, align: "center"
  616. },
  617. {
  618. name: "EmployeeCode", title: 'common.EmployeeCode', width: 70, type: "text"
  619. },
  620. {
  621. name: "EmployeeName", title: 'common.EmployeeName', width: 70, type: "text"
  622. },
  623. {
  624. name: "OvertimeClassName", title: 'common.OvertimeClass', width: 60, type: "text"
  625. },
  626. {
  627. name: "AttendanceDate", title: 'common.AttendanceDate', width: 70, align: "center", type: "text"
  628. },
  629. {
  630. name: "StartDate", title: 'common.StartDate', width: 70, type: "text", align: "center"
  631. },
  632. {
  633. name: "StartTime", title: 'common.StartTime', width: 60, type: "text", align: "center"
  634. },
  635. {
  636. name: "EndDate", title: 'common.EndDate', width: 70, type: "text", align: "center"
  637. },
  638. {
  639. name: "EndTime", title: 'common.EndTime', width: 60, type: "text", align: "center"
  640. },
  641. {
  642. name: "OvertimeHours", title: 'common.OvertimeHours', width: 60, align: "center", type: "text"
  643. },
  644. {
  645. name: "TakeTimeOffHours", title: 'common.TakeTimeOffHours', width: 60, align: "center", type: "text"
  646. },
  647. {
  648. name: "PrjCode", title: 'common.PrjCode', width: 70, type: "text",
  649. itemTemplate: function (val, item) {
  650. return item.PrjCode + (!item.PrjName ? '' : '(' + item.PrjName + ')');
  651. }
  652. },
  653. {
  654. name: "Reason", title: 'common.LeaveReason', width: 70, type: "text"
  655. }
  656. ],
  657. controller: {
  658. loadData: function (args) {
  659. return {
  660. data: oCurData.OverTimes,
  661. itemsCount: oCurData.OverTimes.length //data.length
  662. };
  663. }
  664. }
  665. });
  666. $("#jsGrid1").jsGrid({
  667. width: "100%",
  668. height: "auto",
  669. autoload: true,
  670. pageLoading: true,
  671. pageIndex: 1,
  672. pageSize: 10000,
  673. rowClass: function (item, itemIndex) {
  674. var sRowClass = '';
  675. if (oCurData.CheckFlows.length !== itemIndex + 1) {
  676. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  677. }
  678. else {
  679. sRowClass = 'last-cell';
  680. }
  681. return sRowClass;
  682. },
  683. fields: [
  684. {
  685. type: "Icon", width: 50, align: "center",
  686. itemTemplate: function (val, item) {
  687. var oIcon = {
  688. flow2: '<img src="../../images/flow2_View.gif">',
  689. flow3: '<img src="../../images/flow3_View.gif">',
  690. flow4: '<img src="../../images/flow4.gif">'
  691. };
  692. return item.Icon ? oIcon[item.SignedWay] || '' : '';
  693. }
  694. },
  695. {
  696. name: "Order", title: 'common.Order', width: 50, align: "center",
  697. itemTemplate: function (val, item) {
  698. return val < 10 ? '0' + val : val;
  699. }
  700. },
  701. {
  702. name: "SignedMember", title: 'common.SignedMember', width: 150,
  703. itemTemplate: function (val, item) {
  704. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  705. }
  706. },
  707. {
  708. name: "SignedDecision", title: 'common.Decision', width: 100,
  709. itemTemplate: function (val, item) {
  710. var sVal = val;
  711. if (val === 'Y') {
  712. sVal = i18next.t("common.Agree");// ╠common.Agree⇒同意╣
  713. }
  714. else if (val === 'N') {
  715. sVal = i18next.t("common.NotAgree");// ╠common.NotAgree⇒不同意╣
  716. }
  717. else if (val === 'O') {
  718. sVal = i18next.t("common.AddOther");// ╠common.AddOther⇒先加簽╣
  719. }
  720. else if (val === 'T') {
  721. sVal = i18next.t("common.HasNotice");// ╠common.HasNotice⇒已通知╣
  722. }
  723. else if (val === 'R') {
  724. sVal = i18next.t("common.HasRead");// ╠common.HasRead⇒已閱讀╣
  725. }
  726. return $('<a>', { html: sVal });
  727. }
  728. },
  729. {
  730. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  731. itemTemplate: function (val, item) {
  732. var saVal = [],
  733. oDiv = $('<div>');
  734. if (item.SignedPush) {
  735. var saFlowsPush = item.SignedPush,
  736. saFlowsPushText = [],
  737. sFlowsPushText = '';
  738. $.each(saFlowsPush, function (idx, flow) {
  739. var sFlowType = i18next.t('common.' + flow.SignedWay);
  740. if (flow.SignedWay !== 'flow1') {
  741. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  742. }
  743. else {
  744. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  745. }
  746. });
  747. sFlowsPushText = saFlowsPushText.join(' → ');
  748. saVal.push($('<a>', { html: sFlowsPushText }));
  749. saVal.push('<br />');
  750. }
  751. if (val) {
  752. saVal.push(val);
  753. saVal.push('<br />');
  754. }
  755. fnGetFiles(oDiv.append(saVal), item.FlowId);
  756. return oDiv;
  757. }
  758. },
  759. {
  760. name: "SignedDate", title: 'common.SignedDate', width: 120,
  761. itemTemplate: function (val, item) {
  762. return val;
  763. }
  764. }
  765. ],
  766. controller: {
  767. loadData: function (args) {
  768. return {
  769. data: oCurData.CheckFlows,
  770. itemsCount: oCurData.CheckFlows.length //data.length
  771. };
  772. }
  773. }
  774. });
  775. $("#jsGrid2").jsGrid({
  776. width: "100%",
  777. height: "auto",
  778. autoload: true,
  779. pageLoading: true,
  780. pageIndex: 1,
  781. pageSize: 10000,
  782. rowClass: function (item, itemIndex) {
  783. var sRowClass = '';
  784. if (oCurData.HandleFlows.length !== itemIndex + 1) {
  785. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  786. }
  787. else {
  788. sRowClass = 'last-cell';
  789. }
  790. return sRowClass;
  791. },
  792. fields: [
  793. {
  794. name: "SignedMember", title: 'common.HandleMembers', width: 150,
  795. itemTemplate: function (val, item) {
  796. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  797. }
  798. },
  799. {
  800. name: "SignedDecision", title: 'common.Status', width: 100,
  801. itemTemplate: function (val, item) {
  802. var sVal = val;
  803. if (val === 'Y') {
  804. sVal = i18next.t("common.Hashandle");// ╠common.Hashandle⇒已經辦╣
  805. }
  806. else if (val === 'N') {
  807. sVal = i18next.t("common.Nothandle");// ╠common.Nothandle⇒未經辦╣
  808. }
  809. else if (val === 'O') {
  810. sVal = i18next.t("common.AddOtherAudit");// ╠common.Nothandle⇒未處理╣
  811. }
  812. return $('<a>', { html: sVal });
  813. }
  814. },
  815. {
  816. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  817. itemTemplate: function (val, item) {
  818. var saVal = [],
  819. oDiv = $('<div>');
  820. if (item.SignedPush) {
  821. var saFlowsPush = item.SignedPush,
  822. saFlowsPushText = [],
  823. sFlowsPushText = '';
  824. $.each(saFlowsPush, function (idx, flow) {
  825. var sFlowType = i18next.t('common.' + flow.SignedWay);
  826. if (flow.SignedWay !== 'flow1') {
  827. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  828. }
  829. else {
  830. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  831. }
  832. });
  833. sFlowsPushText = saFlowsPushText.join(' → ');
  834. saVal.push($('<a>', { html: sFlowsPushText }));
  835. saVal.push('<br />');
  836. }
  837. if (val) {
  838. saVal.push(val);
  839. saVal.push('<br />');
  840. }
  841. fnGetFiles(oDiv.append(saVal), item.FlowId);
  842. return oDiv;
  843. }
  844. },
  845. {
  846. name: "SignedDate", title: 'common.HandleDate', width: 120,
  847. itemTemplate: function (val, item) {
  848. return val;
  849. }
  850. }
  851. ],
  852. controller: {
  853. loadData: function (args) {
  854. return {
  855. data: oCurData.HandleFlows,
  856. itemsCount: oCurData.HandleFlows.length //data.length
  857. };
  858. }
  859. }
  860. });
  861. $.each([3, 4], function (idx, _grididx) {
  862. fnRegisterAddFlows(_grididx);
  863. $("#jsGrid" + _grididx).jsGrid({
  864. width: "100%",
  865. height: "auto",
  866. autoload: true,
  867. filtering: false,
  868. pageLoading: true,
  869. pageIndex: 1,
  870. pageSize: 10000,
  871. fields: [
  872. {
  873. name: "Order", title: 'common.Order', width: 50, align: "center",
  874. itemTemplate: function (val, item) {
  875. return val < 10 ? '0' + val : val;
  876. }
  877. },
  878. {
  879. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  880. itemTemplate: function (val, item) {
  881. return i18next.t('common.' + val);
  882. }
  883. },
  884. {
  885. type: "Icon", width: 50, align: "center",
  886. itemTemplate: function (val, item) {
  887. var oIcon = {
  888. flow1: '<img src="../../images/flow_check.gif">',
  889. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  890. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  891. flow4: '<img src="../../images/flow4.gif">'
  892. },
  893. sIcon = oIcon[item.SignedWay];
  894. if (item.Order !== saCheckOrder_Push.length) {
  895. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  896. }
  897. return sIcon;
  898. }
  899. },
  900. {
  901. name: "SignedMember", title: 'common.SignedMember', width: 500,
  902. itemTemplate: function (val, item) {
  903. return Enumerable.From(val).ToString(",", "$.name");
  904. }
  905. },
  906. {
  907. type: "control", title: 'common.Action', width: 200,
  908. itemTemplate: function (val, item) {
  909. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  910. class: 'glyphicon glyphicon-pencil',
  911. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  912. click: function () {
  913. var oOption = {};
  914. oOption.SignedWay = item.SignedWay;
  915. oOption.SignedMember = item.SignedMember;
  916. oOption.Callback = function (data) {
  917. if (data.Users.length > 0) {
  918. var oFlow = {};
  919. if (data.FlowType === 'flow1') {
  920. $.each(data.Users, function (idx, user) {
  921. var oFlow = {};
  922. oFlow.id = guid();
  923. oFlow.Order = item.Order + idx;
  924. oFlow.SignedWay = data.FlowType;
  925. oFlow.SignedMember = [{
  926. id: user.id,
  927. name: user.name,
  928. deptname: user.deptname,
  929. jobname: user.jobname
  930. }];
  931. saCheckOrder_Push.insert(item.Order + idx, oFlow);
  932. });
  933. }
  934. else {
  935. var saSignedMembers = [];
  936. $.each(data.Users, function (idx, user) {
  937. saSignedMembers.push({
  938. id: user.id,
  939. name: user.name,
  940. deptname: user.deptname,
  941. jobname: user.jobname
  942. });
  943. });
  944. oFlow.id = guid();
  945. oFlow.Order = item.Order;
  946. oFlow.SignedWay = data.FlowType;
  947. oFlow.SignedMember = saSignedMembers;
  948. saCheckOrder_Push.insert(item.Order, oFlow);
  949. }
  950. var iOrder = 1;
  951. $.each(saCheckOrder_Push, function (idx, _data) {
  952. if (item.id !== _data.id) {
  953. _data.Order = iOrder;
  954. iOrder++;
  955. }
  956. });
  957. saCheckOrder_Push = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  958. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  959. $("#jsGrid" + _grididx).jsGrid("loadData");
  960. }
  961. };
  962. oPenUserListPop(oOption);
  963. }
  964. })),
  965. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  966. class: 'glyphicon glyphicon-trash',
  967. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  968. click: function () {
  969. var saNewList = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  970. saCheckOrder_Push = saNewList;
  971. $.each(saCheckOrder_Push, function (idx, _data) {
  972. _data.Order = idx + 1;
  973. });
  974. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  975. $("#jsGrid" + _grididx).jsGrid("loadData");
  976. }
  977. }))];
  978. if (saCheckOrder_Push.length !== item.Order) {
  979. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  980. class: 'glyphicon glyphicon-arrow-down',
  981. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  982. click: function () {
  983. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  984. iOrder = sOrder * 1;
  985. $.each(saCheckOrder_Push, function (idx, _data) {
  986. if (iOrder === _data.Order) {
  987. _data.Order++;
  988. }
  989. else if ((iOrder + 1) === _data.Order) {
  990. _data.Order--;
  991. }
  992. });
  993. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  994. $("#jsGrid" + _grididx).jsGrid("loadData");
  995. }
  996. })));
  997. }
  998. else {
  999. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  1000. }
  1001. if (1 !== item.Order) {
  1002. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1003. class: 'glyphicon glyphicon-arrow-up',
  1004. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  1005. click: function () {
  1006. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1007. iOrder = sOrder * 1;
  1008. $.each(saCheckOrder_Push, function (idx, _data) {
  1009. if (iOrder === _data.Order) {
  1010. _data.Order--;
  1011. }
  1012. else if ((iOrder - 1) === _data.Order) {
  1013. _data.Order++;
  1014. }
  1015. });
  1016. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1017. $("#jsGrid" + _grididx).jsGrid("loadData");
  1018. }
  1019. })));
  1020. }
  1021. return oBtns;
  1022. }
  1023. }
  1024. ],
  1025. controller: {
  1026. loadData: function (args) {
  1027. return {
  1028. data: saCheckOrder_Push,
  1029. itemsCount: saCheckOrder_Push.length //data.length
  1030. };
  1031. }
  1032. }
  1033. });
  1034. });
  1035. };
  1036. init();
  1037. };
  1038. require(['base', 'jsgrid', 'jqprint', 'filer', 'common_eip', 'util'], fnPageInit);