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.

262 lines
11 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. oGrid = null,
  5. fnPageInit = function () {
  6. var setStateDrop = function () {
  7. return g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  8. OrgID: 'TE',
  9. ArgClassID: 'Area',
  10. LevelOfArgument: 1
  11. }, function (res) {
  12. if (res.RESULT) {
  13. let saState = res.DATA.rel;
  14. if (saState.length > 0) {
  15. $('#State').append(createOptions(saState, 'id', 'text', true)).select2();
  16. }
  17. }
  18. });
  19. };
  20. var oForm = $('#form_main'),
  21. oBaseQueryPm = {
  22. pageIndex: 1,
  23. pageSize: parent.SysSet.GridRecords || 10,
  24. sortField: 'ExhibitionCode',
  25. sortOrder: 'desc'
  26. },
  27. /**
  28. * 獲取資料
  29. * @param {Object} args 查詢參數
  30. * @return {Object} Ajax 物件
  31. */
  32. fnGet = function (args) {
  33. var oQueryPm = getFormSerialize(oForm);
  34. $.extend(oQueryPm, oBaseQueryPm, args);
  35. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  36. return g_api.ConnectLite(sProgramId, ComFn.GetPage, oQueryPm, function (res) {
  37. if (res.RESULT) {
  38. var oRes = res.DATA.rel;
  39. if (args.Excel) {//匯出
  40. DownLoadFile(oRes);
  41. layer.close(args.Index);
  42. }
  43. }
  44. });
  45. },
  46. /**
  47. * 打開要匯出的pop選擇匯出類別
  48. */
  49. fnOpenPopToExcel = function () {
  50. layer.open({
  51. type: 1,
  52. title: i18next.t('common.DownLoadDocuments'),// ╠common.DownLoadDocuments⇒下載文檔╣
  53. area: ['300px', '160px'],//寬度
  54. shade: 0.75,//遮罩
  55. shadeClose: true,
  56. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  57. content: '<div class="pop-box">\
  58. <button type="button" data-i18n="common.BasicInformation" id="Exhibition_BasicInformation" class="btn-custom green">基本資料</button>\
  59. <button type="button" data-i18n="common.WenzhongPrjFile" id="Exhibition_WenzhongPrjFile" class="btn-custom green">文中專案檔</button>\
  60. </div>',//common.BasicInformation基本資料common.WenzhongPrjFile文中專案檔
  61. success: function (layero, idx) {
  62. $('.pop-box :button').click(function () {
  63. var sToExcelType = this.id;
  64. fnGet({
  65. Excel: true,
  66. ExcelType: sToExcelType,
  67. Index: idx
  68. });
  69. });
  70. transLang(layero);
  71. }
  72. });
  73. },
  74. /**
  75. * ToolBar 按鈕事件 function
  76. * @param {Object}inst 按鈕物件對象
  77. * @param {Object} e 事件對象
  78. */
  79. fnButtonHandler = function (inst, e) {
  80. var sId = inst.id;
  81. switch (sId) {
  82. case "Toolbar_Qry":
  83. var iNum = $('#PerPageNum').val();
  84. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  85. cacheQueryCondition();
  86. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  87. break;
  88. case "Toolbar_Save":
  89. fnSave('add');
  90. break;
  91. case "Toolbar_ReAdd":
  92. break;
  93. case "Toolbar_Clear":
  94. clearPageVal();
  95. break;
  96. case "Toolbar_Leave":
  97. break;
  98. case "Toolbar_Add":
  99. parent.openPageTab(sEditPrgId, '?Action=Add');
  100. break;
  101. case "Toolbar_Upd":
  102. break;
  103. case "Toolbar_Copy":
  104. break;
  105. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  106. break;
  107. case "Toolbar_Exp":
  108. if (oGrid.data.length === 0) {
  109. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  110. return false;
  111. }
  112. fnOpenPopToExcel();
  113. break;
  114. default:
  115. alert("No handle '" + sId + "'");
  116. break;
  117. }
  118. },
  119. /**
  120. * 初始化 function
  121. */
  122. init = function () {
  123. commonInit({
  124. PrgId: sProgramId,
  125. ButtonHandler: fnButtonHandler,
  126. SearchBar: true
  127. });
  128. var saFields = [
  129. {
  130. name: "RowIndex", title: 'common.RowNumber', type: "text", width: 50, align: "center", sorting: false
  131. },
  132. {
  133. name: "ExhibitionCode", title: 'Exhibition_Upd.ExhibitionCode', type: "text", width: 60
  134. },
  135. {
  136. name: "ExhibitioShotName_TW", title: 'Exhibition_Upd.ExhibitioShotName_TW', type: "text", width: 120
  137. },
  138. {
  139. name: "Exhibitioname_TW", title: 'Exhibition_Upd.Exhibitioname_TW', type: "text", width: 180
  140. },
  141. {
  142. name: "Exhibitioname_EN", title: 'Exhibition_Upd.Exhibitioname_EN', type: "text", width: 180
  143. },
  144. {
  145. name: "ExhibitionDateStart", title: 'Exhibition_Upd.ExhibitionDateRange', type: "text", align: "center", width: 150, itemTemplate: function (val, item) {
  146. var sDateRange = newDate(item.ExhibitionDateStart, 'date', true) + '~' + newDate(item.ExhibitionDateEnd, 'date', true);
  147. return sDateRange === '~' ? '' : sDateRange;
  148. }
  149. }];
  150. if (parent.OrgID === 'TG') {
  151. $('.box-notte').show();
  152. saFields.push({
  153. name: "AreaName", title: 'Exhibition_Upd.Area', type: "text", width: 150
  154. },
  155. {
  156. name: "StateName", title: 'Exhibition_Upd.State', type: "text", width: 150
  157. },
  158. {
  159. name: "IsShowWebSite", title: 'Exhibition_Upd.IsShowWebSite', type: "text", align: "center", width: 100,
  160. itemTemplate: function (val, item) {
  161. return val === 'Y' ? i18next.t('common.Yes') : i18next.t('common.No');
  162. }
  163. });
  164. }
  165. else {
  166. saFields.push({
  167. name: "CreateUserName", title: 'common.CreateUser', type: "text", width: 70
  168. },
  169. {
  170. name: "CreateDate", title: 'common.CreateDate', type: "text", align: "center", width: 100, itemTemplate: function (val, item) {
  171. return newDate(val);
  172. }
  173. },
  174. {
  175. name: "ModifyDate", title: 'common.ModifyDate', type: "text", align: "center", width: 100, itemTemplate: function (val, item) {
  176. return newDate(val);
  177. }
  178. });
  179. }
  180. saFields.push(
  181. {
  182. name: "Effective", title: 'common.Status', type: "text", width: 50, align: "center", itemTemplate: function (val, item) {
  183. return val === 'Y' ? i18next.t('common.Effective') : i18next.t('common.Invalid');// ╠common.Effective⇒有效╣ ╠common.Invalid⇒無效╣
  184. }
  185. },
  186. {
  187. name: "IsTransfer", title: 'common.Transfer_Status', type: "text", width: 50, align: "center", itemTemplate: function (val, item) {
  188. return val === 'Y' ? i18next.t('common.Transfer_Yes') : i18next.t('common.Transfer_No');// ╠common.Transfer_Yes⇒已拋轉╣ ╠common.Transfer_No⇒未拋轉╣
  189. }
  190. });
  191. $.whenArray([
  192. fnSetUserDrop([
  193. {
  194. Select: $('#CreateUser'),
  195. Select2: true,
  196. ShowId: true
  197. }
  198. ]),
  199. setStateDrop()])
  200. .done(function () {
  201. reSetQueryPm(sProgramId);
  202. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  203. $("#jsGrid").jsGrid({
  204. width: "100%",
  205. height: iHeight + "px",
  206. autoload: true,
  207. pageLoading: true,
  208. sorting: true,
  209. paging: true,
  210. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  211. pageSize: parent.SysSet.GridRecords || 10,
  212. pageButtonCount: parent.SysSet.GridPages || 15,
  213. pagePrevText: "<",
  214. pageNextText: ">",
  215. pageFirstText: "<<",
  216. pageLastText: ">>",
  217. onPageChanged: function (args) {
  218. cacheQueryCondition(args.pageIndex);
  219. },
  220. rowClick: function (args) {
  221. if (navigator.userAgent.match(/mobile/i)) {
  222. goToEdit(sEditPrgId, '?Action=Upd&SN=' + args.item.SN);
  223. }
  224. },
  225. rowDoubleClick: function (args) {
  226. parent.openPageTab(sEditPrgId, '?Action=Upd&SN=' + args.item.SN);
  227. },
  228. fields: saFields,
  229. controller: {
  230. loadData: function (args) {
  231. return fnGet(args);
  232. }
  233. },
  234. onInit: function (args) {
  235. oGrid = args.grid;
  236. }
  237. });
  238. });
  239. };
  240. init();
  241. };
  242. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);