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.

1043 lines
54 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = 'BusinessTravel_Qry',
  4. sEditPrgId = 'BusinessTravel_Upd',
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckFlows: [], HandleFlows: [] },
  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 saUsers = [];
  90. $.each(data.Users, function (idx, user) {
  91. saUsers.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 = saUsers;
  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. setFormVal(oForm, oRes);
  166. $('#StartDate').val(newDate(oCurData.StartDate));
  167. $('#EndDate').val(newDate(oCurData.EndDate));
  168. $('.AskTheDummy').text(oCurData.AskTheDummyName + '(' + oCurData.AskTheDummy + ') ' + oCurData.DeptName);
  169. $('.eip-note').text(oCurData.KeyNote);
  170. $('#status').text(sStatus);
  171. $('#Applicant,#AskTheDummy').text(oCurData.DeptName + ' ' + oCurData.AskTheDummyName);
  172. $('#Handle_Person').text(oCurData.Handle_PersonName);// ╠common.Important_1⇒普通╣ ╠common.Important_2⇒重要╣ ╠common.Important_3⇒很重要╣
  173. $('#Important').text(oCurData.Important === '1' ? i18next.t("common.Important_1") : oCurData.Important === '2' ? i18next.t("common.Important_2") : i18next.t("common.Important_3"));
  174. $('#SignedNumber').text(oCurData.SignedNumber);
  175. $.each(oCurData.CheckOrder, function (idx, order) {
  176. var sFlowType = i18next.t('common.' + order.SignedWay);
  177. if (order.SignedWay !== 'flow1') {
  178. saFlowsText.push(sFlowType + '(' + Enumerable.From(order.SignedMember).ToString(",", "$.name") + ')');
  179. }
  180. else {
  181. saFlowsText.push(Enumerable.From(order.SignedMember).ToString(",", "$.name"));
  182. }
  183. });
  184. $('#Recipient').text($('#Agent_Person option:selected').text() + '->' + saFlowsText.join('->'));
  185. fnGetFiles($('#AdditionalFiles'), oCurData.Guid, oCurData.RelationId, oCurData.ExFeild1, sProgramId);//加載附件
  186. fnUpload();//初始化上傳控件(審批與簽辦)
  187. fnRead();//如果是被通知的人,則修改為已閱讀狀態
  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 + '|BT|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  224. data.CheckFlows = fnCheckFlows(data, true, true, saUsers);
  225. data.HandleFlows = fnHandleFlows(data, saUsers);
  226. data.CheckOrder = JSON.stringify(data.CheckOrder);
  227. data.Status = 'A';
  228. data.IsHandled = 'N';
  229. data.Inspectors = '';
  230. data.Reminders = '';
  231. data.VoidReason = '';
  232. data.Flows_Lock = data.Flows_Lock || 'N';
  233. data.Handle_Lock = data.Handle_Lock || 'N';
  234. delete data.RowIndex;
  235. delete data.AskTheDummyName;
  236. delete data.Agent_PersonName;
  237. delete data.Handle_PersonName;
  238. delete data.HolidayCategoryName;
  239. delete data.DeptName;
  240. delete data.CreateUserName;
  241. delete data.ModifyUserName;
  242. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  243. Params: {
  244. businesstravel: data
  245. }
  246. }, function (res) {
  247. if (res.d > 0) {
  248. showMsgAndGo(i18next.t("message.Copy_Success"), sEditPrgId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Copy_Success⇒複製成功╣
  249. }
  250. else {
  251. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  252. }
  253. }, function () {
  254. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  255. });
  256. },
  257. /**
  258. * 資料作廢
  259. */
  260. fnVoid = function () {
  261. layer.open({
  262. type: 1,
  263. title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
  264. shade: 0.75,
  265. maxmin: true, //开启最大化最小化按钮
  266. area: ['500px', '250px'],
  267. content: '<div class="pop-box">\
  268. <textarea name="VoidContent" id="VoidContent" style="min-width:300px;" class="form-control" rows="5" cols="20"></textarea>\
  269. </div>',
  270. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  271. success: function (layero, index) {
  272. },
  273. yes: function (index, layero) {
  274. var data = {
  275. Status: 'X',
  276. VoidReason: $('#VoidContent').val()
  277. };
  278. if (!$('#VoidContent').val()) {
  279. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  280. return false;
  281. }
  282. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  283. Params: {
  284. businesstravel: {
  285. values: data,
  286. keys: { Guid: sDataId }
  287. }
  288. }
  289. }, function (res) {
  290. if (res.d > 0) {
  291. DelTask(sDataId);
  292. showMsgAndGo(i18next.t('message.Void_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  293. }
  294. else {
  295. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  296. }
  297. });
  298. layer.close(index);
  299. }
  300. });
  301. },
  302. /**
  303. * 複製
  304. */
  305. fnRead = function () {
  306. var bToUpd = false;
  307. $.each(oCurData.CheckFlows, function (idx, _data) {
  308. if (_data.SignedId === parent.UserID && _data.SignedWay === 'flow4' && _data.SignedDecision === 'T') {
  309. _data.SignedDecision = 'R';
  310. bToUpd = true;
  311. return false;
  312. }
  313. });
  314. if (bToUpd) {
  315. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  316. Params: {
  317. businesstravel: {
  318. values: { CheckFlows: JSON.stringify(oCurData.CheckFlows) },
  319. keys: { Guid: sDataId }
  320. }
  321. }
  322. });
  323. }
  324. },
  325. /**
  326. * 抽單
  327. */
  328. fnReEdit = function () {
  329. var data = {};
  330. data.Status = 'C-O';
  331. data = packParams(data, 'upd');
  332. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  333. Params: {
  334. businesstravel: {
  335. values: data,
  336. keys: { Guid: sDataId }
  337. }
  338. }
  339. }, function (res) {
  340. if (res.d > 0) {
  341. showMsg(i18next.t("message.ReEdit_Success"), 'success'); // ╠message.ReEdit_Success⇒抽單成功╣
  342. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  343. Params: {
  344. task: {
  345. values: { Status: 'O' },
  346. keys: { SourceID: sDataId }
  347. }
  348. }
  349. });
  350. fnGet();
  351. }
  352. else {
  353. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  354. }
  355. }, function () {
  356. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  357. });
  358. },
  359. /**
  360. * 提交決定
  361. * @param {String} action 簽核 or 經辦
  362. */
  363. fnSubmitDecision = function (action) {
  364. var data = getFormSerialize(oForm),
  365. saNewCheckFlows = clone(oCurData.CheckFlows),
  366. saNewHandleFlows = clone(oCurData.HandleFlows),
  367. saNewCheckOrderPush = clone(saCheckOrder_Push),
  368. saAdds = [],//加簽核順序
  369. saNextUsers = [],//下組簽核人員
  370. saTipsUsers = [],//需要通知的人員
  371. saNextSignedWays = [],//下組需要處理的動作
  372. iCurOder = 0,//當前順序
  373. sHandlePerson = "";//經辦人
  374. if (action === 'Signed') {
  375. if (data.SignedDecision === 'N' && !data.SignedOpinion) {
  376. showMsg(i18next.t("message.SignedOpinion_required")); // ╠message.SignedOpinion_required⇒請填寫簽核意見╣
  377. return false;
  378. }
  379. else if (data.SignedDecision === 'O' && saCheckOrder_Push.length === 0) {
  380. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  381. return false;
  382. }
  383. var oCurFlow = Enumerable.From(oCurData.CheckFlows).Where(function (e) { return e.FlowId == sCurAuditFlowId; }).First(),
  384. oNewCurFlow = clone(oCurFlow);
  385. iCurOder = oCurFlow.Order;
  386. $.each(saNewCheckOrderPush, function (idx, _push) {
  387. _push.Order = idx + 1 + iCurOder;
  388. });
  389. $.each(saNewCheckFlows, function (idx, _flow) {
  390. if (sCurAuditFlowId === _flow.FlowId) {
  391. _flow.SignedDecision = data.SignedDecision;
  392. _flow.SignedOpinion = data.SignedOpinion;
  393. _flow.SignedDate = newDate();
  394. if (data.SignedDecision === 'O') {
  395. _flow.SignedPush = saCheckOrder_Push;
  396. }
  397. }
  398. if (data.SignedDecision === 'O' && _flow.Order > iCurOder) {
  399. _flow.Order = _flow.Order + saNewCheckOrderPush.length;
  400. if (data.NoreTurn) {//如果再回傳給自己的話排序再增加一個值
  401. _flow.Order++;
  402. }
  403. else {//如果加簽核流程最後一個是通知,並且原流程下一個也是通知的話就合併新舊排序
  404. if (saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay === 'flow4' && saNewCheckFlows[iCurOder + 1].SignedWay === saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay) {
  405. _flow.Order--;
  406. }
  407. }
  408. }
  409. });
  410. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  411. if (data.SignedDecision === 'O' && data.NoreTurn) {
  412. oNewCurFlow.Order = oNewCurFlow.Order + saNewCheckOrderPush.length + 1;
  413. oNewCurFlow.FlowId = guid();
  414. saAdds.push(oNewCurFlow);
  415. }
  416. }
  417. else {
  418. if (data.HandleDecision === 'O' && saCheckOrder_Push.length === 0) {
  419. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  420. return false;
  421. }
  422. iCurOder = saNewCheckFlows[saNewCheckFlows.length - 1].Order;//如果是签辦的話當前順序就是原本流程的最大順序
  423. $.each(saNewHandleFlows, function (idx, _flow) {
  424. if (sCurHandleFlowId === _flow.FlowId) {
  425. _flow.SignedDecision = data.HandleDecision;
  426. _flow.SignedOpinion = data.HnadleOpinion;
  427. _flow.SignedDate = newDate();
  428. if (data.HandleDecision === 'O') {
  429. _flow.SignedPush = saCheckOrder_Push;
  430. }
  431. if (data.HandleDecision === 'Y') {
  432. _flow.SignedPush = null;
  433. }
  434. }
  435. });
  436. if (data.HandleDecision === 'O') {
  437. $.each(saNewCheckOrderPush, function (idx, _push) {
  438. _push.Order = idx + saNewCheckFlows[saNewCheckFlows.length - 1].Order + 1;
  439. });
  440. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  441. }
  442. }
  443. saNewCheckFlows = saNewCheckFlows.concat(saAdds);
  444. saNewCheckFlows = Enumerable.From(saNewCheckFlows).OrderBy("$.Order").ToArray();
  445. var _List = Enumerable.From(saNewCheckFlows).GroupBy("$.Order").ToArray();
  446. saNewCheckFlows = [];
  447. $.each(_List, function (idx, _list) {
  448. //找到要通知的人
  449. var sSignedWay = _list.source[0].SignedWay;
  450. var LastOne = iCurOder >= _List.length
  451. if (idx === iCurOder && !LastOne) {
  452. switch (sSignedWay) {
  453. case "flow1":
  454. case "flow2":
  455. case "flow3":
  456. {
  457. saNextUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  458. saNextSignedWays.push(sSignedWay);
  459. }
  460. break;
  461. case "flow4":
  462. { //不能算通知到
  463. $.each(_list.source, function (i, _source) {
  464. _source.SignedDecision = 'T';
  465. _source.SignedDate = newDate();
  466. });
  467. saTipsUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  468. saNextSignedWays.push(sSignedWay);
  469. ++iCurOder
  470. }
  471. break;
  472. default:
  473. break;
  474. }
  475. }
  476. saNewCheckFlows = saNewCheckFlows.concat(_list.source);
  477. });
  478. //Flow => Handle => END
  479. if (action != 'Handle') {
  480. var CheckNextUser = saNextUsers.length === 0;
  481. if (CheckNextUser && iCurOder === _List.length) {
  482. sHandlePerson = saNewHandleFlows[0].SignedId;
  483. saNextSignedWays.push("flow5");
  484. }
  485. }
  486. g_api.ConnectLite(sEditPrgId, 'BusinessTravelAudit', {
  487. Guid: oCurData.Guid,
  488. Action: action,
  489. GoNext: bGoNext ? 'Y' : 'N',
  490. HandlePerson: sHandlePerson,
  491. NextSignedWays: JSON.stringify(saNextSignedWays),
  492. NextUsers: JSON.stringify(saNextUsers),
  493. TipsUsers: JSON.stringify(saTipsUsers),
  494. CheckFlows: JSON.stringify(saNewCheckFlows),
  495. HandleFlows: JSON.stringify(saNewHandleFlows),
  496. SignedDecision: data.SignedDecision,
  497. HandleDecision: data.HandleDecision
  498. }, function (res) {
  499. if (res.RESULT) {
  500. showMsgAndGo(i18next.t('message.' + action + '_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  501. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  502. }
  503. else {
  504. showMsg(i18next.t('message.' + action + '_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  505. }
  506. }, function () {
  507. showMsg(i18next.t('message.' + action + '_Failed'), 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  508. });
  509. },
  510. /**
  511. * 上傳附件
  512. * @param {Array} files 上傳的文件
  513. */
  514. fnUpload = function (files) {
  515. var option = {};
  516. option.input = $('#fileInput1');
  517. option.theme = 'dragdropbox';
  518. option.folder = 'BusinessTravel';
  519. option.type = 'list';
  520. option.parentid = sCurAuditFlowId;
  521. if (files) {
  522. option.files = files;
  523. }
  524. fnUploadRegister(option);
  525. option.input = $('#fileInput2');
  526. option.parentid = sCurHandleFlowId;
  527. fnUploadRegister(option);
  528. },
  529. /**
  530. * ToolBar 按鈕事件 function
  531. * @param {Object}inst 按鈕物件對象
  532. * @param {Object} e 事件對象
  533. */
  534. fnButtonHandler = function (inst, e) {
  535. var sId = inst.id;
  536. switch (sId) {
  537. case "Toolbar_Qry":
  538. break;
  539. case "Toolbar_Save":
  540. break;
  541. case "Toolbar_ReAdd":
  542. break;
  543. case "Toolbar_Clear":
  544. clearPageVal();
  545. break;
  546. case "Toolbar_Leave":
  547. pageLeave();
  548. break;
  549. case "Toolbar_Add":
  550. break;
  551. case "Toolbar_Upd":
  552. break;
  553. case "Toolbar_Copy":
  554. fnRefreshFlowsThenCopy(oCurData, fnCopy);
  555. break;
  556. case "Toolbar_Void":
  557. fnVoid();
  558. break;
  559. case "Toolbar_ReEdit":
  560. // ╠message.CheckReEdit⇒確定要抽單嗎?╣ ╠common.Tips⇒提示╣
  561. layer.confirm(i18next.t('message.CheckReEdit'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  562. fnReEdit();
  563. layer.close(index);
  564. });
  565. break;
  566. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  567. break;
  568. case "Toolbar_Print":
  569. fnPrePrint($(".panel-info"));
  570. break;
  571. default:
  572. alert("No handle '" + sId + "'");
  573. break;
  574. }
  575. },
  576. /**
  577. * 初始化 function
  578. */
  579. init = function () {
  580. var saCusBtns = null;
  581. if (sAction === 'Upd') {
  582. saCusBtns = [
  583. {
  584. id: 'Toolbar_ReEdit',
  585. value: 'common.ReEdit'// ╠common.ReEdit⇒抽單╣
  586. },
  587. {
  588. id: 'Toolbar_Copy',
  589. value: 'common.Toolbar_Copy'// ╠common.Toolbar_Copy⇒複製╣
  590. }];
  591. }
  592. commonInit({
  593. PrgId: sProgramId,
  594. ButtonHandler: fnButtonHandler,
  595. Buttons: saCusBtns,
  596. GoTop: true
  597. });
  598. $.whenArray([
  599. fnSetDeptDrop($('#Agent_DeptID')),
  600. fnSetUserDrop([
  601. {
  602. Select: $('#Agent_Person'),
  603. CallBack: function (data) {
  604. saUsers = data;
  605. }
  606. }
  607. ]),
  608. fnSetArgDrop([
  609. {
  610. ArgClassID: 'BTrlType',
  611. Select: $('#HolidayCategory'),
  612. ShowId: true
  613. }
  614. ])])
  615. .done(function () {
  616. fnGet();
  617. });
  618. $("#jsGrid1").jsGrid({
  619. width: "100%",
  620. height: "auto",
  621. autoload: true,
  622. pageLoading: true,
  623. pageIndex: 1,
  624. pageSize: 10000,
  625. rowClass: function (item, itemIndex) {
  626. var sRowClass = '';
  627. if (oCurData.CheckFlows.length !== itemIndex + 1) {
  628. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  629. }
  630. else {
  631. sRowClass = 'last-cell';
  632. }
  633. return sRowClass;
  634. },
  635. fields: [
  636. {
  637. type: "Icon", width: 50, align: "center",
  638. itemTemplate: function (val, item) {
  639. var oIcon = {
  640. flow2: '<img src="../../images/flow2_View.gif">',
  641. flow3: '<img src="../../images/flow3_View.gif">',
  642. flow4: '<img src="../../images/flow4.gif">'
  643. };
  644. return item.Icon ? oIcon[item.SignedWay] || '' : '';
  645. }
  646. },
  647. {
  648. name: "Order", title: 'common.Order', width: 50, align: "center",
  649. itemTemplate: function (val, item) {
  650. return val < 10 ? '0' + val : val;
  651. }
  652. },
  653. {
  654. name: "SignedMember", title: 'common.SignedMember', width: 150,
  655. itemTemplate: function (val, item) {
  656. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  657. }
  658. },
  659. {
  660. name: "SignedDecision", title: 'common.Decision', width: 100,
  661. itemTemplate: function (val, item) {
  662. var sVal = val;
  663. if (val === 'Y') {
  664. sVal = i18next.t("common.Agree");// ╠common.Agree⇒同意╣
  665. }
  666. else if (val === 'N') {
  667. sVal = i18next.t("common.NotAgree");// ╠common.NotAgree⇒不同意╣
  668. }
  669. else if (val === 'O') {
  670. sVal = i18next.t("common.AddOther");// ╠common.AddOther⇒先加簽╣
  671. }
  672. else if (val === 'T') {
  673. sVal = i18next.t("common.HasNotice");// ╠common.HasNotice⇒已通知╣
  674. }
  675. else if (val === 'R') {
  676. sVal = i18next.t("common.HasRead");// ╠common.HasRead⇒已閱讀╣
  677. }
  678. return $('<a>', { html: sVal });
  679. }
  680. },
  681. {
  682. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  683. itemTemplate: function (val, item) {
  684. var saVal = [],
  685. oDiv = $('<div>');
  686. if (item.SignedPush) {
  687. var saFlowsPush = item.SignedPush,
  688. saFlowsPushText = [],
  689. sFlowsPushText = '';
  690. $.each(saFlowsPush, function (idx, flow) {
  691. var sFlowType = i18next.t('common.' + flow.SignedWay);
  692. if (flow.SignedWay !== 'flow1') {
  693. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  694. }
  695. else {
  696. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  697. }
  698. });
  699. sFlowsPushText = saFlowsPushText.join(' → ');
  700. saVal.push($('<a>', { html: sFlowsPushText }));
  701. saVal.push('<br />');
  702. }
  703. if (val) {
  704. saVal.push(val);
  705. saVal.push('<br />');
  706. }
  707. fnGetFiles(oDiv.append(saVal), item.FlowId);
  708. return oDiv;
  709. }
  710. },
  711. {
  712. name: "SignedDate", title: 'common.SignedDate', width: 120,
  713. itemTemplate: function (val, item) {
  714. return val;
  715. }
  716. }
  717. ],
  718. controller: {
  719. loadData: function (args) {
  720. return {
  721. data: oCurData.CheckFlows,
  722. itemsCount: oCurData.CheckFlows.length //data.length
  723. };
  724. }
  725. }
  726. });
  727. $("#jsGrid2").jsGrid({
  728. width: "100%",
  729. height: "auto",
  730. autoload: true,
  731. pageLoading: true,
  732. pageIndex: 1,
  733. pageSize: 10000,
  734. rowClass: function (item, itemIndex) {
  735. var sRowClass = '';
  736. if (oCurData.HandleFlows.length !== itemIndex + 1) {
  737. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  738. }
  739. else {
  740. sRowClass = 'last-cell';
  741. }
  742. return sRowClass;
  743. },
  744. fields: [
  745. {
  746. name: "SignedMember", title: 'common.HandleMembers', width: 150,
  747. itemTemplate: function (val, item) {
  748. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  749. }
  750. },
  751. {
  752. name: "SignedDecision", title: 'common.Status', width: 100,
  753. itemTemplate: function (val, item) {
  754. var sVal = val;
  755. if (val === 'Y') {
  756. sVal = i18next.t("common.Hashandle");// ╠common.Hashandle⇒已經辦╣
  757. }
  758. else if (val === 'N') {
  759. sVal = i18next.t("common.Nothandle");// ╠common.Nothandle⇒未處理╣
  760. }
  761. else if (val === 'O') {
  762. sVal = i18next.t("common.AddOtherAudit");// ╠common.AddOtherAudit⇒轉呈其它主管審批╣
  763. }
  764. return $('<a>', { html: sVal });
  765. }
  766. },
  767. {
  768. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  769. itemTemplate: function (val, item) {
  770. var saVal = [],
  771. oDiv = $('<div>');
  772. if (item.SignedPush) {
  773. var saFlowsPush = item.SignedPush,
  774. saFlowsPushText = [],
  775. sFlowsPushText = '';
  776. $.each(saFlowsPush, function (idx, flow) {
  777. var sFlowType = i18next.t('common.' + flow.SignedWay);
  778. if (flow.SignedWay !== 'flow1') {
  779. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  780. }
  781. else {
  782. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  783. }
  784. });
  785. sFlowsPushText = saFlowsPushText.join(' → ');
  786. saVal.push($('<a>', { html: sFlowsPushText }));
  787. saVal.push('<br />');
  788. }
  789. if (val) {
  790. saVal.push(val);
  791. saVal.push('<br />');
  792. }
  793. fnGetFiles(oDiv.append(saVal), item.FlowId);
  794. return oDiv;
  795. }
  796. },
  797. {
  798. name: "SignedDate", title: 'common.HandleDate', width: 120,
  799. itemTemplate: function (val, item) {
  800. return val;
  801. }
  802. }
  803. ],
  804. controller: {
  805. loadData: function (args) {
  806. return {
  807. data: oCurData.HandleFlows,
  808. itemsCount: oCurData.HandleFlows.length //data.length
  809. };
  810. }
  811. }
  812. });
  813. $.each([3, 4], function (idx, _grididx) {
  814. fnRegisterAddFlows(_grididx);
  815. $("#jsGrid" + _grididx).jsGrid({
  816. width: "100%",
  817. height: "auto",
  818. autoload: true,
  819. filtering: false,
  820. pageLoading: true,
  821. pageIndex: 1,
  822. pageSize: 10000,
  823. fields: [
  824. {
  825. name: "Order", title: 'common.Order', width: 50, align: "center",
  826. itemTemplate: function (val, item) {
  827. return val < 10 ? '0' + val : val;
  828. }
  829. },
  830. {
  831. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  832. itemTemplate: function (val, item) {
  833. return i18next.t('common.' + val);
  834. }
  835. },
  836. {
  837. type: "Icon", width: 50, align: "center",
  838. itemTemplate: function (val, item) {
  839. var oIcon = {
  840. flow1: '<img src="../../images/flow_check.gif">',
  841. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  842. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  843. flow4: '<img src="../../images/flow4.gif">'
  844. },
  845. sIcon = oIcon[item.SignedWay];
  846. if (item.Order !== saCheckOrder_Push.length) {
  847. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  848. }
  849. return sIcon;
  850. }
  851. },
  852. {
  853. name: "SignedMember", title: 'common.SignedMember', width: 500,
  854. itemTemplate: function (val, item) {
  855. return Enumerable.From(val).ToString(",", "$.name");
  856. }
  857. },
  858. {
  859. type: "control", title: 'common.Action', width: 200,
  860. itemTemplate: function (val, item) {
  861. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  862. class: 'glyphicon glyphicon-pencil',
  863. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  864. click: function () {
  865. var oOption = {};
  866. oOption.SignedWay = item.SignedWay;
  867. oOption.SignedMember = item.SignedMember;
  868. oOption.Callback = function (data) {
  869. if (data.Users.length > 0) {
  870. var oFlow = {};
  871. if (data.FlowType === 'flow1') {
  872. $.each(data.Users, function (idx, user) {
  873. var oFlow = {};
  874. oFlow.id = guid();
  875. oFlow.Order = item.Order + idx;
  876. oFlow.SignedWay = data.FlowType;
  877. oFlow.SignedMember = [{
  878. id: user.id,
  879. name: user.name,
  880. deptname: user.deptname,
  881. jobname: user.jobname
  882. }];
  883. saCheckOrder_Push.insert(item.Order + idx, oFlow);
  884. });
  885. }
  886. else {
  887. var saUsers = [];
  888. $.each(data.Users, function (idx, user) {
  889. saUsers.push({
  890. id: user.id,
  891. name: user.name,
  892. deptname: user.deptname,
  893. jobname: user.jobname
  894. });
  895. });
  896. oFlow.id = guid();
  897. oFlow.Order = item.Order;
  898. oFlow.SignedWay = data.FlowType;
  899. oFlow.SignedMember = saUsers;
  900. saCheckOrder_Push.insert(item.Order, oFlow);
  901. }
  902. var iOrder = 1;
  903. $.each(saCheckOrder_Push, function (idx, _data) {
  904. if (item.id !== _data.id) {
  905. _data.Order = iOrder;
  906. iOrder++;
  907. }
  908. });
  909. saCheckOrder_Push = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  910. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  911. $("#jsGrid" + _grididx).jsGrid("loadData");
  912. }
  913. };
  914. oPenUserListPop(oOption);
  915. }
  916. })),
  917. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  918. class: 'glyphicon glyphicon-trash',
  919. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  920. click: function () {
  921. var saNewList = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  922. saCheckOrder_Push = saNewList;
  923. $.each(saCheckOrder_Push, function (idx, _data) {
  924. _data.Order = idx + 1;
  925. });
  926. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  927. $("#jsGrid" + _grididx).jsGrid("loadData");
  928. }
  929. }))];
  930. if (saCheckOrder_Push.length !== item.Order) {
  931. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  932. class: 'glyphicon glyphicon-arrow-down',
  933. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  934. click: function () {
  935. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  936. iOrder = sOrder * 1;
  937. $.each(saCheckOrder_Push, function (idx, _data) {
  938. if (iOrder === _data.Order) {
  939. _data.Order++;
  940. }
  941. else if ((iOrder + 1) === _data.Order) {
  942. _data.Order--;
  943. }
  944. });
  945. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  946. $("#jsGrid" + _grididx).jsGrid("loadData");
  947. }
  948. })));
  949. }
  950. else {
  951. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  952. }
  953. if (1 !== item.Order) {
  954. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  955. class: 'glyphicon glyphicon-arrow-up',
  956. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  957. click: function () {
  958. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  959. iOrder = sOrder * 1;
  960. $.each(saCheckOrder_Push, function (idx, _data) {
  961. if (iOrder === _data.Order) {
  962. _data.Order--;
  963. }
  964. else if ((iOrder - 1) === _data.Order) {
  965. _data.Order++;
  966. }
  967. });
  968. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  969. $("#jsGrid" + _grididx).jsGrid("loadData");
  970. }
  971. })));
  972. }
  973. return oBtns;
  974. }
  975. }
  976. ],
  977. controller: {
  978. loadData: function (args) {
  979. return {
  980. data: saCheckOrder_Push,
  981. itemsCount: saCheckOrder_Push.length //data.length
  982. };
  983. }
  984. }
  985. });
  986. });
  987. };
  988. init();
  989. };
  990. require(['base', 'jsgrid', 'jqprint', 'filer', 'common_eip', 'util'], fnPageInit);