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.

254 lines
14 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. case "Toolbar_Exp":
  65. if (oGrid.data.length === 0) {
  66. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  67. return false;
  68. }
  69. fnGet({ Excel: true });
  70. break;
  71. default:
  72. alert("No handle '" + sId + "'");
  73. break;
  74. }
  75. },
  76. /**
  77. * 頁面初始化
  78. */
  79. init = function () {
  80. commonInit({
  81. PrgId: sProgramId,
  82. ButtonHandler: fnButtonHandler,
  83. SearchBar: true
  84. });
  85. fnSetUserDrop([
  86. {
  87. Select: $('#AskTheDummy'),
  88. ShowId: true,
  89. Select2: true,
  90. CallBack: function () {
  91. reSetQueryPm(sProgramId);
  92. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  93. $("#jsGrid").jsGrid({
  94. width: "100%",
  95. height: iHeight + "px",
  96. autoload: true,
  97. pageLoading: true,
  98. inserting: false,
  99. editing: true,
  100. sorting: true,
  101. paging: true,
  102. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  103. pageSize: parent.SysSet.GridRecords || 10,
  104. pageButtonCount: parent.SysSet.GridPages || 15,
  105. pagePrevText: "<",
  106. pageNextText: ">",
  107. pageFirstText: "<<",
  108. pageLastText: ">>",
  109. rowClass: function (item) {
  110. if (item.Status === 'X') {
  111. return 'data-void';
  112. }
  113. },
  114. onPageChanged: function (args) {
  115. cacheQueryCondition(args.pageIndex);
  116. },
  117. rowClick: function (args) {
  118. if (navigator.userAgent.match(/mobile/i)) {
  119. if ('A,C'.indexOf(args.item.Status) > -1 && args.item.AskTheDummy === parent.UserID) {
  120. goToEdit(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  121. }
  122. else {
  123. goToEdit(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  124. }
  125. }
  126. },
  127. rowDoubleClick: function (args) {
  128. if ('A,C'.indexOf(args.item.Status) > -1 && args.item.AskTheDummy === parent.UserID) {
  129. parent.openPageTab(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  130. }
  131. else {
  132. parent.openPageTab(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  133. }
  134. },
  135. fields: [
  136. { name: "RowIndex", title: 'common.RowNumber', align: 'center', width: 40, sorting: false },
  137. { name: "SignedNumber", title: 'common.SignedNumber', width: 60 },
  138. {
  139. name: "KeyNote", title: 'common.KeyNote', width: 200, itemTemplate: function (val, item) {
  140. var sVal = val,
  141. oStatus = {
  142. 'A': i18next.t('common.Draft'),// ╠common.Draft⇒草稿╣
  143. 'B': i18next.t('common.InAudit'),// ╠common.InAudit⇒審核中╣
  144. 'C-O': i18next.t('common.HasReEdited'),// ╠common.HasReEdited⇒已抽單╣
  145. 'D-O': i18next.t('common.HasReturned'),// ╠common.HasReturned⇒已退件╣
  146. 'H-O': i18next.t('common.Hashandle'),// ╠common.Hashandle⇒已經辦╣
  147. 'E': i18next.t('common.ToHandle'),// ╠common.ToHandle⇒待經辦╣
  148. 'X': i18next.t('common.HasVoid')// ╠common.HasVoid⇒已作廢╣
  149. };
  150. sVal += oStatus[item.Status] ? '<span style="color:#DF5F09">(' + oStatus[item.Status] + ')</span>' : '';
  151. if (item.Important > 1) {
  152. for (var i = 0; i < item.Important - 1; i++) {
  153. sVal += ' <img src="../../images/star.gif">';
  154. }
  155. }
  156. return $('<a>', { html: sVal });
  157. }
  158. },
  159. { name: "AskTheDummyName", title: 'common.Applicant', width: 70, align: 'center' },
  160. {
  161. name: "OverTimes", title: 'common.OverTimeUsers', width: 200, itemTemplate: function (val, item) {
  162. var saOverTimes = $.parseJSON(val),
  163. sOverTimes = Enumerable.From(saOverTimes).ToString(",", "$.EmployeeName");
  164. return sOverTimes;
  165. }
  166. },
  167. {
  168. name: "CheckFlows", title: 'common.Progress', width: 50, itemTemplate: function (val, item) {
  169. var saCheckFlows = $.parseJSON(val),
  170. iProgress = 0;
  171. var saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray();
  172. $.each(saNewList, function (idx, _data) {
  173. var sSignedWay = _data.source[0].SignedWay,
  174. iCount = Enumerable.From(_data.source).Where(function (e) { return e.SignedDecision !== ''; }).Count();
  175. if ((iCount === _data.source.length && sSignedWay !== 'flow3') || (iCount > 0 && sSignedWay === 'flow3')) {
  176. iProgress = idx + 1;
  177. }
  178. else {
  179. return false;
  180. }
  181. });
  182. return $('<a>', { html: iProgress + '/' + saNewList.length });
  183. }
  184. },
  185. {
  186. name: "CheckFlows", title: 'common.CurAuditor', width: 100, itemTemplate: function (val, item) {
  187. var saCheckFlows = $.parseJSON(val),
  188. sCurAuditor = '';
  189. var saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray();
  190. $.each(saNewList, function (idx, _data) {
  191. var sSignedWay = _data.source[0].SignedWay,
  192. sFlowType = i18next.t('common.' + sSignedWay),
  193. iCount = Enumerable.From(_data.source).Where(function (e) { return e.SignedDecision !== ''; }).Count();
  194. if (('flow1,flow3'.indexOf(sSignedWay) > -1 && iCount === 0) || (sSignedWay === 'flow2' && iCount !== _data.source.length)) {
  195. sCurAuditor = Enumerable.From(_data.source).ToString(",", "$.SignedMember");
  196. if (sSignedWay !== 'flow1') {
  197. sCurAuditor = sFlowType + '(' + sCurAuditor + ')';
  198. }
  199. return false;
  200. }
  201. });
  202. if (sCurAuditor === '') {
  203. var saCheckFlows = $.parseJSON(item.HandleFlows);
  204. if (saCheckFlows[0].SignedDecision !== 'Y') {
  205. sCurAuditor = saCheckFlows[0].SignedMember;
  206. }
  207. }
  208. return $('<a>', { html: sCurAuditor.length > 11 ? sCurAuditor.substr(0, 11) + '...' : sCurAuditor, title: sCurAuditor });
  209. }
  210. },
  211. {
  212. name: "CreateDate", title: 'common.CreateDate', width: 90, align: 'center', itemTemplate: function (val, item) {
  213. return newDate(val);
  214. }
  215. }
  216. ],
  217. controller: {
  218. loadData: function (args) {
  219. return fnGet(args);
  220. },
  221. },
  222. onInit: function (args) {
  223. oGrid = args.grid;
  224. }
  225. });
  226. }
  227. }
  228. ]);
  229. };
  230. init();
  231. };
  232. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);