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.

240 lines
13 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. sViewPrgId = sProgramId.replace('_Qry', '_View'),
  5. oGrid = null,
  6. fnPageInit = function () {
  7. var oForm = $('#form_main'),
  8. oBaseQueryPm = {
  9. pageIndex: 1,
  10. pageSize: parent.SysSet.GridRecords || 10,
  11. sortField: 'ModifyDate',
  12. sortOrder: 'desc'
  13. },
  14. /**
  15. * 獲取資料
  16. * @param {Object} args 查詢參數
  17. */
  18. fnGet = function (args) {
  19. var oQueryPm = getFormSerialize(oForm);
  20. $.extend(oQueryPm, oBaseQueryPm, args);
  21. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  22. oQueryPm.Roles = parent.UserInfo.roles;
  23. return g_api.ConnectLite(sProgramId, ComFn.GetPage, oQueryPm, function (res) {
  24. if (res.RESULT) {
  25. var oRes = res.DATA.rel;
  26. if (args.Excel) {//匯出
  27. DownLoadFile(oRes);
  28. }
  29. }
  30. });
  31. },
  32. /**
  33. * ToolBar 按鈕事件 function
  34. * @param {Object}inst 按鈕物件對象
  35. * @param {Object} e 事件對象
  36. */
  37. fnButtonHandler = function (inst, e) {
  38. var sId = inst.id;
  39. switch (sId) {
  40. case "Toolbar_Qry":
  41. var iNum = $('#PerPageNum').val();
  42. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  43. cacheQueryCondition();
  44. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  45. break;
  46. case "Toolbar_Save":
  47. break;
  48. case "Toolbar_ReAdd":
  49. break;
  50. case "Toolbar_Clear":
  51. clearPageVal();
  52. break;
  53. case "Toolbar_Leave":
  54. break;
  55. case "Toolbar_Add":
  56. parent.openPageTab(sEditPrgId, '?Action=Add');
  57. break;
  58. case "Toolbar_Upd":
  59. break;
  60. case "Toolbar_Copy":
  61. break;
  62. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  63. break;
  64. default:
  65. alert("No handle '" + sId + "'");
  66. break;
  67. }
  68. },
  69. /**
  70. * 頁面初始化
  71. */
  72. init = function () {
  73. commonInit({
  74. PrgId: sProgramId,
  75. ButtonHandler: fnButtonHandler,
  76. SearchBar: true
  77. });
  78. fnSetUserDrop([
  79. {
  80. Select: $('#Applicant'),
  81. ShowId: true,
  82. Select2: true,
  83. CallBack: function () {
  84. reSetQueryPm(sProgramId);
  85. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  86. $("#jsGrid").jsGrid({
  87. width: "100%",
  88. height: iHeight + "px",
  89. autoload: true,
  90. pageLoading: true,
  91. inserting: false,
  92. editing: true,
  93. sorting: true,
  94. paging: true,
  95. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  96. pageSize: parent.SysSet.GridRecords || 10,
  97. pageButtonCount: parent.SysSet.GridPages || 15,
  98. pagePrevText: "<",
  99. pageNextText: ">",
  100. pageFirstText: "<<",
  101. pageLastText: ">>",
  102. rowClass: function (item) {
  103. if (item.Status === 'X') {
  104. return 'data-void';
  105. }
  106. },
  107. onPageChanged: function (args) {
  108. cacheQueryCondition(args.pageIndex);
  109. },
  110. rowClick: function (args) {
  111. if (navigator.userAgent.match(/mobile/i)) {
  112. if ('A,C'.indexOf(args.item.Status) > -1 && args.item.AskTheDummy === parent.UserID) {
  113. goToEdit(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  114. }
  115. else {
  116. goToEdit(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  117. }
  118. }
  119. },
  120. rowDoubleClick: function (args) {
  121. if ('A,C'.indexOf(args.item.Status) > -1 && args.item.Applicant === parent.UserID) {
  122. parent.openPageTab(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  123. }
  124. else {
  125. parent.openPageTab(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  126. }
  127. },
  128. fields: [
  129. { name: "RowIndex", title: 'common.RowNumber', align: 'center', width: 40, sorting: false },
  130. { name: "SignedNumber", title: 'common.SignedNumber', width: 60 },
  131. {
  132. name: "KeyNote", title: 'common.KeyNote', width: 200, itemTemplate: function (val, item) {
  133. var sVal = val,
  134. oStatus = {
  135. 'A': i18next.t('common.Draft'),// ╠common.Draft⇒草稿╣
  136. 'B': i18next.t('common.InAudit'),// ╠common.InAudit⇒審核中╣
  137. 'C-O': i18next.t('common.HasReEdited'),// ╠common.HasReEdited⇒已抽單╣
  138. 'D-O': i18next.t('common.HasReturned'),// ╠common.HasReturned⇒已退件╣
  139. 'H-O': i18next.t('common.Hashandle'),// ╠common.Hashandle⇒已經辦╣
  140. 'E': i18next.t('common.ToHandle'),// ╠common.ToHandle⇒待經辦╣
  141. 'X': i18next.t('common.HasVoid')// ╠common.HasVoid⇒已作廢╣
  142. };
  143. sVal += oStatus[item.Status] ? '<span style="color:#DF5F09">(' + oStatus[item.Status] + ')</span>' : '';
  144. if (item.Important > 1) {
  145. for (var i = 0; i < item.Important - 1; i++) {
  146. sVal += ' <img src="../../images/star.gif">';
  147. }
  148. }
  149. return $('<a>', { html: sVal });
  150. }
  151. },
  152. { name: "ApplicantName", title: 'common.Applicant', width: 70, align: 'center' },
  153. { name: "TravelPlace", title: 'common.TravelPlace', width: 150 },
  154. {
  155. name: "CheckFlows", title: 'common.Progress', width: 50, itemTemplate: function (val, item) {
  156. var saCheckFlows = $.parseJSON(val),
  157. iProgress = 0;
  158. var saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray();
  159. $.each(saNewList, function (idx, _data) {
  160. var sSignedWay = _data.source[0].SignedWay,
  161. iCount = Enumerable.From(_data.source).Where(function (e) { return e.SignedDecision !== ''; }).Count();
  162. if ((iCount === _data.source.length && sSignedWay !== 'flow3') || (iCount > 0 && sSignedWay === 'flow3')) {
  163. iProgress = idx + 1;
  164. }
  165. else {
  166. return false;
  167. }
  168. });
  169. return $('<a>', { html: iProgress + '/' + saNewList.length });
  170. }
  171. },
  172. {
  173. name: "CheckFlows", title: 'common.CurAuditor', width: 100, itemTemplate: function (val, item) {
  174. var saCheckFlows = $.parseJSON(val),
  175. sCurAuditor = '';
  176. var saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray();
  177. $.each(saNewList, function (idx, _data) {
  178. var sSignedWay = _data.source[0].SignedWay,
  179. sFlowType = i18next.t('common.' + sSignedWay),
  180. iCount = Enumerable.From(_data.source).Where(function (e) { return e.SignedDecision !== ''; }).Count();
  181. if (('flow1,flow3'.indexOf(sSignedWay) > -1 && iCount === 0) || (sSignedWay === 'flow2' && iCount !== _data.source.length)) {
  182. sCurAuditor = Enumerable.From(_data.source).ToString(",", "$.SignedMember");
  183. if (sSignedWay !== 'flow1') {
  184. sCurAuditor = sFlowType + '(' + sCurAuditor + ')';
  185. }
  186. return false;
  187. }
  188. });
  189. if (sCurAuditor === '') {
  190. var saCheckFlows = $.parseJSON(item.HandleFlows);
  191. if (saCheckFlows[0].SignedDecision !== 'Y') {
  192. sCurAuditor = saCheckFlows[0].SignedMember;
  193. }
  194. }
  195. return $('<a>', { html: sCurAuditor.length > 11 ? sCurAuditor.substr(0, 11) + '...' : sCurAuditor, title: sCurAuditor });
  196. }
  197. },
  198. {
  199. name: "CreateDate", title: 'common.CreateDate', width: 90, align: 'center', itemTemplate: function (val, item) {
  200. return newDate(val);
  201. }
  202. }
  203. ],
  204. controller: {
  205. loadData: function (args) {
  206. return fnGet(args);
  207. },
  208. },
  209. onInit: function (args) {
  210. oGrid = args.grid;
  211. }
  212. });
  213. }
  214. }
  215. ]);
  216. };
  217. init();
  218. };
  219. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);