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.

315 lines
12 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sAction = getUrlParam('Action') || 'Add',
  5. sDataId = getUrlParam('SN'),
  6. sCheckId = sDataId,
  7. fnPageInit = function () {
  8. var oCurData = {},
  9. oForm = $('#form_main'),
  10. oValidator = null,
  11. oEditor = null,
  12. /**
  13. * 獲取資料
  14. * @return {Object} ajax 對象
  15. */
  16. fnGet = function () {
  17. if (sDataId) {
  18. return CallAjax(ComFn.W_Com, ComFn.GetOne, {
  19. Type: '',
  20. Params: {
  21. news: {
  22. SN: sDataId
  23. }
  24. }
  25. }, function (res) {
  26. if (res.d) {
  27. var oRes = $.parseJSON(res.d);
  28. oCurData = oRes;
  29. if (!oCurData.News_Pic) {
  30. oCurData.News_Pic = guid();
  31. }
  32. if (!oCurData.PicShowId) {
  33. oCurData.PicShowId = guid();
  34. }
  35. //判斷非TG時是否需要生成展會花絮
  36. if (oCurData.News_Type == "02" && parent.OrgID != "TG") {
  37. $('.picshowid').show();
  38. }
  39. oEditor.ready(function () {
  40. oEditor.setContent(oRes.News_Content);
  41. });
  42. setFormVal(oForm, oRes);
  43. fnSetOrderByValueDrop(oRes.News_LanguageType).done(function () {
  44. $('#OrderByValue').val(oRes.OrderByValue);
  45. });
  46. fnGetUploadFiles(oCurData.News_Pic, fnUpload, $('#fileInput'));
  47. fnGetUploadFiles(oCurData.PicShowId, fnUpload, $('#fileInput_show'));
  48. setNameById().done(function () {
  49. getPageVal(); //緩存頁面值,用於清除
  50. });
  51. }
  52. });
  53. }
  54. else {
  55. oCurData.News_Pic = guid();
  56. oCurData.PicShowId = guid();
  57. fnUpload(null, oCurData.News_Pic, $('#fileInput'));
  58. fnUpload(null, oCurData.PicShowId, $('#fileInput_show'));
  59. return fnSetOrderByValueDrop();
  60. }
  61. },
  62. /**
  63. * 新增資料
  64. * @param {String} sFlag 儲存 or 儲存后新增
  65. * @return {Object} ajax 對象
  66. */
  67. fnAdd = function (sFlag) {
  68. var data = getFormSerialize(oForm);
  69. data.OrgID = parent.OrgID;
  70. data.News_Pic = oCurData.News_Pic;
  71. data.PicShowId = oCurData.PicShowId;
  72. data.News_Content = oEditor.getContent();
  73. data.NewsContent = oEditor.getContentTxt();
  74. return g_api.ConnectLite(sProgramId, ComFn.GetAdd, data, function (res) {
  75. if (res.RESULT) {
  76. bRequestStorage = false;
  77. if (sFlag === 'add') {
  78. showMsgAndGo(i18next.t("message.Save_Success"), sQueryPrgId); // ╠message.Save_Success⇒新增成功╣
  79. }
  80. else {
  81. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  82. }
  83. }
  84. else {
  85. showMsg(i18next.t("message.Save_Failed") + '<br>' + res.MSG, 'error');// ╠message.Save_Failed⇒新增失敗╣
  86. }
  87. }, function () {
  88. showMsg(i18next.t("message.Save_Failed"), 'error');// ╠message.Save_Failed⇒新增失敗╣
  89. });
  90. },
  91. /**
  92. * 修改資料
  93. * @return {Object} ajax 對象
  94. */
  95. fnUpd = function () {
  96. var data = getFormSerialize(oForm);
  97. data.News_Content = oEditor.getContent();
  98. data.NewsContent = oEditor.getContentTxt();
  99. data.SN = sDataId;
  100. data.OrgID = parent.OrgID;
  101. data.News_Pic = oCurData.News_Pic;
  102. data.PicShowId = oCurData.PicShowId;
  103. return g_api.ConnectLite(sProgramId, ComFn.GetUpd, data, function (res) {
  104. if (res.RESULT) {
  105. bRequestStorage = false;
  106. showMsgAndGo(i18next.t("message.Modify_Success"), sQueryPrgId); //╠message.Modify_Success⇒修改成功╣
  107. }
  108. else {
  109. showMsg(i18next.t("message.Modify_Failed") + '<br>' + res.MSG, 'error');// ╠message.Modify_Failed⇒修改失敗╣
  110. }
  111. }, function () {
  112. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  113. });
  114. },
  115. /**
  116. * 資料刪除
  117. * @return {Object} ajax 對象
  118. */
  119. fnDel = function () {
  120. return g_api.ConnectLite(sProgramId, ComFn.GetDel, { Id: sDataId }, function (res) {
  121. if (res.RESULT) {
  122. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  123. }
  124. else {
  125. showMsg(i18next.t("message.Delete_Failed") + '<br>' + res.MSG, 'error');// ╠message.Delete_Failed⇒刪除失敗╣
  126. }
  127. }, function () {
  128. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  129. });
  130. },
  131. /**
  132. * 設定排序下拉選單
  133. * @param {String} parentid 父層id
  134. * @return {Object} ajax 對象
  135. */
  136. fnSetOrderByValueDrop = function (parentid) {
  137. var oParams = {
  138. news: {
  139. News_Show: 'Y',
  140. OrgID: parent.OrgID
  141. }
  142. };
  143. if (parentid) {
  144. oParams.news.News_LanguageType = parentid;
  145. }
  146. return CallAjax(ComFn.W_Com, ComFn.GetCount, {
  147. Params: oParams
  148. }, function (res) {
  149. var iCount = res.d;
  150. if (sAction === 'Add') {
  151. iCount++;
  152. }
  153. $('#OrderByValue').html(createOptions(iCount));
  154. if (sAction === 'Add') {
  155. $('#OrderByValue').val(1);
  156. }
  157. });
  158. },
  159. /**
  160. * 上傳附件
  161. * @param {Array} files 上傳的文件
  162. * @param {String} parentid 父層id
  163. * @param {String} finput file input id
  164. */
  165. fnUpload = function (files, parentid, finput) {
  166. var option = {},
  167. sFilesType = finput.attr('data-file');
  168. option.input = finput;
  169. option.limit = 1;
  170. option.extensions = ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'png'];
  171. option.folder = 'News';
  172. option.type = 'one';
  173. option.maxSize = 1;
  174. option.theme = 'dragdropbox' + parentid;
  175. option.parentid = parentid;
  176. if (files) {
  177. option.files = files;
  178. }
  179. if (sFilesType === 'show') {
  180. option.limit = 99;
  181. delete option.type;
  182. }
  183. fnUploadRegister(option);
  184. },
  185. /**
  186. * ToolBar 按鈕事件 function
  187. * @param {Object}inst 按鈕物件對象
  188. * @param {Object} e 事件對象
  189. * @return {Boolean} 是否停止
  190. */
  191. fnButtonHandler = function (inst, e) {
  192. var sId = inst.id;
  193. switch (sId) {
  194. case "Toolbar_Qry":
  195. break;
  196. case "Toolbar_Save":
  197. if (!$("#form_main").valid()) {
  198. oValidator.focusInvalid();
  199. return false;
  200. }
  201. if (sAction === 'Add') {
  202. fnAdd('add');
  203. }
  204. else {
  205. fnUpd();
  206. }
  207. break;
  208. case "Toolbar_ReAdd":
  209. if (!$("#form_main").valid()) {
  210. oValidator.focusInvalid();
  211. return false;
  212. }
  213. fnAdd('readd');
  214. break;
  215. case "Toolbar_Clear":
  216. clearPageVal();
  217. break;
  218. case "Toolbar_Leave":
  219. pageLeave();
  220. break;
  221. case "Toolbar_Add":
  222. break;
  223. case "Toolbar_Upd":
  224. break;
  225. case "Toolbar_Copy":
  226. break;
  227. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  228. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  229. fnDel();
  230. layer.close(index);
  231. });
  232. break;
  233. default:
  234. alert("No handle '" + sId + "'");
  235. break;
  236. }
  237. },
  238. /**
  239. * 初始化 function
  240. */
  241. init = function () {
  242. commonInit({
  243. PrgId: sProgramId,
  244. ButtonHandler: fnButtonHandler,
  245. GoTop: true
  246. });
  247. if (parent.OrgID === 'SG') {
  248. $('.picshowid').show();
  249. };
  250. $.validator.addMethod("compardate", function (value, element, parms) {
  251. if (new Date(value) < new Date($('#News_StartDete').val())) {
  252. return false;
  253. }
  254. return true;
  255. });
  256. oValidator = $("#form_main").validate();
  257. oEditor = UE.getEditor('News_Content');
  258. $('#News_LanguageType').change(function () {
  259. fnSetOrderByValueDrop(this.value);
  260. });
  261. //TE新增新類別展會花絮顯示條件 2019/04/15 Yang
  262. $('#News_Type').change(function () {
  263. if (parent.OrgID === 'TE') {
  264. $(this).val() == '02' ? $('.picshowid').show(): $('.picshowid').hide() ;
  265. }
  266. })
  267. fnSetArgDrop([
  268. {
  269. ArgClassID: 'LanCountry',
  270. Select: $('#News_LanguageType'),
  271. ShowId: true
  272. },
  273. {
  274. ArgClassID: 'News_Class',
  275. Select: $('#News_Type'),
  276. ShowId: true
  277. }
  278. ])
  279. .done(function () {
  280. fnGet();
  281. });
  282. };
  283. init();
  284. };
  285. require(['base', 'jsgrid', 'filer', 'util'], fnPageInit);