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.

142 lines
5.2 KiB

2 years ago
2 years ago
  1. 'use strict';
  2. var fnPageInit = function () {
  3. var canDo = new CanDo({
  4. /**
  5. * 當前程式所有ID名稱集合
  6. */
  7. idKeys: ['OrgID', 'ArgumentClassID', 'ArgumentID'],
  8. /**
  9. * 當前程式所有參數名稱集合
  10. */
  11. paramKeys: ['ArgumentClassID', 'ArgumentID'],
  12. /**
  13. * 客製化驗證規則
  14. * @param {Object} pargs CanDo 對象
  15. */
  16. validRulesCus: function (pargs) {
  17. $.validator.addMethod("argumentidrule", function (value) {
  18. var bRetn = true;
  19. if (value) {
  20. g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout,
  21. {
  22. ArgumentClassID: $('#ArgumentClassID').val(),
  23. ArgumentID: value
  24. },
  25. function (res) {
  26. if (res.RESULT && res.DATA.rel > 0) {
  27. bRetn = false;
  28. }
  29. }, null, false);
  30. }
  31. return bRetn;
  32. });
  33. },
  34. /**
  35. * 驗證規則
  36. */
  37. validRules: {
  38. onfocusout: false,
  39. rules: {
  40. ArgumentID: { argumentidrule: true },
  41. },
  42. messages: {
  43. ArgumentID: { argumentidrule: i18next.t("message.Data_Repeat") }// ╠message.Data_Repeat⇒此筆資料已建檔╣
  44. }
  45. },
  46. /**
  47. * 頁面初始化
  48. * @param {Object} pargs CanDo 對象
  49. */
  50. pageInit: function (pargs) {
  51. var postArray = [];
  52. if (pargs.action === 'upd') {
  53. $('#ArgumentClassID,#ArgumentID').prop('disabled', true);
  54. console.log("ArgumentClassID" + ": " + ArgumentClassID);
  55. console.log("ArgumentID" + ": " + ArgumentID);
  56. postArray.push(pargs._getOne());
  57. }
  58. postArray.push(fnSetArgumentClassIDDrop(), fnSetOrderByValueDrop());
  59. //加載報關類別,加載報價頁簽,加載運輸方式, 加載機場, 加載貨棧場, 加載倉庫
  60. $.whenArray(postArray).done(function (res) {
  61. if (pargs.action === 'upd' && res[0].RESULT) {
  62. var oRes = res[0].DATA.rel;
  63. pargs._setFormVal(oRes);
  64. }
  65. fnSetParentArgumentDrop().done(function () {
  66. pargs._getPageVal();//緩存頁面值,用於清除
  67. });
  68. });
  69. $('#ArgumentValue').on('blur', function () {
  70. $('#ArgumentValue_CN').val(simplized(this.value));
  71. });
  72. }
  73. }),
  74. /**
  75. * 設定參數類別下拉選單
  76. * @return {Object} Ajax 物件
  77. */
  78. fnSetArgumentClassIDDrop = function () {
  79. return g_api.ConnectLite(canDo.QueryPrgId, canDo._api.getlist, {},
  80. function (res) {
  81. if (res.RESULT) {
  82. var saList = res.DATA.rel;
  83. $('#ArgumentClassID').html(createOptions(saList, 'ArgumentClassID', 'ArgumentClassName', true))
  84. .on('change', function () {
  85. fnSetOrderByValueDrop();
  86. });
  87. }
  88. });
  89. },
  90. /**
  91. * 設定報關類別下拉選單
  92. * @return {Object} Ajax 物件
  93. */
  94. fnSetOrderByValueDrop = function () {
  95. return g_api.ConnectLite(canDo.ProgramId, canDo._api.getcout,
  96. {
  97. ArgumentClassID: $('#ArgumentClassID').val()
  98. },
  99. function (res) {
  100. if (res.RESULT) {
  101. var iOrderByCount = res.DATA.rel;
  102. if (canDo.action === 'add') {
  103. iOrderByCount++;
  104. }
  105. $('#OrderByValue').html(createOptions(iOrderByCount));
  106. if (canDo.action === 'add') {
  107. $('#OrderByValue').val(iOrderByCount);
  108. }
  109. }
  110. });
  111. },
  112. /**
  113. * 獲取父層下拉資料
  114. * @return {Object} Ajax 物件
  115. */
  116. fnSetParentArgumentDrop = function () {
  117. var sArgumentClassID = $('#ArgumentClassID').val();
  118. if (sArgumentClassID) {
  119. return fnSetArgDrop([
  120. {
  121. ArgClassID: sArgumentClassID,
  122. Select: $('#ParentArgument'),
  123. ShowId: true,
  124. Select2: true,
  125. CallBack: function (data) {
  126. if (canDo.data.ParentArgument) {
  127. $('#ParentArgument').val(canDo.data.ParentArgument).trigger('change');
  128. }
  129. }
  130. }
  131. ]);
  132. }
  133. else {
  134. return $.Deferred().resolve().promise();
  135. }
  136. };
  137. };
  138. require(['base', 'select2', 'jsgrid', 'convetlng', 'cando'], fnPageInit);