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.

318 lines
16 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. oTimeOut = null,
  8. oBaseQueryPm = {
  9. pageIndex: 1,
  10. pageSize: parent.SysSet.GridRecords || 10,
  11. sortField: '',
  12. sortOrder: 'asc'
  13. },
  14. /**
  15. * 獲取資料
  16. * @param {Object} args 查詢參數
  17. * @return {Object} Ajax 物件
  18. */
  19. fnGetPro = function (args) {
  20. var oQueryPm = getFormSerialize(oForm);
  21. $.extend(oQueryPm, oBaseQueryPm, args);
  22. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  23. return g_api.ConnectLite(sProgramId, 'QueryPage', oQueryPm, function (res) {
  24. if (args.Excel) {//匯出
  25. var oRes = res.DATA.rel;
  26. DownLoadFile(oRes);
  27. layer.close(args.Index);
  28. }
  29. });
  30. },
  31. /**
  32. * 打開要匯出的pop選擇匯出類別
  33. */
  34. fnOpenPopToExcel = function () {
  35. layer.open({
  36. type: 1,
  37. title: i18next.t('common.DownLoadDocuments'), // ╠common.DownLoadDocuments⇒下載文檔╣
  38. area: ['200px', '160px'],//寬度
  39. shade: 0.75,//遮罩
  40. shadeClose: true,
  41. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  42. content: '<div class="pop-box">\
  43. <button type="button" data-i18n="common.BasicInformation" id="OtherBusiness_BasicInformation" class="btn-custom green">基本資料</button>\
  44. </div>',
  45. success: function (layero, idx) {
  46. $('.pop-box :button').click(function () {
  47. var sToExcelType = this.id;
  48. fnGetPro({
  49. Excel: true,
  50. ExcelType: sToExcelType,
  51. Index: idx
  52. });
  53. });
  54. transLang(layero);
  55. }
  56. });
  57. },
  58. /**
  59. * ToolBar 按鈕事件 function
  60. * @param {Object}inst 按鈕物件對象
  61. * @param {Object} e 事件對象
  62. */
  63. fnButtonHandler = function (inst, e) {
  64. var sId = inst.id;
  65. switch (sId) {
  66. case "Toolbar_Qry":
  67. var iNum = $('#PerPageNum').val();
  68. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  69. cacheQueryCondition();
  70. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  71. break;
  72. case "Toolbar_Save":
  73. fnSave('add');
  74. break;
  75. case "Toolbar_ReAdd":
  76. break;
  77. case "Toolbar_Clear":
  78. clearPageVal();
  79. break;
  80. case "Toolbar_Leave":
  81. break;
  82. case "Toolbar_Add":
  83. parent.openPageTab(sEditPrgId, '?Action=Add');
  84. break;
  85. case "Toolbar_Upd":
  86. break;
  87. case "Toolbar_Copy":
  88. break;
  89. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  90. break;
  91. case "Toolbar_Exp":
  92. if (oGrid.data.length === 0) {
  93. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  94. return false;
  95. }
  96. fnOpenPopToExcel();
  97. break;
  98. default:
  99. alert("No handle '" + sId + "'");
  100. break;
  101. }
  102. },
  103. /**
  104. * 初始化 function
  105. */
  106. init = function () {
  107. if (parent.OrgID !== 'TE') {
  108. $('.dept-box').hide();
  109. }
  110. commonInit({
  111. PrgId: sProgramId,
  112. ButtonHandler: fnButtonHandler,
  113. SearchBar: true
  114. });
  115. $.whenArray([
  116. fnSetDeptDrop($('#DepartmentID'), parent.SysSet.SearchDeptList),
  117. fnSetUserDrop([
  118. {
  119. Select: $('#ResponsiblePerson'),
  120. Select2: true,
  121. ShowId: true,
  122. ServiceCode: parent.SysSet.IMCode
  123. }
  124. ]),
  125. fnSetArgDrop([
  126. {
  127. ArgClassID: 'DeclClass',
  128. Select: $('#DeclarationClass'),
  129. ShowId: true
  130. }
  131. ])
  132. ])
  133. .done(function () {
  134. reSetQueryPm(sProgramId);
  135. var sCode = parent.UserInfo.ServiceCode;
  136. if (sCode && parent.SysSet.IMCode.indexOf(sCode) > -1 && parent.UserInfo.roles.indexOf('CDD') === -1) {
  137. $('#ResponsiblePerson').val(parent.UserInfo.MemberID);
  138. }
  139. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  140. $("#jsGrid").jsGrid({
  141. width: "100%",
  142. height: iHeight + "px",
  143. autoload: true,
  144. pageLoading: true,
  145. sorting: true,
  146. paging: true,
  147. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  148. pageSize: parent.SysSet.GridRecords || 10,
  149. pageButtonCount: parent.SysSet.GridPages || 15,
  150. pagePrevText: "<",
  151. pageNextText: ">",
  152. pageFirstText: "<<",
  153. pageLastText: ">>",
  154. headerClick: function () {
  155. },
  156. onPageChanged: function (args) {
  157. cacheQueryCondition(args.pageIndex);
  158. },
  159. rowClick: function (args) {
  160. if ((args.item.IsVoid === 'Y' && parent.UserInfo.IsManager) || args.item.IsVoid === 'N') {
  161. if (navigator.userAgent.match(/mobile/i)) {
  162. goToEdit(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  163. }
  164. }
  165. else {
  166. showMsg(i18next.t("message.NoPermission")); // ╠message.NoPermission⇒沒有權限╣
  167. }
  168. },
  169. rowDoubleClick: function (args) {
  170. if ((args.item.IsVoid === 'Y' && parent.UserInfo.IsManager) || args.item.IsVoid === 'N') {
  171. parent.openPageTab(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  172. }
  173. else {
  174. showMsg(i18next.t("message.NoPermission")); // ╠message.NoPermission⇒沒有權限╣
  175. }
  176. },
  177. rowClass: function (item) {
  178. var sClass = '';
  179. if (item.IsVoid === 'Y') {
  180. sClass = 'data-void';
  181. }
  182. return sClass;
  183. },
  184. fields: [
  185. {
  186. name: "RowIndex", title: 'common.RowNumber', type: "text", width: 50, align: "center", sorting: false
  187. },
  188. {
  189. name: "ExhibitionName", title: 'common.ExhibitionName', type: "text", width: 150
  190. },
  191. {// ╠common.DeclarationNO⇒報單號碼╣
  192. name: "ImportDeclarationNO", title: 'common.DeclarationNO', type: "text", width: 100
  193. },
  194. {
  195. name: "AgentName", title: 'ExhibitionImport_Upd.Agent', type: "text", width: 150
  196. },
  197. {
  198. name: "ResponsiblePersonName", title: 'common.ResponsiblePerson', type: "text", width: 100
  199. },
  200. {
  201. type: "control", title: 'common.Bill_Status', itemTemplate: function (val, item) {// ╠common.Bill_Status⇒帳單狀態╣
  202. var iTips = 0,
  203. sTipsHtml = '<div class="layui-layer-btn-c">' + i18next.t("common.Bill_Status") + '</div>',// ╠common.Bill_Status⇒帳單狀態╣
  204. saBills = $.parseJSON(!(item.Bills) ? '[]' : item.Bills),
  205. bOK = true,
  206. oOption = {
  207. btnAlign: 'c',
  208. time: 600000 //一個小時(如果不配置,默认是3秒)
  209. },
  210. oTips = $('<span>', {
  211. 'class': 'glyphicon glyphicon-info-sign',
  212. 'aria-hidden': true
  213. }).on({
  214. click: function () {
  215. oOption.btn = [i18next.t("common.Close")];// ╠common.Close⇒關閉╣
  216. layer.msg(sTipsHtml, oOption);
  217. },
  218. mouseenter: function (event) {
  219. delete oOption.btn;
  220. iTips = layer.msg(sTipsHtml, oOption);
  221. },
  222. mouseleave: function (event) {
  223. layer.close(iTips);
  224. }
  225. });
  226. if (saBills.length > 0) {
  227. sTipsHtml += '<ul class="bill-status">';
  228. $.each(saBills, function (idx, bill) {
  229. var sStatusName = '';
  230. switch (bill.AuditVal) {
  231. case '0':// ╠common.NotAudit⇒未提交審核╣
  232. sStatusName = i18next.t("common.NotAudit");
  233. if (bOK) { bOK = false; }
  234. break;
  235. case '1':// ╠common.InAudit⇒提交審核中╣
  236. sStatusName = i18next.t("common.InAudit");
  237. if (bOK) { bOK = false; }
  238. break;
  239. case '2':// ╠common.Audited⇒已審核╣
  240. sStatusName = i18next.t("common.Audited");
  241. break;
  242. case '3':// ╠common.NotPass⇒不通過╣
  243. sStatusName = i18next.t("common.NotPass");
  244. if (bOK) { bOK = false; }
  245. break;
  246. case '4':// ╠common.HasBeenRealized⇒已銷帳╣
  247. sStatusName = i18next.t("common.HasBeenRealized");
  248. break;
  249. case '5':// ╠common.HasBeenPost⇒已過帳╣
  250. sStatusName = i18next.t("common.HasBeenPost");
  251. break;
  252. case '6':// ╠common.HasVoid⇒已作廢╣
  253. sStatusName = i18next.t("common.HasVoid");
  254. break;
  255. case '7':// ╠common.HasReEdit⇒抽單中╣
  256. sStatusName = i18next.t("common.HasReEdit");
  257. break;
  258. }
  259. sTipsHtml += "<li><a class='gopagetab' onclick='parent.openPageTab(\"" + sEditPrgId + "\",\"?Action=Upd&GoTab=3&Guid=" + item.Guid + "&BillNO=" + bill.BillNO + "\")' ><div>" + (bill.SupplierName || bill.SupplierEName || '') + '(' + bill.BillNO + ")</div><div>" + sStatusName + "</div></a></li>";
  260. });
  261. sTipsHtml += '</ul>';
  262. oOption.area = ['550px'];
  263. if (saBills.length > 15) {
  264. oOption.area = ['550px', '500px'];
  265. }
  266. }
  267. else {
  268. sTipsHtml = '<div>' + i18next.t("common.NOBills") + '</div>';// ╠common.NOBills⇒還沒有帳單╣
  269. bOK = false;
  270. }
  271. if (bOK) {
  272. oTips.css('color', 'blue');
  273. }
  274. else {
  275. oTips.css('color', 'red');
  276. }
  277. return oTips;
  278. }
  279. }
  280. ],
  281. controller: {
  282. loadData: function (args) {
  283. return fnGetPro(args);
  284. }
  285. },
  286. onInit: function (args) {
  287. oGrid = args.grid;
  288. }
  289. });
  290. if (parent.UserInfo.roles.indexOf('Business') > -1 || parent.UserInfo.roles.indexOf('CDD') > -1) {//報關||業務
  291. $('.slide-box').click();
  292. }
  293. });
  294. };
  295. init();
  296. };
  297. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);