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.

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