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.

210 lines
9.8 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. oGrid = null,
  5. fnPageInit = function () {
  6. var oForm = $('#form_main'),
  7. oBaseQueryPm = {
  8. pageIndex: 1,
  9. pageSize: parent.SysSet.GridRecords || 10,
  10. sortField: 'News_LanguageType,OrderByValue',
  11. sortOrder: 'asc'
  12. },
  13. /**
  14. * 獲取資料
  15. * @param {Object} args 查詢條件參數
  16. * @return {Object} Ajax 物件
  17. */
  18. fnGet = function (args) {
  19. var oQueryPm = getFormSerialize(oForm);
  20. $.extend(oQueryPm, oBaseQueryPm, args);
  21. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  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. default:
  64. alert("No handle '" + sId + "'");
  65. break;
  66. }
  67. },
  68. /**
  69. * 頁面初始化
  70. */
  71. init = function () {
  72. commonInit({
  73. PrgId: sProgramId,
  74. ButtonHandler: fnButtonHandler,
  75. SearchBar: true
  76. });
  77. fnSetArgDrop([
  78. {
  79. ArgClassID: 'LanCountry',
  80. Select: $('#News_LanguageType'),
  81. ShowId: true
  82. },
  83. {
  84. ArgClassID: 'News_Class',
  85. Select: $('#News_Type'),
  86. ShowId: true
  87. }
  88. ])
  89. .done(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. onPageChanged: function (args) {
  109. cacheQueryCondition(args.pageIndex);
  110. },
  111. rowClick: function (args) {
  112. if (navigator.userAgent.match(/mobile/i)) {
  113. goToEdit(sEditPrgId, '?Action=Upd&SN=' + args.item.SN);
  114. }
  115. },
  116. rowDoubleClick: function (args) {
  117. parent.openPageTab(sEditPrgId, '?Action=Upd&SN=' + args.item.SN);
  118. },
  119. fields: [
  120. { name: "RowIndex", title: 'common.RowNumber', align: 'center', width: 50, sorting: false },
  121. {
  122. name: "News_Type", title: 'News_Upd.News_Type', width: 100, itemTemplate: function (val, item) {
  123. return item.News_TypeName;
  124. }
  125. },
  126. {
  127. name: "News_LanguageType", title: 'News_Upd.News_LanguageType', width: 100, itemTemplate: function (val, item) {
  128. return item.News_LanguageTypeName;
  129. }
  130. },
  131. { name: "News_Title", title: 'News_Upd.News_Title', width: 300 },
  132. {// ╠common.ReleaseDate⇒發佈日期╣
  133. name: "CreateDate", title: 'common.ReleaseDate', width: 100, align: 'center', itemTemplate: function (val, item) {
  134. return newDate(val, 'date');
  135. }
  136. },
  137. {
  138. name: "News_StartDete", title: 'News_Upd.News_StartDete', width: 100, align: 'center', itemTemplate: function (val, item) {
  139. return newDate(val, 'date');
  140. }
  141. },
  142. {
  143. name: "News_EndDete", title: 'News_Upd.News_EndDete', width: 100, align: 'center', itemTemplate: function (val, item) {
  144. return newDate(val, 'date', true);
  145. }
  146. },
  147. {
  148. name: "News_Show", title: 'common.Status', width: 100, align: 'center', itemTemplate: function (val, item) {
  149. return val === 'Y' ? i18next.t('common.Effective') : i18next.t('common.Invalid');// ╠common.Effective⇒有效╣ ╠common.Invalid⇒無效╣
  150. }
  151. },
  152. {
  153. name: "OrderByValue", title: 'common.OrderByValue', type: "select", width: 100,
  154. itemTemplate: function (val, item) {
  155. return this._createSelect = $("<select>", {
  156. class: 'w70',
  157. html: createOptions(item.OrderCount),
  158. change: function () {
  159. var sOldValue = val,
  160. sNewValue = this.value;
  161. g_api.ConnectLite(sProgramId, ComFn.GetUpdateOrder, {
  162. Id: item.SN,
  163. OldOrderByValue: sOldValue,
  164. NewOrderByValue: sNewValue
  165. }, function (res) {
  166. if (res.RESULT) {
  167. showMsg(i18next.t('message.Update_Success'), 'success');// ╠message.Update_Success⇒更新成功╣
  168. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  169. }
  170. else {
  171. showMsg(i18next.t('message.Update_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Update_Failed⇒更新失敗╣
  172. }
  173. });
  174. }
  175. }).val(val);
  176. }
  177. }
  178. ],
  179. controller: {
  180. loadData: function (args) {
  181. return fnGet(args);
  182. },
  183. },
  184. onInit: function (args) {
  185. oGrid = args.grid;
  186. }
  187. });
  188. });
  189. };
  190. init();
  191. };
  192. require(['base', 'jsgrid', 'util'], fnPageInit);