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.

915 lines
45 KiB

2 years ago
  1. 'use strict';
  2. var EditableData = false;
  3. var DefaultState = parent.top.OrgID === 'SG' ? 'CHN' : 'TWN';
  4. var fnPageInit = function () {
  5. var sLang = g_ul.GetLang(),
  6. sAction = getUrlParam('Action') || 'Add',
  7. oAuditFlag = { 'N': 'P', 'Z': 'A', 'Q': 'A' },
  8. canDo = new CanDo({
  9. /**
  10. * 是否返回查詢頁面
  11. */
  12. goBack: false,
  13. /**
  14. * 當前程式所有ID名稱集合
  15. */
  16. idKeys: ['OrgID', 'guid'],
  17. /**
  18. * 當前程式所有參數名稱集合
  19. */
  20. paramKeys: ['guid', 'From', 'FromId', 'Flag'],
  21. /**
  22. * 頁簽回調函數
  23. */
  24. tabAction: function (el, pargs) {
  25. switch (el.id) {
  26. case 'litab2':
  27. if (!$(el).data('action')) {
  28. pargs.Grid.loadData();
  29. $(el).data('action', true);
  30. }
  31. break;
  32. }
  33. },
  34. /**
  35. * 查詢當前資料
  36. * @param {Object} pargs CanDo 對象
  37. * @param {Object} data 當前資料實體
  38. */
  39. getOneBack: function (pargs, data) {
  40. var oRes = data,
  41. sText = '',
  42. elAuditReason = $('#AuditReason');
  43. oRes.Contactors = $.parseJSON(oRes.Contactors || '[]');
  44. $('.NotPassReason').show();
  45. switch (oRes.IsAudit) {
  46. case 'N':// ╠common.NotAudit⇒未提交審核╣
  47. EditableData = true;
  48. sText = i18next.t("common.NotAudit");
  49. elAuditReason.css('color', 'red');
  50. break;
  51. case 'Y':// ╠common.Audited⇒已審核╣
  52. sText = i18next.t("common.Audited");
  53. elAuditReason.css('color', 'green');
  54. break;
  55. case 'P':// ╠common.InAudit⇒提交審核中╣
  56. sText = i18next.t("common.InAudit");
  57. elAuditReason.css('color', 'blue');
  58. break;
  59. case 'A':// ╠common.AuditAgain⇒重新提交審核中╣
  60. sText = i18next.t("common.AuditAgain") + ' (' + (oRes.NotPassReason || '') + ')';
  61. elAuditReason.css('color', 'blue');
  62. break;
  63. case 'Z':// ╠common.ApplyforUpdateing⇒申請修改中╣
  64. EditableData = true;
  65. sText = i18next.t("common.ApplyforUpdateing") + ' (' + (oRes.NotPassReason || '') + ')';
  66. elAuditReason.css('color', 'blue');
  67. break;
  68. case 'Q':// ╠common.NotPass⇒不通過╣
  69. sText = i18next.t("common.NotPass") + ' (' + (oRes.NotPassReason || '') + ')';
  70. elAuditReason.css('color', 'red');
  71. break;
  72. }
  73. elAuditReason.text(sText);
  74. if ('Y,P,A'.indexOf(oRes.IsAudit) > -1) {
  75. disableInput(pargs._form, '.plustemplkey,[data-input],#WebsiteAdress,#State,#Memo');
  76. if ('P,A'.indexOf(oRes.IsAudit) > -1 && parent.top.SysSet.CustomersAuditUsers.indexOf(parent.top.UserInfo.MemberID) > -1) {
  77. $('#Toolbar_Audit').show();
  78. }
  79. if (oRes.IsAudit === 'Y') {
  80. $('#Toolbar_ApplyforUpdate').show();
  81. }
  82. }
  83. else {
  84. disableInput(pargs._form, '#CustomerNO', false);
  85. $('#Toolbar_ToAudit').show();
  86. }
  87. if (pargs.params.Flag === 'Fit') {
  88. $('#Toolbar_Leave,#Toolbar_Del').hide();
  89. }
  90. $('#Toolbar_CopySync').hide();
  91. if (data.IsAudit === 'Y' && 'TE,TG'.indexOf(parent.UserInfo.OrgID) > -1) {
  92. //只有已審核才顯示
  93. $('#Toolbar_CopySync').show();
  94. }
  95. },
  96. /**
  97. * 處理新增資料參數
  98. * @param {Object} pargs CanDo 對象
  99. * @param {Object} data 當前表單資料
  100. */
  101. getInsertParams: function (pargs, data) {
  102. var sCustomerFirstChart = '',
  103. sCustomerNo = '';
  104. //若失敗後,資料已經變成字串了。需要再次轉回陣列,才能刪除
  105. if (typeof pargs.data.Contactors === 'string') {
  106. pargs.data.Contactors = JSON.parse(pargs.data.Contactors || '[]');
  107. }
  108. data.Contactors = JSON.stringify(pargs.data.Contactors);
  109. sCustomerFirstChart = getCustomerFirstChart(data.TransactionType, data.CustomerEName, data.CustomerCName);
  110. sCustomerNo = parent.top.OrgID + data.TransactionType + sCustomerFirstChart;
  111. if (sAction === 'Upd') {
  112. if (data.CustomerNO.substr(0, 4) !== sCustomerNo) {
  113. //與原先不相同,重新產生編碼
  114. data.CustomerNO = sCustomerNo;
  115. }
  116. }
  117. else {
  118. if (!data.CustomerNO) {
  119. data.CustomerNO = sCustomerNo;
  120. }
  121. }
  122. return data;
  123. },
  124. /**
  125. * 處理修改資料參數
  126. * @param {Object} pargs CanDo 對象
  127. * @param {Object} data 當前表單資料
  128. */
  129. getUpdateParams: function (pargs, data) {
  130. return pargs.options.getInsertParams(pargs, data);
  131. },
  132. /**
  133. * 新增資料
  134. * @param {Object} pargs CanDo 對象
  135. * @param {Object} data 當前新增的資料
  136. * @param {String} flag 新增 or 儲存后新增
  137. */
  138. getInsertBack: function (pargs, data, flag) {
  139. if (pargs.params.From === 'Appoint') {
  140. fnReEditCustomer($('body').attr('PopId') || '', data.guid).done(function () {
  141. if (pargs.params.Flag === 'Pop') {
  142. $('#Toolbar button').prop('disabled', true);
  143. parent.fnReFresh(data.guid);
  144. showMsg(i18next.t("message.Save_Success"), 'success'); // ╠message.Save_Success⇒新增成功╣
  145. }
  146. else {
  147. showMsgAndGo(i18next.t("message.Save_Success"), pargs.ProgramId, '?Action=Upd&guid=' + data.guid); // ╠message.Save_Success⇒新增成功╣
  148. }
  149. });
  150. }
  151. else {
  152. if (flag == 'add') {
  153. showMsgAndGo(i18next.t("message.Save_Success"), pargs.ProgramId, '?Action=Upd&guid=' + data.guid); // ╠message.Save_Success⇒新增成功╣
  154. }
  155. else {
  156. showMsgAndGo(i18next.t("message.Save_Success"), pargs.ProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  157. }
  158. }
  159. },
  160. /**
  161. * 修改資料
  162. * @param {Object} pargs CanDo 對象
  163. * @param {Object} data 當前修改的資料
  164. */
  165. getUpdateBack: function (pargs, data) {
  166. if (typeof pargs.data.Contactors === 'string') {
  167. pargs.data.Contactors = $.parseJSON(pargs.data.Contactors || '[]');
  168. }
  169. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  170. if (window.bLeavePage) {
  171. setTimeout(function () {
  172. pargs._pageLeave();
  173. }, 1000);
  174. }
  175. else {
  176. pargs._setFormVal(data);
  177. //location.reload();
  178. }
  179. },
  180. /**
  181. * 客製化驗證規則
  182. * @param {Object} pargs CanDo 對象
  183. */
  184. validRulesCus: function (pargs) {
  185. $.validator.addMethod("unicoderequired", function (value, element, parms) {
  186. var sTransactionType = $('[name="TransactionType"]:checked').val();
  187. if ((sTransactionType === 'A' || sTransactionType === 'D') && value === '') {
  188. return false;
  189. }
  190. return true;
  191. });
  192. $.validator.addMethod("unicodelen", function (value) {
  193. if (value !== '' && value.length != 8) {
  194. return false;
  195. }
  196. return true;
  197. });
  198. $.validator.addMethod("customercnamerequired", function (value, element, parms) {
  199. var sTransactionType = $('[name="TransactionType"]:checked').val();
  200. if (!(sTransactionType === 'B' || sTransactionType === 'C') && value === '') {
  201. return false;
  202. }
  203. return true;
  204. });
  205. $.validator.addMethod("customerenamecus", function (value, element, parms) {
  206. var p = /[a-z]/i,
  207. b = p.test(value.substr(0, 1));
  208. if (!b && value !== '') {
  209. return false;
  210. }
  211. return true;
  212. });
  213. $.validator.addMethod("customerenamerequired", function (value, element, parms) {
  214. var sTransactionType = $('[name="TransactionType"]:checked').val();
  215. if ((sTransactionType === 'B' || sTransactionType === 'C') && value === '') {
  216. return false;
  217. }
  218. return true;
  219. });
  220. $.validator.addMethod("customershortnamerule", function (value) {
  221. var bRetn = true;
  222. g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout,
  223. {
  224. guid: pargs.ids.guid,
  225. CustomerShotCName: value
  226. },
  227. function (res) {
  228. if (res.RESULT && res.DATA.rel > 0) {
  229. bRetn = false;
  230. }
  231. }, null, false);
  232. return bRetn;
  233. });
  234. $.validator.addMethod("unicoderule", function (value) {
  235. var bRetn = true;
  236. if (value) {
  237. g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout,
  238. {
  239. guid: pargs.ids.guid,
  240. UniCode: value
  241. },
  242. function (res) {
  243. if (res.RESULT && res.DATA.rel > 0) {
  244. bRetn = false;
  245. }
  246. }, null, false);
  247. }
  248. return bRetn;
  249. });
  250. },
  251. /**
  252. * 驗證規則
  253. */
  254. validRules: {
  255. //若是換頁新增會出錯,必須驗證隱藏的tab
  256. //ignore: 'disabled',
  257. onfocusout: false,
  258. rules: {
  259. Email: {
  260. email: true
  261. },
  262. UniCode: {
  263. unicodelen: true,
  264. unicoderule: true
  265. },
  266. TransactionType: { required: true },
  267. CustomerShotCName: { customershortnamerule: true }
  268. },
  269. messages: {
  270. Email: i18next.t("message.IncorrectEmail"),// ╠message.IncorrectEmail⇒郵箱格式不正確╣
  271. TransactionType: { required: i18next.t("Customers_Upd.TransactionType_required") },// ╠Customers_Upd.TransactionType_required⇒請選擇交易類型╣
  272. UniCode: {
  273. unicodelen: i18next.t("message.UniCodeLength"),// ╠message.UniCodeLength⇒客戶統一編號必須是8碼╣
  274. unicoderule: i18next.t("message.Data_Repeat")// ╠message.Data_Repeat⇒此筆資料已建檔╣
  275. },
  276. CustomerShotCName: { customershortnamerule: i18next.t("message.ShotNameExist") }// ╠message.ShotNameExist⇒該簡稱已被使用╣
  277. }
  278. },
  279. /**
  280. * 客製化按鈕
  281. * @param {Object} pargs CanDo 對象
  282. */
  283. cusBtns: function (pargs) {
  284. var saCusBtns = [];
  285. if (pargs.action !== 'add') {
  286. saCusBtns.push({
  287. id: 'Toolbar_ToAudit',
  288. value: 'common.SubmitAudit',// ╠common.SubmitAudit⇒提交審核╣
  289. /**
  290. * 業務提交審核
  291. */
  292. action: function (pargs) {
  293. if (pargs.data.Effective === 'N') {
  294. showMsg(i18next.t('message.DataHasInvalid')); // ╠message.DataHasInvalid⇒該資料已無效╣
  295. return false;
  296. }
  297. var sIsAudit = oAuditFlag[pargs.data.IsAudit];
  298. var sCustomerShotCName = $('#CustomerShotCName').val();
  299. var sUniCode = $('#UniCode').val();
  300. var sTransactionType = $('[name="TransactionType"]:checked').val();
  301. var sTaxpayerOrgID = $('#TaxpayerOrgID').val();
  302. g_api.ConnectLite(pargs.ProgramId, 'ToAudit', {
  303. guid: pargs.ids.guid,
  304. IsAudit: sIsAudit,
  305. CustomerShotCName: sCustomerShotCName,
  306. UniCode: sUniCode,
  307. TransactionType: sTransactionType,
  308. TaxpayerOrgID: sTaxpayerOrgID
  309. }, function (res) {
  310. if (res.RESULT) {
  311. $('#Toolbar_ToAudit').hide();
  312. pargs._getOne();
  313. showMsg(i18next.t("message.ToAudit_Success"), 'success'); // ╠message.ToAudit_Success⇒提交審核成功╣
  314. parent.top.msgs.server.pushTips(parent.top.fnReleaseUsers(res.DATA.rel));
  315. }
  316. else {
  317. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  318. }
  319. }, function () {
  320. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  321. });
  322. }
  323. }, {
  324. id: 'Toolbar_CopySync',
  325. value: 'Customers_Upd.CopySync', // 複製同步,
  326. action: function (parg) {
  327. },
  328. 'data-toggle': 'modal',
  329. 'data-target': '#CopySync'
  330. });
  331. if (parent.top.SysSet.CustomersAuditUsers.indexOf(parent.top.UserInfo.MemberID) > -1) {
  332. saCusBtns.push({
  333. id: 'Toolbar_Audit',
  334. value: 'common.Audit',// ╠common.Audit⇒審核╣
  335. /**
  336. * 主管審核
  337. */
  338. action: function (pargs) {
  339. layer.open({
  340. type: 1,
  341. title: i18next.t('common.Audit'),// ╠common.Audit⇒審核╣
  342. area: ['400px', '260px'],//寬度
  343. shade: 0.75,//遮罩
  344. shadeClose: true,
  345. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣// ╠common.Cancel⇒取消╣
  346. content: '<div class="pop-box">\
  347. <textarea name="NotPassReason" id="NotPassReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.NotPassReason" placeholder="不通過原因..."></textarea><br>\
  348. <button type="button" data-i18n="common.Pass" id="audit_pass" class="btn-custom green">通過</button>\
  349. <button type="button" data-i18n="common.NotPass" id="audit_notpass" class="btn-custom red">不通過</button>\
  350. </div>',
  351. success: function (layero, idx) {
  352. $('.pop-box :button').click(function () {
  353. var oAudit = {},
  354. sNotPassReason = $('#NotPassReason').val();
  355. if (this.id === 'audit_pass') {
  356. oAudit.IsAudit = 'Y';
  357. oAudit.NotPassReason = '';
  358. }
  359. else {
  360. oAudit.IsAudit = 'Q';
  361. oAudit.NotPassReason = sNotPassReason;
  362. if (!sNotPassReason) {
  363. showMsg(i18next.t("message.NotPassReason_Required")); // ╠message.NotPassReason_Required⇒請填寫不通過原因╣
  364. return false;
  365. }
  366. }
  367. g_api.ConnectLite(pargs.ProgramId, 'Audit', {
  368. IsAudit: oAudit.IsAudit,
  369. NotPassReason: oAudit.NotPassReason,
  370. guid: pargs.ids.guid
  371. }, function (res) {
  372. if (res.RESULT) {
  373. $('#Toolbar_Audit').hide();
  374. layer.close(idx);
  375. pargs._getOne();
  376. showMsg(i18next.t("message.Audit_Completed"), 'success'); // ╠message.Audit_Completed⇒審核完成╣
  377. parent.top.msgs.server.pushTip(parent.top.OrgID, res.DATA.rel);
  378. if (oAudit.IsAudit === 'Y') {
  379. parent.top.msgs.server.pushTransfer(parent.top.OrgID, parent.top.UserID, pargs.data.CustomerNO, 2);
  380. }
  381. }
  382. else {
  383. showMsg(i18next.t('message.Audit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  384. }
  385. }, function () {
  386. showMsg(i18next.t('message.Audit_Failed'), 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  387. });
  388. });
  389. pargs._transLang(layero);
  390. }
  391. });
  392. }
  393. });
  394. }
  395. saCusBtns.push({
  396. id: 'Toolbar_ApplyforUpdate',
  397. value: 'common.ApplyforUpdate',// ╠common.ApplyforUpdate⇒申請修改╣
  398. /**
  399. * 申請修改
  400. */
  401. action: function (pargs) {
  402. layer.open({
  403. type: 1,
  404. title: i18next.t('common.ApplyforUpdate'),// ╠common.ApplyforUpdate⇒申請修改╣
  405. area: ['400px', '260px'],//寬度
  406. shade: 0.75,//遮罩
  407. shadeClose: true,
  408. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  409. content: '<div class="pop-box"><textarea name="Reason" id="Reason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.ApplyforUpdateReason" placeholder="申請修改原因..."></textarea></div>',
  410. success: function (layero, idx) {
  411. pargs._transLang(layero);
  412. },
  413. yes: function (index, layero) {
  414. var sReason = $('#Reason').val();
  415. if (!sReason) {
  416. showMsg(i18next.t("message.Reason_Required")); // ╠message.Reason_Required⇒請填寫原因╣
  417. return false;
  418. }
  419. g_api.ConnectLite(pargs.ProgramId, 'ApplyforUpdate', {
  420. Guid: pargs.ids.guid,
  421. NotPassReason: sReason
  422. }, function (res) {
  423. if (res.RESULT) {
  424. layer.close(index);
  425. $('#Toolbar_ApplyforUpdate').hide();
  426. pargs._getOne();
  427. showMsg(i18next.t("message.HasNoticeAditor"), 'success'); // ╠message.HasNoticeAditor⇒已通知審核人員╣
  428. parent.top.msgs.server.pushTips(parent.top.fnReleaseUsers(res.DATA.rel));
  429. }
  430. else {
  431. showMsg(i18next.t('message.ToApplyFailed') + '<br>' + res.MSG, 'error'); // ╠message.ToApplyFailed⇒提交申請失敗╣
  432. }
  433. }, function () {
  434. showMsg(i18next.t('message.ToApplyFailed'), 'error');// ╠message.ToApplyFailed⇒提交申請失敗╣
  435. });
  436. }
  437. });
  438. }
  439. });
  440. }
  441. return saCusBtns;
  442. },
  443. /**
  444. * 頁面初始化
  445. * @param {Object} pargs CanDo 對象
  446. */
  447. pageInit: function (pargs) {
  448. var postArray = [];
  449. if (pargs.action === 'add') {
  450. $("#ui-id-2").hide();
  451. }
  452. $('#CopySync').find('label[OrgID=\"' + g_db.GetItem("orgid").toUpperCase() + '\"]').hide(); //隱藏自己組織別
  453. $('#Toolbar_CopySync').click(function () {
  454. $('#CopySync').find('label[OrgID] > :checkbox').prop('checked', false); //清除已勾選項目
  455. });
  456. $('#CopySycnOK').click(function () {
  457. var aryCheckOrgID = [];
  458. //取得勾選組織別
  459. $('#CopySync').find('label[OrgID]').each(function (idx, element) {
  460. var sOrgID = $(element).attr('OrgID');
  461. if ($(element).find(':checkbox').is(':checked')) {
  462. aryCheckOrgID.push(sOrgID);
  463. }
  464. });
  465. if (aryCheckOrgID.length <= 0) {
  466. showMsg(i18next.t("請先選擇要複製同步的公司別"), 'error');
  467. }
  468. else {
  469. canDo.data.currOrgID = g_db.GetItem("orgid").toUpperCase();
  470. canDo.data.OrgID = aryCheckOrgID[0];
  471. var sCustomerFirstChart = getCustomerFirstChart(canDo.data.TransactionType, canDo.data.CustomerEName, canDo.data.CustomerCName),
  472. sCustomerNo = canDo.data.OrgID + canDo.data.TransactionType + sCustomerFirstChart;
  473. canDo.data.CustomerNO = sCustomerNo;
  474. g_api.ConnectLite(pargs.ProgramId, 'CopySync', canDo.data, function (res) {
  475. if (res.RESULT) {
  476. var data = res.DATA.rel;
  477. showMsg(i18next.t("執行成功,同步新客戶編號為" + data.CustomerNO), 'success');
  478. parent.top.msgs.server.pushTips(parent.top.fnReleaseUsers(data));
  479. }
  480. else {
  481. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  482. }
  483. }, function () {
  484. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  485. });
  486. }
  487. });
  488. if (pargs.action === 'upd') {
  489. postArray.push(pargs._getOne());
  490. }
  491. else {
  492. if (g_db.GetItem("orgid").toUpperCase() === 'SG') // if (parent.OrgID.toUpperCase() === 'SG')
  493. $('.APIImport').hide();
  494. else
  495. $('.APIImport').show();
  496. $('.CustomerEName').hide();
  497. pargs.data.Contactors = [];
  498. }
  499. postArray.push(fnSetArgDrop([
  500. {
  501. ArgClassID: 'TranType',
  502. CallBack: function (data) {
  503. $('#transactiontype').html(createRadios(data, 'id', 'text', 'TransactionType', '', true)).find('label:first').click();
  504. pargs._uniformInit($('#transactiontype'));
  505. }
  506. }
  507. ]));
  508. //postArray return 要是function 才會生效
  509. postArray.push(setStateDrop());
  510. if (parent.top.OrgID === 'SG') {
  511. $('.unicode-box').hide();
  512. $('.sg-box').show();
  513. }
  514. //加載報關類別,加載報價頁簽,加載運輸方式, 加載機場, 加載貨棧場, 加載倉庫
  515. $.whenArray(postArray).done(function (res) {
  516. let resState = '';
  517. if (pargs.action === 'upd' && res[0].RESULT) {
  518. var oRes = res[0].DATA.rel;
  519. pargs._setFormVal(oRes);
  520. fnBindContactors();
  521. pargs._getPageVal();//緩存頁面值,用於清除
  522. resState = oRes.State;
  523. switch (pargs.data.IsAudit) {
  524. case 'N'://未提交
  525. case 'Q'://退件
  526. case 'Z'://申請修改中
  527. $('#Toolbar_ApplyforUpdate,#Toolbar_Audit').hide();
  528. break;
  529. case 'Y':// ╠common.Audited⇒已審核╣
  530. $('#Toolbar_ToAudit,#Toolbar_Audit').hide();
  531. break;
  532. case 'P':// ╠common.InAudit⇒提交審核中╣
  533. case 'A'://重新提交審核中
  534. $('#Toolbar_ApplyforUpdate').hide();
  535. $('#Toolbar_ToAudit').hide();
  536. break;
  537. }
  538. }
  539. if (pargs.params.Flag === 'Pop') {
  540. $('#Toolbar_Leave,#Toolbar_ReAdd,#APIImport').hide();
  541. }
  542. else if (pargs.params.Flag === 'Fit') {
  543. $('#Toolbar_Leave,#Toolbar_Del').hide();
  544. }
  545. if (canDo.params.FromId) {
  546. fnGetImportCustomersByAppointNO();
  547. }
  548. if ('Y,P,A'.indexOf(pargs.data.IsAudit) > -1) {
  549. disableInput(pargs._form, '.plustemplkey,[data-input],#WebsiteAdress,#State,#Memo');
  550. }
  551. $('[name="TransactionType"]').click(function () {
  552. if (this.value === 'A' || this.value === 'D') {
  553. $('.innercol,.address,.telephone').show();
  554. $('#BankName,#BankAcount,#TaxpayerOrgID,#Telephone,#Address').attr('required', true);
  555. }
  556. else {
  557. $('.innercol,.address,.telephone').hide();
  558. $('#BankName,#BankAcount,#TaxpayerOrgID,#Telephone,#Address').removeAttr('required');
  559. }
  560. if (this.value === 'B' || this.value === 'C') {
  561. $('.CustomerCName').hide();
  562. $('.CustomerEName').show();
  563. }
  564. else {
  565. $('.CustomerCName').show();
  566. $('.CustomerEName').hide();
  567. }
  568. if (EditableData || sAction === 'Add') {
  569. var DefaultChangeState = 'A,D,E,F'.indexOf(this.value) > -1;
  570. if (DefaultChangeState) {
  571. $('#State').val(DefaultState).trigger("change");
  572. }
  573. else {
  574. $('#State').val('').trigger("change");
  575. }
  576. }
  577. });
  578. $('[name="TransactionType"]:checked').click();
  579. if (!!resState) {
  580. $('#State').val(resState);
  581. }
  582. $('.plustemplkey').on('click', function () {
  583. var oNewKey = {};
  584. oNewKey.guid = guid();
  585. oNewKey.FullName = '';
  586. oNewKey.JobtitleName = '';
  587. oNewKey.TEL1 = '';
  588. oNewKey.TEL2 = '';
  589. oNewKey.FAX = '';
  590. oNewKey.Email = '';
  591. oNewKey.Memo = '';
  592. //若失敗後,資料已經變成字串了。需要再次轉回陣列,才能刪除
  593. if (typeof pargs.data.Contactors === 'string') {
  594. pargs.data.Contactors = JSON.parse(pargs.data.Contactors || '[]');
  595. }
  596. pargs.data.Contactors.push(oNewKey);
  597. fnBindContactors();
  598. });
  599. });
  600. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 120;
  601. $("#jsGrid").jsGrid({
  602. width: "100%",
  603. height: "auto",
  604. autoload: false,
  605. filtering: false,
  606. pageLoading: true,
  607. inserting: false,
  608. editing: false,
  609. sorting: false,
  610. paging: false,
  611. pageIndex: 1,
  612. pageSize: parent.top.SysSet.GridRecords || 10,
  613. confirmDeleting: true,
  614. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  615. pagePrevText: "<",
  616. pageNextText: ">",
  617. pageFirstText: "<<",
  618. pageLastText: ">>",
  619. fields: [
  620. {
  621. name: "RowIndex", title: 'common.RowNumber', width: 50, align: "center"
  622. },
  623. {
  624. name: "ExhibitionCode", title: 'Exhibition_Upd.ExhibitionCode', width: 150, align: "center"
  625. },
  626. {
  627. name: "Exhibitioname_TW", title: 'Exhibition_Upd.Exhibitioname_TW', width: 600,
  628. itemTemplate: function (val, item) {
  629. var oA = $('<a>', {
  630. html: sLang === 'zh' ? item.Exhibitioname_CN : val,
  631. class: 'a-url',
  632. click: function () {
  633. parent.top.openPageTab('Exhibition_Upd', '?Action=Upd&SN=' + item.SN);
  634. }
  635. });
  636. return oA;
  637. }
  638. }
  639. ],
  640. controller: {
  641. loadData: function (args) {
  642. return fnGetGridData();
  643. },
  644. insertItem: function (args) {
  645. },
  646. updateItem: function (args) {
  647. },
  648. deleteItem: function (args) {
  649. }
  650. },
  651. onInit: function (args) {
  652. pargs.setGrid(args.grid);
  653. }
  654. });
  655. $('#UniCode').on('blur', function () {
  656. this.value = $.trim(this.value);
  657. });
  658. $('#CustomerEName,#CustomerShotCName,#Address,#InvoiceAddress').on('blur', function () {
  659. this.value = this.value.toUpperCase();
  660. });
  661. $('#APIImport').on('click', function () {
  662. var sUniCode = $('#UniCode').val(),
  663. sCustomerCName = $('#CustomerCName').val();
  664. if (!sUniCode && !sCustomerCName) {
  665. showMsg(i18next.t('message.UniCodeOrCustomerCName_Required')); // ╠message.UniCodeOrCustomerCName_Required⇒請輸入客戶統編或者客戶全稱╣
  666. return false;
  667. }
  668. if (sUniCode && sUniCode.length !== 8) {
  669. showMsg(i18next.t('message.UniCodeInvalid')); // ╠message.UniCodeInvalid⇒統編號碼不合法╣
  670. return false;
  671. }
  672. g_api.ConnectLite(pargs.ProgramId, 'GetCrmBaseDataByUniCode', {
  673. UniCode: sUniCode,
  674. KeyWords: sCustomerCName
  675. }, function (res) {
  676. if (res.RESULT) {
  677. var oBase = res.DATA.rel,
  678. oFirst = {};
  679. if (oBase) {
  680. var saBase = $.parseJSON(oBase);
  681. if ($.isArray(saBase)) {
  682. oFirst = saBase[0];
  683. if (!$.isEmptyObject(oFirst)) {
  684. $('#UniCode').val(oFirst.Business_Accounting_NO);
  685. $('#CustomerCName').val(oFirst.Company_Name);
  686. $('#Address').val(oFirst.Company_Location);
  687. $('#InvoiceAddress').val(oFirst.Company_Location);
  688. }
  689. }
  690. }
  691. }
  692. else {
  693. showMsg(i18next.t('message.NotFindData') + '<br>' + res.MSG, 'error'); // ╠message.NotFindData⇒查不到對應的資料╣
  694. }
  695. }, function () {
  696. showMsg(i18next.t('message.NotFindData'), 'error');
  697. });
  698. });
  699. }
  700. }),
  701. /**
  702. * 設定國家下拉選單
  703. */
  704. setStateDrop = function () {
  705. return g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  706. OrgID: 'TE',
  707. ArgClassID: 'Area',
  708. LevelOfArgument: 1
  709. }, function (res) {
  710. if (res.RESULT) {
  711. let saState = res.DATA.rel;
  712. if (saState.length > 0) {
  713. $('#State').append(createOptions(saState, 'id', 'text', true)).select2();
  714. }
  715. }
  716. });
  717. },
  718. /**
  719. * 客戶轉為正式資料后回寫動作
  720. * @param {String} preid 轉正前的客戶id
  721. * @param {String} afterid 轉正后的客戶id
  722. */
  723. fnReEditCustomer = function (previd, afterid) {
  724. return g_api.ConnectLite('Exhibition_Upd', 'UpdateCustomerTag', {//匯入費用項目
  725. PrevId: previd,
  726. AfterId: afterid
  727. }, function (res) { });
  728. },
  729. /**
  730. * 綁定模版參數
  731. */
  732. fnBindContactors = function () {
  733. var sKeysHtml = '';
  734. $.each(canDo.data.Contactors, function (idx, item) {
  735. sKeysHtml += '<tr data-id="' + item.guid + '">\
  736. <td class="wcenter">' + (idx + 1) + '</td>\
  737. <td><input type="text" data-input="FullName" class="form-control w100p" value="' + item.FullName + '"></td>\
  738. <td><input type="text" data-input="JobtitleName" class="form-control w100p" value="' + (item.JobtitleName || '') + '"></td>\
  739. <td><input type="text" data-input="TEL1" class="form-control w100p" value="' + item.TEL1 + '" placeholderid="Customers_Upd.Instruction_ContactorTEL" placeholder="含分機"></td>\
  740. <td><input type="text" data-input="TEL2" class="form-control w100p" value="' + item.TEL2 + '" placeholderid="Customers_Upd.Instruction_ContactorTEL" placeholder="含分機"></td>\
  741. <td><input type="text" data-input="FAX" class="form-control w100p" value="' + item.FAX + '"></td>\
  742. <td><input type="text" data-input="Email" class="form-control w100p" value="' + item.Email + '"></td>\
  743. <td><input type="text" data-input="Memo" class="form-control w100p" value="' + item.Memo + '"></td>\
  744. <td><input type="number" data-input="RowID" class="form-control w100p" data-OriValue="' + (idx + 1) + '" value="' + (idx + 1) + '"></td>\
  745. <td class="wcenter">\
  746. <i class="glyphicon glyphicon-trash" data-value="' + item.guid + '" title="刪除"></i>\
  747. </td>\
  748. </tr>';
  749. });
  750. $('#table_box').html(sKeysHtml).find('.glyphicon-trash').on('click', function () {
  751. var sId = $(this).attr('data-value'),
  752. saNewList = [];
  753. //若失敗後,資料已經變成字串了。需要再次轉回陣列,才能刪除
  754. if (typeof canDo.data.Contactors === 'string') {
  755. canDo.data.Contactors = JSON.parse(canDo.data.Contactors || '[]');
  756. }
  757. $.each(canDo.data.Contactors, function (idx, item) {
  758. if (sId !== item.guid) {
  759. saNewList.push(item);
  760. }
  761. });
  762. $(this).parents('tr').remove();
  763. canDo.data.Contactors = saNewList;
  764. });
  765. canDo._transLang($('#table_box'));
  766. $('#table_box [data-input]').on('change click', function () {
  767. var sKey = $(this).attr('data-input'),
  768. sId = $(this).parents('tr').attr('data-id'),
  769. sVal = this.value;
  770. if (sKey === "RowID") {
  771. let OriValue = $(this).attr('data-OriValue');
  772. let FromIndex = Number(OriValue) - 1;
  773. let ToIndex = Number(sVal) - 1;
  774. let TempTarget = canDo.data.Contactors[ToIndex];
  775. let TempOrigin = canDo.data.Contactors[FromIndex];
  776. canDo.data.Contactors.splice(FromIndex, 1);
  777. canDo.data.Contactors.splice(ToIndex, 0,TempOrigin);
  778. fnBindContactors();
  779. }
  780. else {
  781. $.each(canDo.data.Contactors, function (idx, item) {
  782. if (sId === item.guid) {
  783. item[sKey] = sVal;
  784. return false;
  785. }
  786. });
  787. }
  788. });
  789. },
  790. /**
  791. * 設定交易型態下拉選單
  792. * @param {String} type 公司類別
  793. * @param {String} egname 英文名稱
  794. * @param {String} cnname 中文名稱
  795. */
  796. getCustomerFirstChart = function (type, egname, cnname) {
  797. var sFirstChart = '';
  798. if (type === 'E') {
  799. if (egname) {
  800. if (egname.indexOf('.') > -1) {
  801. if (egname.split('.')[1]) {
  802. sFirstChart = egname.split('.')[1].substr(0, 1);
  803. }
  804. else {
  805. sFirstChart = egname.split('.')[0].substr(0, 1);
  806. }
  807. }
  808. else {
  809. sFirstChart = egname.substr(0, 1);
  810. }
  811. }
  812. else {
  813. sFirstChart = cnname.substr(0, 1);
  814. }
  815. }
  816. else {
  817. if (egname) {
  818. sFirstChart = egname.substr(0, 1);
  819. }
  820. else {
  821. sFirstChart = cnname.substr(0, 1);
  822. }
  823. }
  824. sFirstChart = makePy(sFirstChart[0]);
  825. return sFirstChart[0].toUpperCase();
  826. },
  827. /**
  828. * 依據預約單號查詢匯入廠商并預設
  829. */
  830. fnGetImportCustomersByAppointNO = function () {
  831. g_api.ConnectLite(canDo.ProgramId, 'GetImportCustomersByAppointNO', {
  832. AppointNO: canDo.params.FromId
  833. }, function (res) {
  834. if (res.RESULT) {
  835. var oRes = res.DATA.rel;
  836. if (oRes) {
  837. $('#CustomerCName').val(oRes.CustomerCName);
  838. $('#Telephone').val(oRes.Telephone);
  839. $('#Email').val(oRes.Email);
  840. $('#Address').val(oRes.Address);
  841. $('#InvoiceAddress').val(oRes.InvoiceAddress);
  842. $('body').attr('PopId', oRes.guid);
  843. setTimeout(function () {
  844. $('.plustemplkey ').trigger('click');
  845. var _input = $('#table_box').find(':input');
  846. _input.eq(0).val(oRes.Contactor);
  847. _input.eq(2).val(oRes.Telephone);
  848. _input.eq(5).val(oRes.Email);
  849. setTimeout(function () {
  850. _input.eq(0).trigger('click');
  851. _input.eq(2).trigger('click');
  852. _input.eq(5).trigger('click');
  853. }, 500);
  854. }, 1000);
  855. }
  856. }
  857. });
  858. },
  859. /**
  860. * 抓去參加展覽列表資料
  861. * @return {Object} ajax物件
  862. */
  863. fnGetGridData = function () {
  864. if (canDo.ids.guid) {
  865. return g_api.ConnectLite(canDo.ProgramId, 'GetExhibitionlist', {
  866. Guid: canDo.ids.guid
  867. });
  868. }
  869. else {
  870. return $.Deferred().resolve().promise();
  871. }
  872. };
  873. };
  874. require(['base', 'select2', 'jsgrid', 'cando'], fnPageInit);