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.

508 lines
24 KiB

2 years ago
  1. 'use strict';
  2. var fnPageInit = function () {
  3. var canDo = new CanDo({
  4. /**
  5. * 修改完后是否跳轉
  6. */
  7. updateGo: false,
  8. /**
  9. * 須初始化的UEEditer 的物件ID集合
  10. */
  11. ueEditorIds: ['Introduction', 'Introduction_CN', 'Introduction_EN', 'MissionAndVision_TW', 'MissionAndVision_CN', 'MissionAndVision_EN', 'MissionAndVision_EN', 'ServiceTitle', 'ServiceTitle_CN', 'ServiceTitle_EN', 'VideoDescription', 'VideoDescription_CN', 'VideoDescription_EN', 'SettingInfo'],
  12. /**
  13. * 查詢當前資料
  14. * @param {Object} pargs CanDo 對象
  15. * @param {Object} data 當前資料實體
  16. */
  17. getOneBack: function (pargs, data) {
  18. pargs._setFormVal(data);
  19. pargs._setUEValues(data);
  20. fnGetUploadFiles(data.WebsiteLgoId, fnUpload, $('#WebsiteLogoId'));
  21. fnGetUploadFiles(data.PicShowId, fnUpload, $('#PicShowId'));
  22. fnGetUploadFiles(data.PicShowId_CN, fnUpload, $('#PicShowId_CN'));
  23. fnGetUploadFiles(data.PicShowId_EN, fnUpload, $('#PicShowId_EN'));
  24. },
  25. /**
  26. * 頁面初始化
  27. * @param {Object} pargs CanDo 對象
  28. */
  29. pageInit: function (pargs) {
  30. pargs.action = 'update';
  31. pargs._getOne();
  32. fnGridInit('Carousel', 'TW');//初始化輪播(繁中)
  33. fnGridInit('ServiceItems', 'TW');//初始化服務項目(繁中)
  34. fnGridInit('ClassicCase', 'TW');//初始化經典案例(繁中)
  35. fnGridInit('Video', 'TW');//初始化品牌影音(繁中)
  36. fnGridInit('Downloads', 'TW');//文檔下載(繁中)
  37. fnGridInit('ServiceBase', 'TW');//初始化全球服務據點(繁中)
  38. fnGridInit('Carousel', 'CN');//初始化輪播(簡中)
  39. fnGridInit('ServiceItems', 'CN');//初始化服務項目(簡中)
  40. fnGridInit('ClassicCase', 'CN');//初始化經典案例(簡中)
  41. fnGridInit('Video', 'CN');//初始化品牌影音(簡中)
  42. fnGridInit('Downloads', 'CN');//文檔下載(簡中)
  43. fnGridInit('ServiceBase', 'CN');//初始化全球服務據點(簡中)
  44. fnGridInit('Carousel', 'EN');//初始化輪播(英文)
  45. fnGridInit('ServiceItems', 'EN');//初始化服務項目(英文)
  46. fnGridInit('ClassicCase', 'EN');//初始化經典案例(英文)
  47. fnGridInit('Video', 'EN');//初始化品牌影音(英文)
  48. fnGridInit('Downloads', 'EN');//文檔下載(英文)
  49. fnGridInit('ServiceBase', 'EN');//初始化全球服務據點(英文)
  50. }
  51. }),
  52. oGrid = {},
  53. oOption = {},
  54. oBaseQueryPm = {
  55. pageIndex: 1,
  56. pageSize: parent.SysSet.GridRecords || 10,
  57. sortField: 'ParentId,OrderByValue',
  58. sortOrder: 'asc'
  59. },
  60. oLang = { 'TW': 'zh-TW', 'CN': 'zh', 'EN': 'en' },
  61. /**
  62. * 新增輪播資訊
  63. * @param {Object} args 參數
  64. * @return {Function} Ajax
  65. */
  66. fnSetInsert = function (args) {
  67. return g_api.ConnectLite(canDo.ProgramId, canDo._api.ginsert, args, function (res) {
  68. if (res.RESULT) {
  69. var oRes = res.DATA.rel;
  70. }
  71. });
  72. },
  73. /**
  74. * 修改輪播資訊
  75. * @param {Object} args 參數
  76. * @return {Function} Ajax
  77. */
  78. fnSetUpdate = function (args) {
  79. return g_api.ConnectLite(canDo.ProgramId, canDo._api.gupdate, args, function (res) {
  80. if (res.RESULT) {
  81. var oRes = res.DATA.rel;
  82. }
  83. });
  84. },
  85. /**
  86. * 刪除輪播資訊
  87. * @param {Object} args 參數
  88. * @return {Function} Ajax
  89. */
  90. fnSetDelete = function (args) {
  91. return g_api.ConnectLite(canDo.ProgramId, canDo._api.gdelete, args, function (res) {
  92. if (res.RESULT) {
  93. var oRes = res.DATA.rel;
  94. }
  95. });
  96. },
  97. /**
  98. * 抓去輪播資訊
  99. * @param {Object} args 參數
  100. * @param {String} settype 設定類別
  101. * @param {String} lang 語系
  102. * @return {Object} ajax
  103. */
  104. fnGetSetting = function (args, settype, lang) {
  105. var sKey = settype + '_' + lang,
  106. oQueryPm = {
  107. SetType: settype, LangId: oLang[lang]
  108. };
  109. $.extend(oQueryPm, oBaseQueryPm, args);
  110. return g_api.ConnectLite(canDo.ProgramId, canDo._api.getpage, oQueryPm, function (res) {
  111. if (res.RESULT) {
  112. var oRes = res.DATA.rel;
  113. if (settype === 'ClassicCase') {
  114. var saParentId = $.grep(oRes.DataList, function (item) {
  115. if (!item.ParentId) {
  116. return item;
  117. }
  118. });
  119. oOption[sKey].ParentIdHtml = createOptions(saParentId, 'Guid', 'Title');
  120. }
  121. }
  122. });
  123. },
  124. /**
  125. * Grid客戶化計價模式控件
  126. * @param {String}flag 標記
  127. * @return {HTMLElement} html 物件
  128. */
  129. fnCreateActiveInput = function (flag) {
  130. var elDiv = $('<div>'),
  131. data = [{ id: true, text: i18next.t('common.Effective') }, { id: false, text: i18next.t('common.Invalid') }];
  132. elDiv.html(createRadios(data, 'id', 'text', '~Active' + flag, flag, false, false));
  133. return elDiv;
  134. },
  135. /**
  136. * 初始化輪播
  137. * @param {String} settype 設定類別
  138. * @param {String} lang 語系
  139. */
  140. fnGridInit = function (settype, lang) {
  141. var sKey = settype + '_' + lang,
  142. saFields = [{ name: "RowIndex", title: 'common.RowNumber', align: 'center', width: 40, sorting: false }];
  143. if ('ClassicCase'.indexOf(settype) > -1) {
  144. saFields.push({
  145. name: "ParentId", title: 'common.ParentId', width: 120, type: 'select',// ╠common.ParentId⇒父層╣
  146. itemTemplate: function (val, item) {
  147. var oControl = $('<select />', {
  148. class: "form-control w100p",
  149. html: !oOption[sKey] ? '' : oOption[sKey].ParentIdHtml
  150. }).val(val);
  151. return oControl;
  152. },
  153. insertTemplate: function (val, item) {
  154. var oControl = $('<select />', {
  155. class: "form-control w100p",
  156. html: !oOption[sKey] ? '' : oOption[sKey].ParentIdHtml
  157. });
  158. setTimeout(function () { oControl.html(!oOption[sKey] ? '' : oOption[sKey].ParentIdHtml); }, 2000);
  159. return this.insertControl = oControl;
  160. },
  161. insertValue: function () {
  162. return this.insertControl.val();
  163. },
  164. editTemplate: function (val, item) {
  165. var oControl = $('<select />', {
  166. class: "form-control w100p",
  167. html: !oOption[sKey] ? '' : oOption[sKey].ParentIdHtml
  168. });
  169. return this.editControl = oControl.val(val);
  170. },
  171. editValue: function () {
  172. return this.editControl.val();
  173. }
  174. });
  175. }
  176. if ('Carousel'.indexOf(settype) === -1) {
  177. saFields.push({
  178. name: "Title", title: { 'ServiceItems': 'common.ServiceItemsName' }[settype] || 'common.Title', width: 120, type: 'text', validate: [
  179. {// ╠common.ServiceItemsName⇒服務項目名稱╣
  180. validator: 'required',// ╠common.ServiceItemsName_required⇒請輸入服務項目名稱╣ ╠common.Title_required⇒請輸入標題╣
  181. message: { 'ServiceItems': 'common.ServiceItemsName_required' }[settype] || i18next.t('common.Title_required')
  182. },
  183. {
  184. validator: 'maxLength',
  185. message: "Field value is too long",
  186. param: 200
  187. }]
  188. });
  189. }
  190. if ('ServiceItems,ClassicCase,ServiceBase'.indexOf(settype) > -1) {
  191. saFields.push({
  192. name: "IconId", title: { 'ServiceBase': 'common.StrongholdIconPic' }[settype] || 'common.IconPic', width: 120,
  193. itemTemplate: function (val, item) {//╠common.IconPic⇒圖標╣//╠common.StrongholdIconPic⇒據點圖標╣
  194. var oFileDiv = $('<div />', { class: 'file-Info' }),
  195. fileInput = $('<input />', { type: 'file', class: 'displayNone', name: 'files[]', 'multiple': 'multiple' });
  196. fnGetUploadFiles(val, fnUpload, fileInput);
  197. return oFileDiv.append(fileInput);
  198. }
  199. });
  200. }
  201. if ('ClassicCase'.indexOf(settype) > -1) {
  202. saFields.push({
  203. name: "SubIconId", title: 'common.SubIcon', width: 120,
  204. itemTemplate: function (val, item) {//╠common.SubIcon⇒圖標2╣
  205. var oFileDiv = $('<div />', { class: 'file-Info' }),
  206. fileInput = $('<input />', { type: 'file', class: 'displayNone', name: 'files[]', 'multiple': 'multiple' });
  207. fnGetUploadFiles(val, fnUpload, fileInput);
  208. return oFileDiv.append(fileInput);
  209. }
  210. });
  211. }
  212. if ('Carousel,ClassicCase,Downloads'.indexOf(settype) > -1) {
  213. saFields.push({
  214. name: "CoverId", title: { 'Carousel': 'common.CarouselPic', 'Downloads': 'common.DownLoadDocuments' }[settype] || 'common.CoverPic', width: 120, align: 'center',
  215. itemTemplate: function (val, item) {//╠common.CarouselPic⇒輪播圖片╣
  216. var oFileDiv = $('<div />', { class: 'file-Info' }),
  217. fileInput = $('<input />', { type: 'file', class: 'displayNone', name: 'files[]', 'multiple': 'multiple', 'data-file': settype });
  218. fnGetUploadFiles(val, fnUpload, fileInput);
  219. return oFileDiv.append(fileInput);
  220. }
  221. });
  222. }
  223. if ('ServiceBase,Downloads'.indexOf(settype) === -1) {
  224. saFields.push({ //╠common.Link⇒連接╣
  225. name: "Link", title: 'common.Link', width: 150, type: 'text', validate: {
  226. validator: 'maxLength',
  227. message: "Field value is too long",
  228. param: 500
  229. },
  230. itemTemplate: function (val, item) {
  231. var elLink = $('<a />', { class: 'link', 'target': '_new', text: val, href: val });
  232. return elLink;
  233. }
  234. });
  235. }
  236. if ('ServiceItems,ClassicCase,Video,ServiceBase,Downloads'.indexOf(settype) > -1) {
  237. saFields.push(
  238. {// ╠common.CenterCoordinates⇒中心坐標╣
  239. name: "Description", title: { 'ServiceBase': 'common.CenterCoordinates' }[settype] || 'common.Description', width: 150,//╠common.Description⇒描述╣
  240. itemTemplate: function (val, item) {
  241. val = val || '';
  242. return val.length > 100 ? val.substr(0, 100) + '...' : val;
  243. },
  244. insertTemplate: function (val, item) {
  245. var elControl = $('<textarea rows="3" cols="20" />', {
  246. class: "form-control w100p"
  247. });
  248. return this.insertControl = elControl;
  249. },
  250. insertValue: function () {
  251. return this.insertControl.val();
  252. },
  253. editTemplate: function (val, item) {
  254. var elControl = $('<textarea rows="3" cols="20" />', {
  255. class: "form-control w100p"
  256. });
  257. return this.editControl = elControl.val(val);
  258. },
  259. editValue: function () {
  260. return this.editControl.val();
  261. }
  262. });
  263. }
  264. if ('ServiceItems,ClassicCase,ServiceBase'.indexOf(settype) > -1) {
  265. if (settype === 'ServiceBase') {
  266. saFields.push(
  267. {// ╠common.GlobalStronghold⇒全球據點坐標╣
  268. name: "Content", title: 'common.GlobalStronghold', width: 150,
  269. insertTemplate: function (val, item) {
  270. var elControl = $('<textarea rows="3" cols="20" />', {
  271. class: "form-control w100p"
  272. });
  273. return this.insertControl = elControl;
  274. },
  275. insertValue: function () {
  276. return this.insertControl.val();
  277. },
  278. editTemplate: function (val, item) {
  279. var elControl = $('<textarea rows="3" cols="20" />', {
  280. class: "form-control w100p"
  281. });
  282. return this.editControl = elControl.val(val);
  283. },
  284. editValue: function () {
  285. return this.editControl.val();
  286. }
  287. });
  288. }
  289. else {
  290. saFields.push({
  291. name: "Content", title: { 'ServiceItems': 'common.ServiceItemsInfo' }[settype] || 'common.Info', width: 80, align: 'center',
  292. itemTemplate: function (val, item) {//╠common.CarouselPic⇒輪播圖片╣ ╠common.ServiceItemsInfo⇒服務項目明細╣ ╠common.Info⇒內容明細╣
  293. var oEdit = $('<a />', {
  294. class: 'link', text: i18next.t('common.Edit'),
  295. click: function () {
  296. layer.open({
  297. type: 1, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  298. title: i18next.t('common.Info'),
  299. area: ['960px', '600px'],//寬度
  300. shade: 0.75,//遮罩
  301. shadeClose: true,
  302. maxmin: true, //开启最大化最小化按钮
  303. id: 'layer_Info', //设定一个id,防止重复弹出
  304. offset: '50px',
  305. anim: 0,//彈出動畫
  306. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],
  307. btnAlign: 'c',//按鈕位置
  308. content: $('#UeditorInfo'),
  309. success: function (layero, index) {
  310. var iframe = layero.find('iframe').contents(),
  311. iZindex_layer = layero.css('z-index');
  312. setTimeout(function () {
  313. iframe.find('body').html(item.Content || '');
  314. }, 200);
  315. layero.find('#UE_SettingInfo').children(":first").css('z-index', iZindex_layer * 1 + 1);//為解決POP視窗ueditor上傳pop被遮擋之問題
  316. },
  317. yes: function (index, layero) {
  318. item.Content = canDo.UE_Editor.SettingInfo.getContent();
  319. fnSetUpdate(item).done(function () {
  320. layer.close(index);
  321. });
  322. },
  323. end: function () {
  324. $('#UeditorInfo').hide();
  325. }
  326. });
  327. }
  328. });
  329. return oEdit;
  330. }
  331. });
  332. }
  333. }
  334. saFields.push(
  335. {//╠common.Styles⇒坐標樣式╣
  336. name: "Memo", title: { 'ServiceBase': 'common.Styles' }[settype] || 'common.Memo', width: 150,
  337. insertTemplate: function (val, item) {
  338. var elControl = $('<textarea rows="3" cols="20" />', {
  339. class: "form-control w100p"
  340. });
  341. return this.insertControl = elControl;
  342. },
  343. insertValue: function () {
  344. return this.insertControl.val();
  345. },
  346. editTemplate: function (val, item) {
  347. var elControl = $('<textarea rows="3" cols="20" />', {
  348. class: "form-control w100p"
  349. });
  350. return this.editControl = elControl.val(val);
  351. },
  352. editValue: function () {
  353. return this.editControl.val();
  354. }
  355. },
  356. {
  357. name: "OrderByValue", title: 'common.OrderByValue', width: 80, align: 'center',
  358. itemTemplate: function (val, item) {
  359. return this._createSelect = $("<select>", {
  360. class: 'w70',
  361. html: createOptions(item.OrderCount),
  362. change: function () {
  363. var sOldValue = val,
  364. sNewValue = this.value;
  365. g_api.ConnectLite(canDo.ProgramId, canDo._api.order, {
  366. Id: item.Guid,
  367. OldOrderByValue: sOldValue,
  368. NewOrderByValue: sNewValue
  369. }, function (res) {
  370. if (res.RESULT) {
  371. oGrid[sKey].openPage(1);
  372. }
  373. });
  374. }
  375. }).val(val);
  376. }
  377. },
  378. {
  379. name: "Active", title: 'common.Active', width: 100, align: 'center',
  380. itemTemplate: function (val, item) {//╠common.Active⇒有效狀態╣
  381. return val.toString() === "true" ? i18next.t('common.Effective') : i18next.t('common.Invalid');
  382. },
  383. insertTemplate: function (val, item) {
  384. var elControl = fnCreateActiveInput('add' + sKey);
  385. setTimeout(function () {
  386. elControl.find('label:first').click();
  387. canDo._uniformInit(elControl);
  388. }, 100);
  389. return this.insertControl = elControl;
  390. },
  391. insertValue: function () {
  392. return this.insertControl.find(':input:checked').val();
  393. },
  394. editTemplate: function (val, item) {
  395. var elControl = fnCreateActiveInput('edit' + sKey);
  396. setTimeout(function () {
  397. elControl.find(':input[value="' + val + '"]').click();
  398. canDo._uniformInit(elControl);
  399. }, 100);
  400. return this.editControl = elControl;
  401. },
  402. editValue: function () {
  403. return this.editControl.find(':input:checked').val();
  404. }
  405. },
  406. {
  407. type: "control", width: 50
  408. });
  409. $('#jsGrid_' + sKey).jsGrid({
  410. width: "100%",
  411. height: "auto",
  412. autoload: true,
  413. pageLoading: true,
  414. inserting: true,
  415. editing: true,
  416. sorting: true,
  417. paging: true,
  418. pageIndex: 1,
  419. pageSize: 1000,
  420. pageButtonCount: parent.SysSet.GridPages || 15,
  421. invalidMessage: '输入的数据无效!',
  422. confirmDeleting: true,
  423. deleteConfirm: "確定要刪除嗎?",
  424. pagePrevText: "<",
  425. pageNextText: ">",
  426. pageFirstText: "<<",
  427. pageLastText: ">>",
  428. rowClick: function (args) {
  429. },
  430. fields: saFields,
  431. controller: {
  432. loadData: function (args) {
  433. return fnGetSetting(args, settype, lang);
  434. },
  435. insertItem: function (args) {
  436. args.SetType = settype;
  437. args.LangId = oLang[lang];
  438. args.IconId = guid();
  439. args.SubIconId = guid();
  440. args.CoverId = guid();
  441. args.SubCoverId = guid();
  442. var saCurrent = [];
  443. if (oGrid[sKey].data.length > 0) {
  444. saCurrent = $.grep(oGrid[sKey].data, function (item) {
  445. if (args.ParentId) {
  446. return item.ParentId === args.ParentId;
  447. } else {
  448. return !item.ParentId;
  449. }
  450. });
  451. }
  452. args.OrderByValue = saCurrent.length + 1;
  453. return fnSetInsert(args);
  454. },
  455. updateItem: function (args) {
  456. fnSetUpdate(args);
  457. },
  458. deleteItem: function (args) {
  459. return fnSetDelete(args);
  460. }
  461. },
  462. onInit: function (args) {
  463. if (settype === 'ClassicCase' && !oOption[sKey]) {
  464. oOption[sKey] = {};
  465. }
  466. oGrid[sKey] = args.grid;
  467. }
  468. });
  469. },
  470. /**
  471. * 上傳附件
  472. * @param {Array} files 當前文件
  473. * @param {String} parentid 父層id
  474. * @param {String} finput file input id
  475. */
  476. fnUpload = function (files, parentid, finput) {
  477. var option = {},
  478. sFilesType = finput.attr('data-file');
  479. option.input = finput;
  480. option.limit = 1;
  481. option.type = 'one';
  482. option.theme = 'dragdropbox' + parentid;
  483. option.parentid = parentid;
  484. option.extensions = ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'png', 'svg'];
  485. option.folder = 'WebSiteSetup';
  486. if (files) {
  487. option.files = files;
  488. }
  489. if (sFilesType === 'Downloads') {
  490. delete option.extensions;
  491. }
  492. else if (sFilesType === 'PicShowId') {
  493. option.limit = 99;
  494. delete option.type;
  495. }
  496. fnUploadRegister(option);
  497. };
  498. };
  499. require(['base', 'filer', 'jsgrid', 'cando'], fnPageInit);