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.

1125 lines
52 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sAction = getUrlParam('Action') || 'Add',
  5. sDataId = getUrlParam('SN'),
  6. sTab = getUrlParam('Tab'),
  7. sCheckId = sDataId,
  8. bRefresh = false,
  9. fnPageInit = function () {
  10. var oGrid = null,
  11. oForm = $('#form_main'),
  12. oGrid1 = null,
  13. oValidator = null,
  14. oCurData = {},
  15. saGridData = [],
  16. saState = [],
  17. saHalls = [],
  18. oBaseQueryPm = {
  19. pageIndex: 1,
  20. pageSize: parent.SysSet.GridRecords || 10,
  21. sortField: 'CustomerCName',
  22. sortOrder: 'asc'
  23. },
  24. /**
  25. * 獲取資料
  26. * @return {Object} Ajax 物件
  27. */
  28. fnGet = function () {
  29. if (sDataId) {
  30. $('#litab3').show();
  31. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  32. {
  33. Guid: sDataId
  34. },
  35. function (res) {
  36. if (res.RESULT) {
  37. var oRes = res.DATA.rel;
  38. oCurData = oRes;
  39. $('.TransferResult').show();
  40. if (oRes.IsTransfer === 'N') {
  41. $('#TransferResult').text(i18next.t("common.Transfer_No")).css('color', 'red');// ╠common.Transfer_No⇒未拋轉╣
  42. }
  43. else {// ╠common.Transfer_No⇒已拋轉╣ ╠common.TransferDate⇒最後拋轉時間╣
  44. $('#TransferResult').text(i18next.t("common.Transfer_Yes") + '(' + i18next.t("common.TransferDate") + ':' + newDate(oRes.LastTransfer_Time) + ')').css('color', 'green');
  45. }
  46. }
  47. });
  48. }
  49. else {
  50. $('#litab3').hide();
  51. oCurData.LogoFileId = guid();
  52. fnUpload();
  53. return $.Deferred().resolve().promise();
  54. }
  55. },
  56. /**
  57. * 新增資料
  58. * @param {String} sFlag 新增或儲存後新增
  59. */
  60. fnAdd = function (sFlag) {
  61. var data = getFormSerialize(oForm);
  62. data = packParams(data);
  63. data.OrgID = parent.OrgID;
  64. data.LogoFileId = oCurData.LogoFileId;
  65. data.IsTransfer = 'N';
  66. //data.ExhibitionCode = 'SerialNumber|' + parent.UserInfo.OrgID + '|' + (parent.UserInfo.OrgID === 'TE' ? '' : parent.UserInfo.OrgID) + '|MinYear|3||';
  67. if (!data.ExhibitionDate) {
  68. delete data.ExhibitionDateStart;
  69. delete data.ExhibitionDateEnd;
  70. }
  71. else {
  72. data.ExhibitionDateStart = $.trim(data.ExhibitionDate.split('~')[0]);
  73. data.ExhibitionDateEnd = $.trim(data.ExhibitionDate.split('~')[1]);
  74. }
  75. delete data.ExhibitionDate;
  76. delete data.file_hidden;
  77. if (!data.ShelfTime_Home) {
  78. delete data.ShelfTime_Home;
  79. }
  80. if (!data.ShelfTime_Abroad) {
  81. delete data.ShelfTime_Abroad;
  82. }
  83. g_api.ConnectLite(Service.com, ComFn.GetSerial, {
  84. Type: parent.UserInfo.OrgID === 'TE' ? '' : parent.UserInfo.OrgID,
  85. Flag: 'MinYear',
  86. Len: 3,
  87. Str: '',
  88. AddType: '',
  89. PlusType: ''
  90. }, function (res) {
  91. if (res.RESULT) {
  92. data.ExhibitionCode = res.DATA.rel;
  93. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  94. Params: { exhibition: data }
  95. }, function (res1) {
  96. if (res1.d > 0) {
  97. bRequestStorage = false;
  98. if (sFlag === 'add') {
  99. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  100. Type: '',
  101. Params: {
  102. exhibition: {
  103. ExhibitionCode: data.ExhibitionCode
  104. },
  105. }
  106. }, function (res2) {
  107. var oRes = $.parseJSON(res2.d);
  108. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&SN=' + oRes.SN); // ╠message.Save_Success⇒新增成功╣
  109. });
  110. }
  111. else {
  112. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  113. }
  114. if (data.ExhibitionDateStart && data.ExhibitionDateEnd) {
  115. //如果展覽時間不為空的話就同步更新至行事曆和outlook中
  116. fnSynChronousCalendar(data);
  117. }
  118. }
  119. else {
  120. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  121. }
  122. }, function () {
  123. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  124. });
  125. }
  126. else {
  127. showMsg(i18next.t('message.CreateBill_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CreateBill_Failed⇒帳單新增失敗╣
  128. }
  129. }, function () {
  130. showMsg(i18next.t('message.CreateBill_Failed'), 'error'); // ╠message.CreateBill_Failed⇒帳單新增失敗╣
  131. });
  132. },
  133. /**
  134. * 檢查名稱
  135. */
  136. fnCheckNameThenAction = function (Type) {
  137. return g_api.ConnectLite(sProgramId, 'CheckExhibitionName', {
  138. Type: Type,
  139. SN: getUrlParam('SN') ,
  140. Exhibitioname_TW: $('#Exhibitioname_TW').val() ? $('#Exhibitioname_TW').val(): "",
  141. ExhibitioShotName_TW: $('#ExhibitioShotName_TW').val() ? $('#ExhibitioShotName_TW').val() : ""
  142. }, function (res) {
  143. if (!res.MSG) {
  144. switch (Type) {
  145. case "add":
  146. case "readd":
  147. fnAdd(Type);
  148. break;
  149. case "upd":
  150. fnUpd();
  151. break;
  152. default:
  153. break;
  154. }
  155. }
  156. else {
  157. showMsg(res.MSG, 'error');
  158. }
  159. }, function () {
  160. showMsg("未知錯誤,請聯絡資訊人員", 'error');// ╠message.Transfer_Failed⇒拋轉失敗╣
  161. });
  162. },
  163. /**
  164. * 修改資料
  165. */
  166. fnUpd = function () {
  167. var data = getFormSerialize(oForm);
  168. data = packParams(data, 'upd');
  169. data.LogoFileId = oCurData.LogoFileId;
  170. if (!data.ExhibitionDate) {
  171. delete data.ExhibitionDateStart;
  172. delete data.ExhibitionDateEnd;
  173. }
  174. else {
  175. data.ExhibitionDateStart = $.trim(data.ExhibitionDate.split('~')[0]);
  176. data.ExhibitionDateEnd = $.trim(data.ExhibitionDate.split('~')[1]);
  177. }
  178. delete data.ExhibitionDate;
  179. delete data.file_hidden;
  180. if (!data.ShelfTime_Home) {
  181. delete data.ShelfTime_Home;
  182. }
  183. if (!data.ShelfTime_Abroad) {
  184. delete data.ShelfTime_Abroad;
  185. }
  186. if (!data.ExhibitionCode) {
  187. data.ExhibitionCode = 'SerialNumber|' + parent.UserInfo.OrgID + '||MinYear|3||';
  188. }
  189. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  190. Params: {
  191. exhibition: {
  192. values: data,
  193. keys: { SN: sDataId }
  194. }
  195. }
  196. }, function (res) {
  197. if (res.d > 0) {
  198. bRequestStorage = false;
  199. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  200. if (window.bLeavePage) {
  201. setTimeout(function () {
  202. pageLeave();
  203. }, 1000);
  204. }
  205. }
  206. else {
  207. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  208. }
  209. }, function () {
  210. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  211. });
  212. },
  213. /**
  214. * 資料刪除
  215. */
  216. fnDel = function () {
  217. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  218. Params: {
  219. exhibition: {
  220. SN: sDataId
  221. }
  222. }
  223. }, function (res) {
  224. if (res.d > 0) {
  225. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  226. }
  227. else {
  228. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  229. }
  230. }, function () {
  231. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  232. });
  233. },
  234. /**
  235. * 設定國家下拉選單
  236. */
  237. setStateDrop = function () {
  238. return g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  239. ArgClassID: 'Area',
  240. ParentID: '',
  241. LevelOfArgument: 1
  242. }, function (res) {
  243. if (res.RESULT) {
  244. saState = res.DATA.rel;
  245. if (saState.length > 0) {
  246. $('#State').html(createOptions(saState, 'id', 'text', true)).change(function () {
  247. setExhibitionAddressDrop();
  248. });
  249. select2Init($('#State').parent());
  250. if (parent.OrgID === 'TG' && sAction === 'Add') {
  251. $('#State').val('TWN');
  252. setExhibitionAddressDrop();
  253. }
  254. }
  255. else {
  256. $('#State').html(createOptions([]));
  257. }
  258. }
  259. });
  260. },
  261. /**
  262. * 設定展覽地點下拉選單
  263. */
  264. setExhibitionAddressDrop = function () {
  265. var sState = $('#State').val() || '';
  266. g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  267. ArgClassID: 'Area',
  268. ParentID: sState,
  269. LevelOfArgument: 2
  270. }, function (res) {
  271. if (res.RESULT) {
  272. saHalls = res.DATA.rel;
  273. if (saHalls.length > 0) {
  274. $('#ExhibitionAddress').html(createOptions(saHalls, 'id', 'text', true)).change(function () {
  275. var sExhibitionAddressId = this.value;
  276. if (sExhibitionAddressId) {
  277. var oState = Enumerable.From(saHalls).Where(function (e) { return e.id === sExhibitionAddressId; }).First();
  278. $('#ExhibitionAddress_CN').text(oState.text_cn);
  279. $('#ExhibitionAddress_EN').text(oState.text_en);
  280. }
  281. else {
  282. $('#ExhibitionAddress_CN').text('');
  283. $('#ExhibitionAddress_EN').text('');
  284. }
  285. });
  286. if (oCurData.ExhibitionAddress) {
  287. $('#ExhibitionAddress').val(oCurData.ExhibitionAddress);
  288. if (!$('#ExhibitionAddress').val()) {
  289. $('#ExhibitionAddress_CN').text('');
  290. $('#ExhibitionAddress_EN').text('');
  291. }
  292. }
  293. }
  294. else {
  295. $('#ExhibitionAddress').html(createOptions([]));
  296. }
  297. }
  298. });
  299. },
  300. /**
  301. * 設定費用規則下拉選單
  302. */
  303. setCostRulesDrop = function () {
  304. return CallAjax(ComFn.W_Com, ComFn.GetList, {
  305. Type: '', Params: {
  306. exhibitionrules: {
  307. OrgID: parent.OrgID
  308. }
  309. }
  310. }, function (res) {
  311. var saData = JSON.parse(res.d);
  312. if (saData) {
  313. $('#CostRulesId').html(createOptions(saData, 'Guid', 'Title'));
  314. }
  315. });
  316. },
  317. /**
  318. * 上傳附件
  319. * @param {Array}files 要綁定的html物件
  320. */
  321. fnUpload = function (files) {
  322. var option = {};
  323. option.input = $('#fileInput');
  324. option.theme = 'dragdropbox';
  325. option.folder = 'Exhibition';
  326. option.type = 'one';
  327. option.extensions = ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'png'];
  328. option.limit = 1;
  329. option.parentid = oCurData.LogoFileId;
  330. if (files) {
  331. option.files = files;
  332. }
  333. fnUploadRegister(option);
  334. },
  335. /**
  336. * 拋轉文中
  337. */
  338. fnTransfer = function () {
  339. g_api.ConnectLite('Exhibition', 'Transfer', {
  340. SN: oCurData.SN
  341. }, function (res) {
  342. if (res.RESULT) {
  343. showMsg(i18next.t("message.Transfer_Success"), 'success'); // ╠message.Transfer_Success⇒拋轉完成╣
  344. parent.msgs.server.pushTransfer(parent.OrgID, parent.UserID, oCurData.ExhibitionCode, 3);
  345. fnGet();
  346. }
  347. else {
  348. showMsg(i18next.t('message.Transfer_Failed') + '<br>' + res.MSG, 'error');// ╠message.Transfer_Failed⇒拋轉失敗╣
  349. }
  350. }, function () {
  351. showMsg(i18next.t("message.Transfer_Failed"), 'error');// ╠message.Transfer_Failed⇒拋轉失敗╣
  352. });
  353. },
  354. /**
  355. * 抓去參加展覽列表資料
  356. * @param {String} flag 是否匯出
  357. * @return {Object} ajax物件
  358. */
  359. fnGetGridData = function (flag) {
  360. if (sDataId) {
  361. return g_api.ConnectLite(sProgramId, 'GetCustomers', {
  362. SN: sDataId,
  363. Flag: flag
  364. }, function (res) {
  365. if (res.RESULT) {
  366. if (flag === 'export') {
  367. DownLoadFile(res.DATA.rel, oCurData.Exhibitioname_TW);
  368. }
  369. else {
  370. saGridData = res.DATA.rel;
  371. }
  372. }
  373. });
  374. }
  375. else {
  376. return $.Deferred().resolve().promise();
  377. }
  378. },
  379. /**
  380. * 抓去參加展覽列表資料
  381. * @param {String} flag 是否匯出
  382. * @return {Object} ajax物件
  383. */
  384. fnGetGridData1 = function (args) {
  385. var oQueryPm = {};
  386. $.extend(oQueryPm, oBaseQueryPm, args);
  387. if (sDataId) {
  388. oQueryPm.SN = sDataId;
  389. return g_api.ConnectLite(sProgramId, 'GetImportCustomers', oQueryPm);
  390. }
  391. else {
  392. return $.Deferred().resolve().promise();
  393. }
  394. },
  395. /**
  396. * 刪除單筆列表資料
  397. * @param {String} id 廠商id
  398. * @return {Object} ajax 物件
  399. */
  400. fnDelGrid1Data = function (id) {
  401. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  402. Params: {
  403. importcustomers: {
  404. guid: id
  405. }
  406. }
  407. }, function (res) {
  408. if (res.d > 0) {
  409. showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
  410. oGrid1.loadData();
  411. }
  412. else {
  413. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  414. }
  415. }, function () {
  416. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  417. });
  418. },
  419. /**
  420. * 轉正式資料
  421. * @param {Object} item 單筆廠商資料
  422. * @return {Object} ajax 物件
  423. */
  424. fnTransferToFormal = function (item) {
  425. layer.open({
  426. type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  427. title: i18next.t('common.CustomerTransferToFormal'),// ╠common.CustomerTransferToFormal⇒匯入廠商轉正╣
  428. area: ['1200px', '600px'],//寬度
  429. shade: 0.75,//遮罩
  430. maxmin: true, //开启最大化最小化按钮
  431. id: 'layer_TransferToFormal', //设定一个id,防止重复弹出
  432. anim: 0,//彈出動畫
  433. btnAlign: 'c',//按鈕位置
  434. content: '../Crm/Customers_Upd.html?Action=Add&From=Appoint&Flag=Pop',
  435. success: function (layero, index) {
  436. //layer.full(index); //弹出即全屏
  437. var iframe = layero.find('iframe').contents();
  438. iframe.find('#CustomerCName').val(item.CustomerCName);
  439. iframe.find('#CustomerEName').val(item.CustomerEName);
  440. iframe.find('#UniCode').val(item.UniCode);
  441. iframe.find('#Telephone').val(item.Telephone);
  442. iframe.find('#Email').val(item.Email);
  443. iframe.find('#Address').val(item.Address);
  444. iframe.find('#InvoiceAddress').val(item.InvoiceAddress);
  445. iframe.find('body').attr('PopId', item.guid);
  446. setTimeout(function () {
  447. iframe.find('.plustemplkey ').trigger('click');
  448. var _input = iframe.find('#table_box').find(':input');
  449. _input.eq(0).val(item.Contactor);
  450. _input.eq(2).val(item.Telephone);
  451. _input.eq(5).val(item.Email);
  452. setTimeout(function () {
  453. _input.eq(0).trigger('click');
  454. _input.eq(2).trigger('click');
  455. _input.eq(5).trigger('click');
  456. }, 500);
  457. }, 1000);
  458. },
  459. end: function () {
  460. if (bRefresh) {
  461. bRefresh = false;
  462. oGrid1.loadData();
  463. }
  464. }
  465. });
  466. },
  467. /**
  468. * 匯入廠商資料
  469. */
  470. fnImportCusList = function () {
  471. $('#importfile').val('').off('change').on('change', function () {
  472. if (this.value.indexOf('.xls') > -1 || this.value.indexOf('.xlsx') > -1) {
  473. var sFileId = guid(),
  474. sFileName = this.value;
  475. $.ajaxFileUpload({
  476. url: '/Controller.ashx?action=importfile&FileId=' + sFileId,
  477. secureuri: false,
  478. fileElementId: 'importfile',
  479. success: function (data, status) {
  480. g_api.ConnectLite(sProgramId, 'ImportCustomers', {
  481. FileId: sFileId,
  482. FileName: sFileName,
  483. SN: sDataId
  484. }, function (res) {
  485. if (res.RESULT) {
  486. oGrid1.loadData();
  487. }
  488. else {
  489. showMsg(i18next.t('message.ProgressError') + '<br>' + res.MSG, 'error'); // ╠message.ProgressError⇒資料處理異常╣
  490. }
  491. }, function () {
  492. showMsg(i18next.t("message.ProgressError"), 'error'); // ╠message.ProgressError⇒資料處理異常╣
  493. });
  494. },
  495. error: function (data, status, e) {
  496. showMsg(i18next.t("message.ProgressError"), 'error'); // ╠message.ProgressError⇒資料處理異常╣
  497. }
  498. });
  499. bRequestStorage = true;
  500. }
  501. else {
  502. showMsg(i18next.t("message.FileTypeError"), 'error'); // ╠message.FileTypeError⇒文件格式錯誤╣
  503. }
  504. }).click();
  505. },
  506. /**
  507. * 匯入廠商資料匯出
  508. */
  509. fnExportCusList = function () {
  510. g_api.ConnectLite(sProgramId, 'ExportCustomers', {
  511. SN: sDataId
  512. }, function (res) {
  513. if (res.RESULT) {
  514. DownLoadFile(res.DATA.rel);
  515. }
  516. });
  517. },
  518. /**
  519. * 新增匯入客戶
  520. * @param {Object}data 序列化資料
  521. */
  522. fnAddCustomers = function (data) {
  523. data.ExhibitionNO = sDataId;
  524. g_api.ConnectLite(sProgramId, 'InsertImportCustomers', data, function (res) {
  525. if (res.RESULT) {
  526. oGrid1.loadData();
  527. showMsg(i18next.t("message.Save_Success"), 'success'); // ╠message.Save_Success⇒新增成功╣
  528. }
  529. else {
  530. showMsg(res.MSG, 'error');
  531. }
  532. }, function () {
  533. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  534. });
  535. },
  536. /**
  537. * 修改資料
  538. * @param {Object}data 序列化資料
  539. */
  540. fnUpdCustomers = function (data) {
  541. data = packParams(data, 'upd');
  542. delete data.Exhibitioname_TW;
  543. delete data.Exhibitioname_EN;
  544. data = removeNull(data);
  545. g_api.ConnectLite(sProgramId, 'UpdImportCustomers', data, function (res) {
  546. if (res.RESULT) {
  547. bRequestStorage = false;
  548. showMsg(i18next.t("message.Modify_Success"), 'success'); // ╠message.Modify_Success⇒修改成功╣
  549. }
  550. else {
  551. showMsg(res.MSG, 'error');
  552. }
  553. }, function () {
  554. showMsg(i18next.t("message.Modify_Failed"), 'error'); // ╠message.Modify_Failed⇒修改失敗╣
  555. });
  556. },
  557. /**
  558. * 目的 對應正式客戶
  559. * @param {String}item 預約單資料
  560. */
  561. fnCorrespondFormalCus = function (item) {
  562. layer.open({
  563. type: 1, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  564. title: i18next.t("common.CorrespondFormalCus"), // ╠common.CorrespondImpCus⇒對應正式客戶╣
  565. area: '640px;',//寬度
  566. shade: 0.75,//遮罩
  567. closeBtn: 1,
  568. //maxmin: true, //开启最大化最小化按钮
  569. id: 'layer_Correspond', //设定一个id,防止重复弹出
  570. offset: '100px',//右下角弹出
  571. anim: 0,//彈出動畫
  572. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  573. btnAlign: 'c',//按鈕位置
  574. content: '<style>.select2-container{z-index: 39891015;}</style><div class="form-group">\
  575. <div class="col-sm-12">\
  576. <select class= "form-control w95p" id="CustomerId" name="CustomerId"></select>\
  577. </div>\
  578. </div >',
  579. success: function (layero, index) {
  580. g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
  581. if (res.RESULT) {
  582. var saList = res.DATA.rel;
  583. var sOptions = createOptions(saList, 'id', 'text');
  584. $('#CustomerId').html(sOptions).select2();
  585. }
  586. });
  587. transLang(layero);
  588. },
  589. yes: function (index, layero) {
  590. var sCustomerId = $('#CustomerId').val();
  591. if (!sCustomerId) {
  592. showMsg(i18next.t('message.SelectFormalCus'));//╠message.SelectFormalCus⇒請選擇對應的客戶╣
  593. return false;
  594. }
  595. return g_api.ConnectLite('Exhibition_Upd', 'UpdateCustomerTag', {//匯入費用項目
  596. PrevId: item.guid,
  597. AfterId: sCustomerId
  598. }, function (res) {
  599. if (res.DATA.rel) {
  600. oGrid1.loadData();
  601. showMsg(i18next.t("message.Correspond_Success"), 'success'); //╠message.Correspond_Success⇒對應成功╣
  602. layer.close(index);
  603. }
  604. else {
  605. showMsg(i18next.t("message.Correspond_Failed"), 'error');//╠message.Correspond_Failed⇒對應失敗╣
  606. }
  607. });
  608. }
  609. });
  610. },
  611. /**
  612. * 同步新更新行事曆和outlook
  613. * @param {Object}_data 序列化資料
  614. */
  615. fnSynChronousCalendar = function (_data) {
  616. var data = {};
  617. data.CalType = '04';//展覽
  618. data.Title = _data.ExhibitioShotName_TW;
  619. data.Description = _data.Exhibitioname_TW + '(' + _data.Exhibitioname_EN + ') ' + _data.Memo;
  620. data.StartDate = _data.ExhibitionDateStart;
  621. data.EndDate = _data.ExhibitionDateEnd;
  622. data.Color = parent.UserInfo.CalColor;
  623. data.RelationId = _data.ExhibitionCode;
  624. data.GroupMembers = '';
  625. data.Importment = 'M';
  626. data.OpenMent = 'C';
  627. data.AllDay = '0';
  628. g_api.ConnectLite('Calendar', ComFn.GetAdd, data,
  629. function (res) {
  630. if (res.RESULT) {
  631. var sNo = res.DATA.rel;
  632. if (parent.Outklook) {
  633. outlookAPI(outlook.Calendar_Add, {
  634. NO: sNo,
  635. ResponseRequested: false
  636. });
  637. }
  638. }
  639. });
  640. },
  641. /**
  642. * ToolBar 按鈕事件 function
  643. * @param {Object}inst 按鈕物件對象
  644. * @param {Object} e 事件對象
  645. */
  646. fnButtonHandler = function (inst, e) {
  647. var sId = inst.id;
  648. switch (sId) {
  649. case "Toolbar_Qry":
  650. break;
  651. case "Toolbar_Save":
  652. $('#file_hidden').val($('li.jFiler-item').length || '');
  653. if (!$("#form_main").valid()) {
  654. oValidator.focusInvalid();
  655. return;
  656. }
  657. if (sAction === 'Add') {
  658. fnCheckNameThenAction('add');//fnAdd('add');
  659. }
  660. else {
  661. fnCheckNameThenAction('upd');//fnUpd();
  662. }
  663. break;
  664. case "Toolbar_ReAdd":
  665. $('#file_hidden').val($('li.jFiler-item').length || '');
  666. if (!$("#form_main").valid()) {
  667. oValidator.focusInvalid();
  668. return;
  669. }
  670. fnCheckNameThenAction('readd'); // fnAdd('readd');
  671. break;
  672. case "Toolbar_Clear":
  673. clearPageVal();
  674. break;
  675. case "Toolbar_Leave":
  676. pageLeave();
  677. break;
  678. case "Toolbar_Add":
  679. break;
  680. case "Toolbar_Upd":
  681. break;
  682. case "Toolbar_Copy":
  683. break;
  684. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  685. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  686. fnDel();
  687. layer.close(index);
  688. });
  689. break;
  690. case "Toolbar_Imp":
  691. break;
  692. case "Toolbar_Transfer":
  693. fnTransfer();
  694. break;
  695. default:
  696. alert("No handle '" + sId + "'");
  697. break;
  698. }
  699. },
  700. /**
  701. * 初始化 function
  702. */
  703. init = function () {
  704. var saCusBtns = null;
  705. $('#State,#Industry,#ExhibitionDate').prop('required', true);
  706. $('.ShowNames').hide();
  707. if (parent.OrgID === 'TG') {
  708. $('#CostRulesId,#State,#ExhibitionAddress,#ExhibitionDate,#file_hidden').prop('required', true);
  709. $('#notte').show();
  710. $('.simp-box').hide();
  711. }
  712. else {
  713. $('.costrules').hide();
  714. }
  715. if (sAction === 'Upd') {
  716. saCusBtns = [{
  717. id: 'Toolbar_Transfer',
  718. value: 'common.Toolbar_Transfer'// ╠common.Toolbar_Transfer⇒拋轉╣
  719. }];
  720. }
  721. commonInit({
  722. PrgId: sProgramId,
  723. ButtonHandler: fnButtonHandler,
  724. Buttons: saCusBtns,
  725. GoTop: true,
  726. tabClick: function (el) {
  727. switch (el.id) {
  728. case 'litab2':
  729. if (!$(el).data('action')) {
  730. fnGetGridData().done(function () {
  731. oGrid.loadData();
  732. if (saGridData.length > 0 && (parent.UserInfo.roles.indexOf('Admin') > -1 || parent.UserInfo.roles.indexOf('Manager') > -1)) {
  733. $('.export').show();
  734. $('#Export_CusList').on('click', function () {
  735. fnGetGridData('export');
  736. });
  737. }
  738. });
  739. }
  740. break;
  741. case 'litab3':
  742. if (!$(el).data('action')) {
  743. oGrid1.loadData();
  744. }
  745. break;
  746. }
  747. $(el).data('action', true);
  748. }
  749. });
  750. $.whenArray([
  751. fnGet(),
  752. setStateDrop(),
  753. setExhibitionAddressDrop(),
  754. setCostRulesDrop(),
  755. fnSetArgDrop([
  756. {
  757. OrgID: 'TE',
  758. ArgClassID: 'ExhibClass',
  759. Select: $('#Industry'),
  760. ShowId: true
  761. }
  762. ])
  763. ])
  764. .done(function (res) {
  765. if (res && res[0].RESULT === 1) {
  766. var oRes = res[0].DATA.rel,
  767. sDateRange = '';
  768. oCurData = oRes;
  769. oCurData.LogoFileId = oCurData.LogoFileId || guid();
  770. setFormVal(oForm, oCurData);
  771. if (oCurData.ExhibitionDateStart) {
  772. sDateRange = newDate(oCurData.ExhibitionDateStart, 'date', true) + ' ~ ' + newDate(oCurData.ExhibitionDateEnd, 'date', true);
  773. }
  774. if (sTab) {
  775. $('#litab3 a').click();
  776. }
  777. if (oRes.IsShowWebSite === 'N') {
  778. $('.showwebsite').slideUp();
  779. }
  780. $('#State').val(oRes.State).trigger('change');
  781. $('#ExhibitionDate').val(sDateRange);
  782. $('#ExhibitionAddress_CN').text(oCurData.ExhibitionAddress_CN);
  783. $('#ExhibitionAddress_EN').text(oCurData.ExhibitionAddress_EN);
  784. setNameById().done(function () {
  785. getPageVal();//緩存頁面值,用於清除
  786. });
  787. fnGetUploadFiles(oCurData.LogoFileId, fnUpload);
  788. }
  789. select2Init();
  790. $('[name=IsShowWebSite]').click(function () {
  791. if (this.value === 'N') {
  792. $('#ExhibitionDate,#CostRulesId,#ExhibitionAddress,#file_hidden').removeAttr('required');
  793. $('.showwebsite').slideUp();
  794. }
  795. else {
  796. $('#ExhibitionDate,#CostRulesId,#ExhibitionAddress,#file_hidden,#CostRulesId').attr('required', true);
  797. $('.showwebsite').slideDown();
  798. }
  799. });
  800. //是否顯示於網站,值為'N'收起選項與移除required
  801. if (oCurData.IsShowWebSite === 'N') {
  802. $('#sub_box1').slideUp();
  803. $('[name=IsShowWebSite][value="N"]').click();
  804. }
  805. });
  806. oValidator = $("#form_main").validate({
  807. ignore: ''
  808. });
  809. $('#ExhibitionDate').dateRangePicker(
  810. {
  811. language: 'zh-TW',
  812. separator: ' ~ ',
  813. format: 'YYYY/MM/DD',
  814. autoClose: true
  815. }).bind('datepicker-change', function (e, r) {
  816. try {
  817. var dShelfTime_Home = r.date2.dateAdd('d', -15),
  818. dShelfTime_Abroad = new Date(newDate(r.date2, 'date')).dateAdd('d', -15);
  819. $('#ShelfTime_Home').val(newDate(dShelfTime_Home, 'date'));
  820. $('#ShelfTime_Abroad').val(newDate(dShelfTime_Abroad, 'date'));
  821. } catch (e) { }
  822. });
  823. $('#Exhibitioname_TW').on('blur', function () {
  824. $('#Exhibitioname_CN').val(simplized(this.value));
  825. });
  826. $('#Exhibitioname_CN').on('blur', function () {
  827. $('#Exhibitioname_TW').val(traditionalized(this.value));
  828. });
  829. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 150;
  830. $("#jsGrid").jsGrid({
  831. width: "100%",
  832. height: "auto",
  833. autoload: true,
  834. filtering: false,
  835. pageLoading: true,
  836. inserting: false,
  837. editing: false,
  838. sorting: false,
  839. paging: false,
  840. pageIndex: 1,
  841. pageSize: parent.SysSet.GridRecords || 10,
  842. confirmDeleting: true,
  843. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  844. pagePrevText: "<",
  845. pageNextText: ">",
  846. pageFirstText: "<<",
  847. pageLastText: ">>",
  848. rowClick: function (args) {
  849. if (navigator.userAgent.match(/mobile/i)) {
  850. goToEdit('Customers_Upd', '?Action=Upd&guid=' + args.item.guid);
  851. }
  852. },
  853. rowDoubleClick: function (args) {
  854. parent.openPageTab('Customers_Upd', '?Action=Upd&guid=' + args.item.guid);
  855. },
  856. fields: [
  857. {
  858. name: "RowIndex", title: 'common.RowNumber', width: 50, align: "center"
  859. },
  860. {
  861. name: "AgentCName", title: 'ExhibitionImport_Upd.Agent', width: 200
  862. },
  863. {
  864. name: "CustomerCName", title: 'Customers_Upd.CustomerCName', width: 200
  865. },
  866. {
  867. name: "CustomerEName", title: 'Customers_Upd.CustomerEName', width: 200
  868. },
  869. {
  870. name: "ContactorName", title: 'common.Contactor', width: 150, align: "center"
  871. },
  872. {
  873. name: "Telephone", title: 'common.Telephone', width: 150
  874. }
  875. ],
  876. controller: {
  877. loadData: function (args) {
  878. return {
  879. data: saGridData,
  880. itemsCount: saGridData.length //data.length
  881. };
  882. },
  883. insertItem: function (args) {
  884. },
  885. updateItem: function (args) {
  886. },
  887. deleteItem: function (args) {
  888. }
  889. },
  890. onInit: function (args) {
  891. oGrid = args.grid;
  892. }
  893. });
  894. $("#jsGrid1").jsGrid({
  895. width: "100%",
  896. height: iHeight,
  897. autoload: false,
  898. filtering: true,
  899. pageLoading: true,
  900. inserting: true,
  901. editing: true,
  902. sorting: true,
  903. paging: true,
  904. pageIndex: 1,
  905. pageSize: parent.SysSet.GridRecords || 10,
  906. pageButtonCount: parent.SysSet.GridPages || 15,
  907. confirmDeleting: true,
  908. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  909. pagePrevText: "<",
  910. pageNextText: ">",
  911. pageFirstText: "<<",
  912. pageLastText: ">>",
  913. rowClick: function (args) {
  914. //if (navigator.userAgent.match(/mobile/i)) {
  915. // goToEdit('Customers_Upd', '?Action=Upd&guid=' + args.item.guid);
  916. //}
  917. },
  918. rowDoubleClick: function (args) {
  919. //parent.openPageTab('Customers_Upd', '?Action=Upd&guid=' + args.item.guid);
  920. },
  921. fields: [
  922. {
  923. name: "RowIndex", title: 'common.RowNumber', width: 50, align: "center"
  924. },
  925. {// ╠Exhibition_Upd.ExhibitionArea⇒展區╣
  926. name: "ExhibitionArea", title: 'Exhibition_Upd.ExhibitionArea', type: 'text', width: 100
  927. },
  928. {
  929. name: "MuseumMumber", title: 'ExhibitionImport_Upd.HallMuseumMumber', type: 'text', width: 80
  930. },
  931. {
  932. name: "CustomerCName", title: 'Customers_Upd.CustomerCName', type: 'text', width: 140,
  933. validate: [
  934. {
  935. validator: 'required',
  936. message: i18next.t('Customers_Upd.CustomerCName_required')// ╠Customers_Upd.CustomerCName_required⇒請輸入公司中文名稱╣
  937. },
  938. {
  939. validator: function (value, item) {
  940. var bRetn = true;
  941. CallAjax(ComFn.W_Com, ComFn.GetCount, {
  942. Params: {
  943. importcustomers: {
  944. CustomerCName: value,
  945. OrgID: parent.top.OrgID,
  946. ExhibitionNO: sDataId,
  947. guid: '<>' + item.guid
  948. }
  949. }
  950. }, function (rq) {
  951. if (rq.d > 0) {
  952. bRetn = false;
  953. }
  954. }, null, true, false);
  955. return bRetn;
  956. },
  957. message: i18next.t("message.CustomerCNameExist") // ╠message.CustomerCNameExist⇒該廠商名稱已存在╣
  958. }]
  959. },
  960. {
  961. name: "CustomerEName", title: 'Customers_Upd.CustomerEName', type: 'text', width: 140
  962. },
  963. {
  964. name: "UniCode", title: 'Customers_Upd.UniCode', type: 'text', width: 100,
  965. validate: [
  966. {
  967. validator: function (_val) {
  968. return _val === '' ? true : _val.length === 8;
  969. },
  970. message: i18next.t('message.UniCodeLength')
  971. }
  972. ]
  973. },
  974. {
  975. name: "Contactor", title: 'common.Contactor', type: 'text', width: 120,
  976. validate: { validator: 'required', message: i18next.t('common.Contactor_required') }// ╠common.Contactor_required⇒請輸入聯絡人╣
  977. },
  978. {
  979. name: "Telephone", title: 'common.Telephone', type: 'text', width: 100, align: "center",
  980. validate: { validator: 'required', message: i18next.t('common.Telephone_required') }// ╠common.Telephone_required⇒請輸入聯絡電話╣
  981. },
  982. {
  983. name: "Email", title: 'common.Email', type: 'text', width: 130,
  984. validate: {
  985. validator: function (_val) {
  986. return _val === '' ? true : isEmail(_val);
  987. },
  988. message: i18next.t('message.IncorrectEmail'),// ╠message.IncorrectEmail⇒郵箱格式不正確╣
  989. }
  990. },
  991. {
  992. name: "Address", title: 'common.Address', type: 'text', width: 100
  993. },
  994. {
  995. name: "Memo", title: 'common.Memo', type: 'text', width: 100
  996. },
  997. {// ╠common.IsAppoint⇒預約狀態╣
  998. name: "IsAppoint", title: 'common.IsAppoint', width: 60, align: "center",
  999. itemTemplate: function (val, item) {
  1000. return val === 'Y' ? $('<span />', { text: i18next.t('common.HasAppoint') }).css('color', 'green') : $('<span />', { text: i18next.t('common.NotAppoint') }).css('color', 'red');// ╠common.HasAppoint⇒已預約╣ ╠common.NotAppoint⇒未預約╣
  1001. }
  1002. },
  1003. {// ╠common.IsFormal⇒資料狀態╣
  1004. name: "guid",
  1005. title: 'common.IsFormal',
  1006. width: 140,
  1007. align: 'center',
  1008. itemTemplate: function (val, item) {
  1009. var saAction = [];
  1010. if (!item.IsFormal) {
  1011. saAction.push($('<a/>', {
  1012. html: i18next.t('common.TransferToFormal'),// ╠common.TransferToFormal⇒轉為正式客戶╣
  1013. class: 'link',
  1014. click: function () {
  1015. fnTransferToFormal(item);
  1016. return false;
  1017. }
  1018. }));
  1019. if (parent.UserInfo.roles.indexOf('Admin') > -1) {
  1020. saAction.push(' ', $('<a/>', {
  1021. html: i18next.t('common.CorrespondFormalCus'),// ╠common.CorrespondFormalCus⇒對應到正式客戶╣
  1022. class: 'link',
  1023. style: 'color:green !important',
  1024. click: function () {
  1025. fnCorrespondFormalCus(item);
  1026. }
  1027. }));
  1028. }
  1029. }
  1030. else {
  1031. saAction.push($('<span />', { text: i18next.t('common.HasFormal') }).css('color', 'green'));
  1032. }
  1033. return $('<div>', { 'style': 'width:100%;text-align: center;' }).append(saAction);
  1034. }
  1035. },
  1036. {
  1037. type: "control",
  1038. width: 100,
  1039. headerTemplate: function () {
  1040. var saBtn = [];
  1041. if (sAction === 'Upd') {
  1042. saBtn.push($('<button />', {
  1043. type: 'button', 'class': 'btn-custom blue', title: i18next.t('common.Toolbar_Imp'), html: '<i class="glyphicon glyphicon-import"></i>', click: function () {
  1044. fnImportCusList();
  1045. }
  1046. }));
  1047. saBtn.push($('<button />', {
  1048. type: 'button', 'class': 'btn-custom blue', title: i18next.t('common.Toolbar_Exp'), html: '<i class="glyphicon glyphicon-export"></i>', click: function () {
  1049. fnExportCusList();
  1050. }
  1051. }));
  1052. }
  1053. return saBtn;
  1054. },
  1055. deleteButton: false
  1056. }
  1057. ],
  1058. controller: {
  1059. loadData: function (args) {
  1060. return fnGetGridData1(args);
  1061. },
  1062. insertItem: function (args) {
  1063. fnAddCustomers(args);
  1064. },
  1065. updateItem: function (args) {
  1066. fnUpdCustomers(args);
  1067. },
  1068. deleteItem: function (args) {
  1069. }
  1070. },
  1071. onInit: function (args) {
  1072. oGrid1 = args.grid;
  1073. }
  1074. });
  1075. };
  1076. init();
  1077. },
  1078. /**
  1079. * 客戶轉為正式資料后動作
  1080. * @param {String}afterid 客戶id
  1081. */
  1082. fnReFresh = function (afterid) {
  1083. bRefresh = true;
  1084. $('iframe').attr('src', '../Crm/Customers_Upd.html?Action=Upd&Flag=Fit&guid=' + afterid);
  1085. };
  1086. require(['base', 'select2', 'jsgrid', 'daterangepicker', 'convetlng', 'filer', 'ajaxfile', 'util'], fnPageInit, 'daterangepicker');