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.

743 lines
34 KiB

2 years ago
  1. $(function () {
  2. 'use strict';
  3. var sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW',
  4. bEn = sLang === 'en',
  5. iPageIndex = 1,
  6. iPageCount = 100000,
  7. oCostRules = {},
  8. sExpo = g_db.GetDic('Expo') || getUrlParam('SN'),
  9. iTotal = g_db.GetDic('Total') || 0,
  10. saOrderInfo = g_db.GetDic('OrderInfo'),
  11. eForm = $('#form_inquiry'),
  12. sState = getUrlParam('State'),
  13. sYear = getUrlParam('Year'),
  14. sMonth = getUrlParam('Month'),
  15. FeeCalculateRules = {},
  16. /**
  17. * 目的 設定展覽地區下拉單
  18. */
  19. fnGetArguments = function () {
  20. g_api.ConnectLite(Service.apiappcom, ComFn.GetArguments, {
  21. ArgClassID: 'Area',
  22. OrderBy: 'id',
  23. LevelOfArgument: 1
  24. }, function (res) {
  25. if (res.RESULT) {
  26. var saRes = res.DATA.rel;
  27. $('#area').html(createOptions(saRes, 'id', bEn ? 'text_en' : 'text', true));
  28. if (sState) {
  29. $('#area').val(sState);
  30. }
  31. else {
  32. $('#area').val('TWN');
  33. }
  34. $('#area').select2({
  35. placeholder: bEn ? 'Select Area' : '請選擇地區'
  36. });
  37. if (sYear) {
  38. $('#year').val(sYear);
  39. }
  40. if (sMonth) {
  41. var iMonth = sMonth * 1,
  42. sVal = '';
  43. switch (iMonth) {
  44. case 1:
  45. case 2:
  46. case 3:
  47. sVal = '01-03';
  48. break;
  49. case 4:
  50. case 5:
  51. case 6:
  52. sVal = '04-06';
  53. break;
  54. case 7:
  55. case 8:
  56. case 9:
  57. sVal = '07-09';
  58. break;
  59. case 10:
  60. case 11:
  61. case 12:
  62. sVal = '10-12';
  63. break;
  64. }
  65. $('#month').val(sVal);
  66. }
  67. }
  68. });
  69. },
  70. /**
  71. * 目的 設置日期下拉單
  72. */
  73. fnSetDate = function () {
  74. var saYears = [],
  75. year_cur = new Date().getFullYear();
  76. saYears.push({ id: year_cur, text: year_cur });
  77. year_cur++;
  78. saYears.push({ id: year_cur, text: year_cur });
  79. $('#year').html(createOptions(saYears, 'id', 'text')).find('option:first').text(bEn ? 'Year' : '選擇年份');
  80. },
  81. /**
  82. * 目的 設定展覽資訊下拉單
  83. * @return {Object} Ajax 物件
  84. */
  85. fnGetExhibitionsTop = function () {
  86. var sState = $('#area').val(),
  87. sYear = $('#year').val(),
  88. sMonth = $('#month').val(),
  89. sDateStart = '',
  90. sDateEnd = '';
  91. if (sYear) {
  92. sDateStart = sYear.toString();
  93. sDateEnd = sYear.toString();
  94. if (sMonth) {
  95. var saMonth = sMonth.split('-'),
  96. sMonth_s = saMonth[0],
  97. sMonth_e = saMonth[1];
  98. sDateStart += '/' + sMonth_s + '/01';
  99. sDateEnd += '/' + sMonth_e + '/' + ('03,12'.indexOf(sMonth_e) > -1 ? '31' : '30');
  100. }
  101. else {
  102. sDateStart += '/01/01';
  103. sDateEnd += '/12/31';
  104. }
  105. }
  106. else {
  107. sDateStart = newDate(null, true);
  108. }
  109. return g_api.ConnectLite(Service.apiwebcom, ComFn.GetExhibitionPage, {
  110. pageIndex: iPageIndex,
  111. pageSize: iPageCount,
  112. IsShowWebSim: "Y",
  113. KeyWords: '',
  114. Area: sState,
  115. DateStart: sDateStart,
  116. DateEnd: sDateEnd
  117. }, function (res) {
  118. if (res.RESULT) {
  119. var oRes = res.DATA.rel;
  120. $('#expo').html(createOptions(oRes.DataList, 'SN', bEn ? 'Exhibitioname_EN' : 'Exhibitioname_TW'));
  121. if (sExpo) {
  122. $('#expo').val(sExpo);
  123. }
  124. $('#expo').select2({
  125. placeholder: bEn ? 'Select Exhibition' : "請選擇展覽"
  126. });
  127. }
  128. });
  129. },
  130. /**
  131. * 目的 獲取展覽報價規則
  132. * @return {Object} Ajax 物件
  133. */
  134. fnGetExhibitionRules = function () {
  135. var sId = $('#expo').val();
  136. if (sId) {
  137. return g_api.ConnectLite(Service.apiwebcom, 'GetExhibitionRules', {
  138. Id: sId
  139. }, function (res) {
  140. if (res.RESULT) {
  141. let MinCBMText = {
  142. "zh-TW": { "A": "(以全部貨量計min)", "S": "(以單件計min)" },
  143. "zh": { "A": "(以全部貨量計min)", "S": "(以單件計min)" },
  144. "en": { "A": "(per shipment)", "S": "(per piece)" },
  145. };
  146. oCostRules = res.DATA.rel;
  147. oCostRules.CostRules = $.parseJSON(oCostRules.CostRules);
  148. oCostRules.HasFeedingRequiredMinCBM = !oCostRules.FeedingRequiredMinCBM ? false : true;
  149. oCostRules.FeedingMinCBMModeText = MinCBMText[sLang][oCostRules.FeedingMinMode] || "";
  150. //if (oCostRules.FeedingMinMode) {
  151. // let UseMode = oCostRules.PackingMinMode;
  152. // oCostRules.FeedingMinCBMModeText = MinCBMText[g_db.GetItem("lang")][oCostRules.FeedingMinMode];
  153. //}
  154. oCostRules.HasPackingRequiredMinCBM = !oCostRules.PackingRequiredMinCBM ? false : true;
  155. oCostRules.PackingMinCBMModeText = MinCBMText[sLang][oCostRules.PackingMinMode] || "";
  156. //if (oCostRules.PackingMinMode) {
  157. // let UseMode = oCostRules.PackingMinMode;
  158. // oCostRules.PackingMinCBMModeText = MinCBMText[g_db.GetItem("lang")][UseMode];
  159. //}
  160. FeeCalculateRules = {
  161. "Packing": {
  162. "MinCBMMode": oCostRules.PackingMinMode,
  163. "MinCBMAmount": oCostRules.PackingRequiredMinCBM,
  164. "Price": oCostRules.PackingPrice,
  165. },
  166. "Feeding": {
  167. "MinCBMMode": oCostRules.FeedingMinMode,
  168. "MinCBMAmount": oCostRules.FeedingRequiredMinCBM,
  169. "Price": oCostRules.FeedingPrice,
  170. },
  171. };
  172. var sHtml = $('#temp_costdoc').render(oCostRules);
  173. $('#CostInstruction').html(sHtml);
  174. $('#inquiryNo dd:not(:last)').remove();//清空現有預估報價
  175. $('.download li a').on('click', function () {
  176. var sName = $(this).attr('filename'),
  177. sPath = $(this).attr('filepath');
  178. DownLoadFile(sPath, sName);
  179. });
  180. }
  181. });
  182. }
  183. else {
  184. $('#CostInstruction').html('');
  185. return $.Deferred().resolve().promise();
  186. }
  187. },
  188. /**
  189. * 目的 取得有效CBM
  190. */
  191. fnGetApproveCBMFee = function (Rule, Type, OriginalCBM, OriginalNum) {
  192. var TotalRoundedCBMs = Round((OriginalCBM * OriginalNum));
  193. switch (Rule.MinCBMMode) {
  194. case "A":
  195. {
  196. let TotalRows = $('#inquiryNo dd').not(':last').length;
  197. var AllDatas = getFormSerialize(eForm);
  198. var AllApproveCBMs = 0;
  199. for (let i = 0; i < TotalRows; i++) {
  200. var PackingInfo = AllDatas["PackingInfo" + i.toString()];
  201. var ApproveCBM = PackingInfo[Type]
  202. ? fnGetCMB(PackingInfo["ExpoLen"], PackingInfo["ExpoWidth"], PackingInfo["ExpoHeight"]) * fnPackNum(PackingInfo["ExpoNumber"])
  203. : 0;
  204. AllApproveCBMs += ApproveCBM;
  205. }
  206. AllApproveCBMs = AllApproveCBMs.toFloat(2);
  207. var ApproveCBM = Rule.MinCBMAmount && Rule.MinCBMAmount > AllApproveCBMs
  208. ? Rule.MinCBMAmount * (TotalRoundedCBMs / AllApproveCBMs)
  209. : TotalRoundedCBMs;
  210. //修正其他每個資料
  211. return ApproveCBM * Rule.Price;
  212. }
  213. case "S":
  214. {
  215. let ApproveCBM = Rule.MinCBMAmount && Rule.MinCBMAmount > OriginalCBM
  216. ? Number(Rule.MinCBMAmount) * OriginalNum
  217. : TotalRoundedCBMs;
  218. return ApproveCBM * Rule.Price;
  219. }
  220. default:
  221. return 0;
  222. }
  223. function Round(data) {
  224. return (data).toFloat(2).toString().toMoney();
  225. }
  226. },
  227. /**
  228. * 目的 以全部貨量計min
  229. */
  230. fnMinFeeAllQty = function () {
  231. //不足Min CBM
  232. //超過1CBM
  233. },
  234. /**
  235. * 目的 預估費用明細區塊
  236. */
  237. fnPackInquiry = function () {
  238. var iIndex = $('#inquiryNo dd').length - 1,
  239. sHtml = $('#temp_costinfo').render({ Index: iIndex });
  240. $('#inquiryNo dd:last').before(sHtml);
  241. fnBindEvent();
  242. },
  243. /**
  244. * 目的 小計計算
  245. * @param {HTMLelement}input 當前區塊資料
  246. */
  247. fnSumSub = function (input) {
  248. //if (input.className.indexOf('inputnumber') > -1) {
  249. // input.value = input.value.toMoney();
  250. //}
  251. var sBoxId = $(input).parents('dd').attr('id'),
  252. data = getFormSerialize(eForm),
  253. curData = data[sBoxId];
  254. curData = fnPackItem(curData);
  255. input.AnyError = CheckLimited(curData);
  256. $('#' + sBoxId).find('.subtext').text(curData.SubText.join(' / '));
  257. $('#' + sBoxId).find('.subtotal').text('NT$' + fMoney(curData.SubTotal, 0, 'NTD'));
  258. $('[name="' + sBoxId + '[SubTotal]"]').val(curData.SubTotal);
  259. let TotalRows = $('#inquiryNo dd').not(':last').length;
  260. let SubTotal = 0;
  261. for (let i = 0; i < TotalRows; i++) {
  262. let CurrentPacking = "PackingInfo" + i.toString();
  263. if (sBoxId != CurrentPacking) {
  264. fnPackItem(data[CurrentPacking]);
  265. $('#' + CurrentPacking + " .subtotal").text(SetMoney(data[CurrentPacking].SubTotal, true));
  266. }
  267. SubTotal += data[CurrentPacking].SubTotal;
  268. }
  269. $('.totaltext').text(SetMoney(SubTotal, true));
  270. function SetMoney(val, flag) {
  271. return (flag ? 'NT$' : '') + fMoney(val || 0, 0, 'NTD');
  272. }
  273. },
  274. fnGetCMB = function (ExpoLen, ExpoWidth, ExpoHeight) {
  275. return fnPackNum(ExpoLen) * fnPackNum(ExpoWidth) * fnPackNum(ExpoHeight) / 1000000;//CBM
  276. },
  277. CheckLimited = function (curdata) {
  278. let AnyError = false;
  279. if (curdata['ExpoWeight'] > -1) {
  280. var MaxWeight = oCostRules.CostRules
  281. .map(c => parseFloat(c.Weight_Max) || 0)
  282. .reduce((x, y) => {
  283. return Math.max(x, y);
  284. }) * 1000;
  285. if (curdata['ExpoWeight'] * 1 > MaxWeight) {
  286. AnyError = true;
  287. }
  288. }
  289. if (curdata['ExpoHeight'] * 1 >= 300) {
  290. AnyError = true;
  291. }
  292. if (curdata['ExpoLen'] * 1 > 999) {
  293. AnyError = true;
  294. }
  295. if (curdata['ExpoWidth'] * 1 > 999) {
  296. AnyError = true;
  297. }
  298. if (curdata['ExpoNumber'] * 1 > 99) {
  299. AnyError = true;
  300. }
  301. return AnyError;
  302. },
  303. /**
  304. * 目的 處理當前費用項目
  305. * @param {Object} curdata 當前input值
  306. * @return {Object} 當前服務項目計算對象
  307. */
  308. fnPackItem = function (curdata) {
  309. curdata.ExpoLen = curdata.ExpoLen === '' ? '0' : curdata.ExpoLen;
  310. curdata.ExpoWidth = curdata.ExpoWidth === '' ? '0' : curdata.ExpoWidth;
  311. curdata.ExpoHeight = curdata.ExpoHeight === '' ? '0' : curdata.ExpoHeight;
  312. curdata.TotalCBM = fnGetCMB(curdata.ExpoLen, curdata.ExpoWidth, curdata.ExpoHeight);
  313. //fnPackNum(curdata.ExpoLen) * fnPackNum(curdata.ExpoWidth) * fnPackNum(curdata.ExpoHeight) / 1000000;//CBM
  314. curdata.ExpoWeight = fnPackNum(curdata.ExpoWeight);//重量
  315. curdata.ExpoWeightTon = curdata.ExpoWeight / 1000;//噸
  316. curdata.ExpoNumber = fnPackNum(curdata.ExpoNumber);//件數
  317. curdata.SubTotal = 0;//小計
  318. //curdata.ExpoDays = fnPackNum(curdata.ExpoDays);//天數
  319. curdata.SubText = [];//
  320. curdata.ExpoStack = curdata.ExpoStack || false; //推高機項目
  321. curdata.ExpoSplit = curdata.ExpoSplit || false;//拆箱項目
  322. curdata.ExpoPack = curdata.ExpoPack || false;//裝箱項目
  323. curdata.ExpoFeed = curdata.ExpoFeed || false;//空箱收送
  324. curdata.ExpoStorage = curdata.ExpoStorage || false;//[20190613 已移除]
  325. var oExpoType = {
  326. '01': bEn ? 'Unwrapped' : '裸機',
  327. '02': bEn ? 'Wooden Crate' : '木箱',
  328. '03': bEn ? 'Bulk Cargo' : '散貨',
  329. '04': bEn ? 'Pallet' : '打板',
  330. '05': bEn ? 'Other' : '其他'
  331. };
  332. curdata.ExpoTypeText = oExpoType[curdata.ExpoType];//
  333. if (curdata.ExpoNumber > 0) {//件數
  334. curdata.SubText.push(curdata.ExpoNumber.toString().toMoney() + (bEn ? 'package' : '件'));
  335. if (curdata.TotalCBM > 0) {//CBM
  336. var iTotalCBM = curdata.TotalCBM * curdata.ExpoNumber;
  337. curdata.SubText.push(iTotalCBM.toFloat(2).toString().toMoney() + 'CBM');
  338. }
  339. if (curdata.ExpoWeight > 0) {//KG
  340. var iExpoWeight = curdata.ExpoWeight * curdata.ExpoNumber;
  341. if (iExpoWeight < 1) {
  342. iExpoWeight = 1;
  343. }
  344. curdata.SubText.push(iExpoWeight.toFloat(2).toString().toMoney() + 'KG');
  345. }
  346. }
  347. let HasCBMAndExpoNumber = curdata.TotalCBM > 0 && curdata.ExpoNumber > 0;
  348. let TotalCBMs = curdata.TotalCBM * curdata.ExpoNumber;
  349. if (curdata.ExpoSplit && HasCBMAndExpoNumber) {//拆箱
  350. //Packing Feeding
  351. let ApproveCBMFee = fnGetApproveCBMFee(FeeCalculateRules.Packing, "ExpoSplit", curdata.TotalCBM, curdata.ExpoNumber);
  352. curdata.SubTotal += ApproveCBMFee;
  353. }
  354. if (curdata.ExpoPack && HasCBMAndExpoNumber) {//裝箱
  355. let ApproveCBMFee = fnGetApproveCBMFee(FeeCalculateRules.Packing, "ExpoPack", curdata.TotalCBM, curdata.ExpoNumber);
  356. curdata.SubTotal += ApproveCBMFee;
  357. }
  358. if (curdata.ExpoFeed && HasCBMAndExpoNumber) {// 空箱收送與儲存(展覽期間),等同裝箱計價規則
  359. let ApproveCBMFee = fnGetApproveCBMFee(FeeCalculateRules.Feeding, "ExpoFeed", curdata.TotalCBM, curdata.ExpoNumber);
  360. curdata.SubTotal += ApproveCBMFee;
  361. }
  362. if (curdata.ExpoStack && curdata.ExpoWeightTon > 0 && curdata.ExpoNumber > 0) {//堆高
  363. /*** 2019/01/22 Yang Leo 台北駒驛「線上預約」堆高機價格計算方式調整「材積重」及「重量」擇一個重的去計價 Star ***/
  364. //尺寸:200x200x200cm(換算材積重 = 1,336KGS)
  365. //公式 = 長 寬 高 / 1000000 * 167
  366. //重量:900KGS
  367. //目前系統公式直接以重量900KGS計價 -> $920 / 件
  368. //明年改為以材積重1,336KGS去計價 -> $1,700 / 件
  369. if (curdata.TotalCBM * 167 > curdata.ExpoWeight) { //公式=長*寬*高/1000000*167
  370. curdata.ExpoWeightTon = curdata.TotalCBM * 167 / 1000;
  371. }
  372. /*** 2019/01/22 Yang Leo 台北駒驛「線上預約」堆高機價格計算方式調整「材積重」及「重量」擇一個重的去計價 End ***/
  373. var rule = fnGetCurRule(curdata.ExpoWeightTon);
  374. switch (rule.PricingMode) {
  375. case 'T':
  376. {
  377. curdata.SubTotal += curdata.ExpoWeightTon * curdata.ExpoNumber * fnPackNum(rule.Price);
  378. }
  379. break;
  380. case 'N':
  381. {
  382. curdata.SubTotal += curdata.ExpoNumber * fnPackNum(rule.Price);
  383. }
  384. break;
  385. default:
  386. {
  387. //debugger;
  388. //showMsg(bEn ? 'Special specifications, please call +886-2-2785-7900.' : '貨物內有特殊規格,敬請來電詢價02-2785-7900');
  389. }
  390. break;
  391. }
  392. }
  393. return curdata;
  394. },
  395. /**
  396. * 目的 綁定事件
  397. */
  398. fnBindEvent = function () {
  399. $('#inquiryNo dd').find('.delete').off('click').on('click', function () {
  400. $(this).parent().remove();
  401. $('#inquiryNo dd').not(':last').each(function (index) {
  402. var that = this;
  403. if (that.id) {
  404. var sNewId = 'PackingInfo' + index;
  405. $(this).find('[name]').each(function () {
  406. var name = $(this).attr('name');
  407. if (name.indexOf(that.id) > -1) {
  408. $(this).attr('name', name.replace(that.id, sNewId))
  409. }
  410. });
  411. that.id = sNewId;
  412. }
  413. });
  414. var firstInput = $('#inquiryNo').find(':input[type="text"]:first');
  415. if (firstInput.length > 0) {
  416. firstInput.change();
  417. }
  418. else {
  419. $('[name="Total"]').val('0');
  420. $('.totaltext').text('0');
  421. }
  422. });
  423. $('#inquiryNo').find(':input').off('change keypress keyup').on('change keypress keyup', function (e) {
  424. var _input = this;
  425. if (!$('#expo').val()) {
  426. showMsg(bEn ? 'Please select exhibition' : '請選擇展覽'); // 請選擇展覽
  427. return false;
  428. }
  429. if (_input.type === 'select-one') {
  430. return false;
  431. }
  432. if (_input.type === 'checkbox') {
  433. fnDisabledPack(_input);//拆箱和裝箱服務不能再單獨選擇收送或儲存
  434. }
  435. if (e.type === 'keypress') {
  436. if (!String.fromCharCode(e.keyCode).match(/[0-9\.]/)) {//防止輸入“e”
  437. return false;
  438. }
  439. }
  440. else {
  441. fnSumSub(_input);
  442. if (_input.AnyError) {
  443. showMsg(bEn ? 'Special specifications, please call +886-2-2785-7900.' : '貨物內有特殊規格,敬請來電詢價02-2785-7900');
  444. $('#goappoint').addClass("isDisabled");
  445. }
  446. else {
  447. $('#goappoint').removeClass("isDisabled");
  448. }
  449. }
  450. });
  451. fnsubtotalval();
  452. $('#inquiryNo dd').each(function () {
  453. var boxchecked = $(this).find(':input[type="checkbox"]:not(:first):checked');
  454. if (boxchecked.length > 0) {
  455. fnDisabledPack(boxchecked[0]);
  456. }
  457. });
  458. moneyInput($('.inputnumber'), 0);
  459. },
  460. /**
  461. * 目的 禁用服務
  462. * @param {HTMLElement} el 當前input值
  463. */
  464. fnsubtotalval = function () {
  465. var iTotal = 0;
  466. $('.subtotalval').each(function () {
  467. iTotal += this.value * 1;
  468. });
  469. $('[name="Total"]').val(iTotal);
  470. iTotal = fMoney(iTotal, 0, 'NTD');
  471. $('.totaltext').text(iTotal);
  472. },
  473. /**
  474. * 目的 禁用服務
  475. * @param {HTMLElement} el 當前input值
  476. */
  477. fnDisabledPack = function (el) {
  478. //var ul = $(el).parents('ul'),
  479. // bCheck = false;
  480. //if (el.id.indexOf('ExpoSplit') > -1 || el.id.indexOf('ExpoPack') > -1) {
  481. // ul.find('.packing').each(function () {
  482. // if (this.checked) {
  483. // bCheck = true;
  484. // return false;
  485. // }
  486. // });
  487. // if (bCheck) {
  488. // ul.find('.single-packing,.textStyle').prop('disabled', true);
  489. // ul.find('.textStyle').val('');
  490. // }
  491. // else {
  492. // ul.find('.single-packing,.textStyle').prop('disabled', false);
  493. // }
  494. //}
  495. //else if (el.id.indexOf('ExpoFeed') > -1 || el.id.indexOf('ExpoStorage') > -1) {
  496. // ul.find('.single-packing').each(function () {
  497. // if (this.checked) {
  498. // bCheck = true;
  499. // return false;
  500. // }
  501. // });
  502. // if (bCheck) {
  503. // ul.find('.packing').prop('disabled', true);
  504. // /*** 2019/01/22 Yang Leo 點選「空箱收送」時,已包含「空箱存放」,直接鎖住「空箱存放」欄位 和 點選「空箱存放」時,直接鎖住「空箱收送」欄位 Star ***/
  505. // if (oCostRules.IsMerge === 'Y') {
  506. // if (el.id.indexOf('ExpoFeed') > -1) {
  507. // ul.find("[id^='ExpoStorage'],.textStyle").prop('disabled', true);
  508. // ul.find(".textStyle").val('');
  509. // } else {
  510. // ul.find("[id^='ExpoFeed']").prop('disabled', true);
  511. // }
  512. // }
  513. // /*** 2019/01/22 Yang Leo 點選「空箱收送」時,已包含「空箱存放」,直接鎖住「空箱存放」欄位 和 點選「空箱存放」時,直接鎖住「空箱收送」欄位 End ***/
  514. // }
  515. // else {
  516. // ul.find('.packing').prop('disabled', false);
  517. // /*** 2019/01/22 Yang Leo 取消點選「空箱收送」時,已包含「空箱存放」,直接解鎖「空箱存放」欄位 和 取消點選「空箱存放」時,直接解鎖「空箱收送」欄位 Star ***/
  518. // if (oCostRules.IsMerge === 'Y') {
  519. // if (el.id.indexOf('ExpoFeed') > -1) {
  520. // ul.find("[id^='ExpoStorage'],.textStyle").prop('disabled', false);
  521. // } else {
  522. // ul.find("[id^='ExpoFeed']").prop('disabled', false);
  523. // }
  524. // }
  525. // /*** 2019/01/22 Yang Leo 取消點選「空箱收送」時,已包含「空箱存放」,直接解鎖「空箱存放」欄位 和 取消點選「空箱存放」時,直接解鎖「空箱收送」欄位 End ***/
  526. // }
  527. //}
  528. },
  529. /**
  530. * 目的 轉換數字
  531. * @param {String}str 當前input值
  532. * @return {Number} 轉化後數字
  533. */
  534. fnPackNum = function (str) {
  535. return ((str || '') === '' ? '0' : str) * 1;
  536. },
  537. /**
  538. * 目的 獲取當前適應費用規則
  539. * @param {Number}weight 當前重量
  540. * @return {Object} 當前要抓取的規則對象
  541. */
  542. fnGetCurRule = function (weight) {
  543. var oRule = {};
  544. $.each(oCostRules.CostRules, function (index, item) {
  545. let rule_min = fnPackNum(item.Weight_Min);
  546. let rule_max = fnPackNum(item.Weight_Max);
  547. let RoundedWeight = Math.ceil(weight * 10) / 10;
  548. if (RoundedWeight >= rule_min && RoundedWeight <= rule_max || (weight === 30 && rule_max === 30)) {
  549. oRule = item;
  550. return false;
  551. }
  552. });
  553. return oRule;
  554. },
  555. /**
  556. * 目的 Go預約
  557. * @return {Boolean} 停止符
  558. */
  559. fnGoAppoint = function () {
  560. $('#inquiryNo dd').each(function () {
  561. var boxchecked = $(this).find(':input[type="checkbox"]:not(:first):checked');
  562. if (boxchecked.length > 0) {
  563. fnDisabledPack(boxchecked[0]);
  564. }
  565. });
  566. var sExpo = $('#expo').val(),
  567. data = getFormSerialize(eForm),
  568. oOrderInfo = {},
  569. sError = '';
  570. oOrderInfo.ExhibitionNO = sExpo;
  571. oOrderInfo.PackingInfo = [];
  572. //oOrderInfo.Total = data.Total;
  573. if (!oOrderInfo.ExhibitionNO) {
  574. sError += bEn ? 'Please select exhibition<br/>' : '請選擇展覽<br/>'; // 請選擇展覽
  575. }
  576. oOrderInfo.Total = 0
  577. $('#inquiryNo dd:not(:last)').each(function (index) {
  578. var item = data['PackingInfo' + index],
  579. iNum = index + 1;
  580. if (item) {
  581. item = fnPackItem(item);
  582. oOrderInfo.Total += item.SubTotal;
  583. item.Index = index;
  584. oOrderInfo.PackingInfo.push(item);
  585. if (item.ExpoStack || item.ExpoSplit || item.ExpoPack || item.ExpoFeed || item.ExpoStorage) {
  586. if (item.ExpoNumber === 0) {
  587. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Number of pieces] cannot be empty<br/>' : ':[件數]不能為空<br/>'); // 件數不能為空
  588. }
  589. if (item.ExpoStack) {
  590. if (item.ExpoWeightTon === 0) {
  591. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Forklift] service weight cannot be empty<br/>' : ':[堆高機]服務重量不能為空<br/>'); // [堆高機服務]重量不能為空
  592. }
  593. if (item.TotalCBM === 0) {
  594. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Forklift] service dimensions cannot be empty<br/>' : ':[堆高機]服務尺寸不能為空<br/>'); // [堆高機]服務尺寸不能為空
  595. }
  596. }
  597. if (item.ExpoSplit) {
  598. if (item.TotalCBM === 0) {
  599. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Packing] service dimensions cannot be empty<br/>' : ':[裝箱]服務尺寸不能為空<br/>'); // [裝箱]服務尺寸不能為空
  600. }
  601. }
  602. if (item.ExpoPack) {
  603. if (item.TotalCBM === 0) {
  604. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Unpacking (including empty crate transport & storage)] service dimensions shall not be empty<br/>' : ':[拆箱(含空箱收送與儲存)]服務尺寸不能為空<br/>'); // [拆箱(含空箱收送與儲存)]服務尺寸不能為空
  605. }
  606. }
  607. if (item.ExpoFeed) {
  608. if (item.TotalCBM === 0) {
  609. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Empty Crate Transport] service dimensions cannot be empty<br/>' : ':[空箱收送]服務尺寸不能為空<br/>'); // 空箱收送服務尺寸不能為空
  610. }
  611. }
  612. if (item.ExpoStorage) {
  613. if (item.TotalCBM === 0) {
  614. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[empty storage/storage] service dimensions must not be empty<br/>' : '[空箱存放 / 存放]服務尺寸不能為空<br/>'); //[空箱存放 / 存放]服務尺寸不能為空
  615. }
  616. if (item.ExpoDays === 0) {
  617. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':[Empty Crate Storage] service days cannot be empty<br/>' : ':[空箱存放 / 存放]服務天數不能為空<br/>'); //[空箱存放 / 存放]服務天數不能為空
  618. }
  619. }
  620. }
  621. else {
  622. sError += (bEn ? 'Project' : '項目') + iNum + (bEn ? ':Please choose at least one service<br/>' : ':請至少選擇一種服務<br/>'); // 請至少選擇一種服務
  623. }
  624. }
  625. });
  626. if (oOrderInfo.PackingInfo.length === 0) {
  627. sError += bEn ? 'Please fill in the exhibition estimated quotation information<br/>' : '請填寫展覽預估報價資訊<br/>'; // 請填寫展覽預估報價資訊
  628. }
  629. if (sError) {
  630. showMsg(sError);
  631. return false;
  632. }
  633. else {
  634. g_db.SetDic('Expo', sExpo);
  635. g_db.SetDic('ExpoName', $('#expo option:selected').text());
  636. g_db.SetDic('OrderInfo', oOrderInfo.PackingInfo);
  637. g_db.SetDic('Total', oOrderInfo.Total);
  638. window.location.href = window.location.origin + '/TG/page/inquiryForm' + (bEn ? '_en' : '') + '.html';
  639. }
  640. },
  641. init = function () {
  642. var myHelpers = {
  643. getFileName: function (val) {
  644. return val ? val.split('.')[0] : '';
  645. },
  646. setMoney: function (val, flag) {
  647. return (flag ? 'NT$' : '') + fMoney(val || 0, 0, 'NTD');
  648. },
  649. setCheck: function (val) {
  650. return val ? 'checked="checked"' : '';
  651. },
  652. setSubtext: function (val) {
  653. return val ? val.join(' / ') : '';
  654. },
  655. setWeight: function (val) {
  656. return (val || 0) * 1000;
  657. }
  658. };
  659. $.views.helpers(myHelpers);
  660. $.whenArray([fnSetDate(), fnGetArguments(), fnGetExhibitionsTop()]).done(function () {
  661. fnGetExhibitionRules().done(function () {
  662. if (saOrderInfo) {
  663. if (typeof saOrderInfo === 'string') {
  664. saOrderInfo = JSON.parse(saOrderInfo);
  665. }
  666. var sHtml = $('#temp_costinfo').render(saOrderInfo);
  667. $('#inquiryNo dd:last').before(sHtml);
  668. $('[name="Total"]').val(iTotal);
  669. $('.totaltext').text(fMoney(iTotal, 0, 'NTD'));
  670. $.each(saOrderInfo, function (index, item) {
  671. $('[name="PackingInfo' + index + '[ExpoType]"]').val(item.ExpoType);
  672. });
  673. fnBindEvent();
  674. }
  675. else {
  676. fnPackInquiry();//在新預設一項
  677. }
  678. });
  679. });
  680. $('#inquiryIntro').fancybox({
  681. src: 'inquiryIntro' + (bEn ? '_en' : '') + '.html',
  682. type: 'iframe',
  683. smallBtn: true,
  684. iframe: {
  685. css: {
  686. width: '500px'
  687. }
  688. }
  689. });
  690. $('.expo-search').on('change', function () {
  691. $('.totaltext').text("0");
  692. fnGetExhibitionsTop().done(function () {
  693. fnGetExhibitionRules();
  694. });
  695. });
  696. $('.add').on('click', function () {
  697. fnPackInquiry();
  698. });
  699. $('#goappoint').on('click', function () {
  700. fnGoAppoint();
  701. });
  702. $('#expo').on('change', function () {
  703. fnGetExhibitionRules().done(function () {
  704. fnPackInquiry();//在新預設一項
  705. $('#inquiryNo').find(':input[type="text"]:first').change();
  706. });
  707. });
  708. };
  709. init();
  710. });