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.

287 lines
12 KiB

2 years ago
  1. var sRefNumber = getUrlParam('RefNumber');
  2. $(function () {
  3. 'use strict';
  4. var sRandomCode = '',
  5. sIp = '',
  6. sIPInfo = '',
  7. oCurData = {},
  8. sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW',
  9. /*
  10. * 目的设置名称
  11. * @return
  12. * 作者John
  13. *********************************************/
  14. fnSetName = function () {
  15. if (sLang === 'zh') {
  16. var oSupplierName = $('#SupplierName');
  17. oSupplierName.text(simplized(oSupplierName.text()));
  18. }
  19. },
  20. /*
  21. * 目的初始化查詢區塊
  22. * @return
  23. * 作者John
  24. *********************************************/
  25. fnInitQueryBox = function () {
  26. var elQueryBox = $('#temp_query').render();
  27. $('#right').html(elQueryBox);
  28. $('#form_onlinetrack').validate({
  29. errorPlacement: function (error, element) {
  30. error.css({
  31. "border": "none",
  32. "color": "red"
  33. });
  34. var wrapper = $("<p></p>");
  35. error.appendTo(wrapper);
  36. $(element).parent().after(wrapper);
  37. },
  38. highlight: function (element, errorClass) {
  39. $(element).css({
  40. "border": "1px solid red"
  41. });
  42. },
  43. unhighlight: function (element, errorClass) {
  44. $(element).css({
  45. "border": ""
  46. });
  47. },
  48. rules: {
  49. },
  50. messages: {
  51. trackingno: {
  52. required: { 'zh-TW': '請輸入查詢號碼', 'zh': '请输入查询号码', 'en': 'Please enter a query number' }[sLang]
  53. },
  54. validcode: {
  55. required: { 'zh-TW': '請輸入驗證碼', 'zh': '请输入验证码', 'en': 'Please enter the verification code' }[sLang]
  56. }
  57. }
  58. });
  59. $(".btnquery").click(function () {
  60. fnGetData()
  61. });
  62. $('#change_validcode,.change_validcode').on('click', function () {
  63. var url = $('#imgvalidcode').data('url') || $('#imgvalidcode').attr('src');
  64. $('#imgvalidcode').attr('src', url + '&' + Math.random()).data('url', url);
  65. });
  66. },
  67. /**
  68. * 獲取資料
  69. * @return {Boolean} 是否停止
  70. */
  71. fnGetData = function () {
  72. var sTrackingNo = $('#trackingno').val(),
  73. sValidCode = $('#validcode').val();
  74. if (!$('#form_onlinetrack').valid()) {
  75. return false;
  76. }
  77. g_api.ConnectLite(Service.apite, 'GetTrackingProgress', {
  78. flag: 'cap4',
  79. QueryNum: sTrackingNo,
  80. ValidCode: sValidCode,
  81. IP: sIp,
  82. IPInfo: sIPInfo
  83. }, function (res) {
  84. if (res.RESULT) {
  85. fnReleseData(res.DATA.rel, sTrackingNo);
  86. }
  87. else {
  88. $('#change_validcode').click();
  89. showMsg(res.MSG, 'error'); //提示錯誤
  90. }
  91. }, null, null, { 'zh-TW': '資料查詢中...', 'zh': '资料查询中...', 'en': 'Data query...' }[sLang]);
  92. },
  93. fnReleseData = function (data, num) {
  94. if (JSON.stringify(data) !== "{}") {
  95. oCurData = data;
  96. var sType = num.substr(2, 2),
  97. sHtmlInfo = '',
  98. fnReleaseObj = function (o) {
  99. var saLi = [];
  100. for (var key in o) {
  101. if (typeof o[key] === 'object') {
  102. var nobj = o[key];
  103. nobj.keyName = key;
  104. saLi.push(nobj);
  105. }
  106. }
  107. saLi = saLi.sort(function (a, b) {
  108. return new Date(a.Date === '' ? new Date() : a.Date) > new Date(b.Date === '' ? new Date() : b.Date);
  109. });
  110. return saLi;
  111. },
  112. myHelpers = {
  113. checkFlowName: function (name) {
  114. var bRtn = false;
  115. if (name === 'IMPORT' || name.indexOf('RETURN') > -1) {
  116. bRtn = true;
  117. }
  118. return bRtn;
  119. },
  120. setJson: function (val, name) {
  121. var o = $.parseJSON(val);
  122. return getJsonVal(o, name) || '';
  123. },
  124. setBtn: function (val, btntype, path) {
  125. var o = $.parseJSON(val),
  126. oBtn = $('<input>', {
  127. type: 'button', class: 'btn btnStyle signaturefile', value: '取得簽收證明', 'data-i18n': 'common.ObtainProofofDelivery', 'data-path': path, id: 'btn-' + btntype
  128. });
  129. if (!o.complete || !path) {
  130. oBtn.attr('disabled', true);
  131. }
  132. return oBtn[0].outerHTML;
  133. },
  134. setInfo: function (val, type) {
  135. var o = $.parseJSON(val),
  136. saLi = fnReleaseObj(o),
  137. saInfoHtml = [],
  138. iLastIndex = 0;
  139. $.each(saLi, function (idx, li) {
  140. if (li.Checked) {
  141. iLastIndex = idx;
  142. saInfoHtml.push('<div class="tr templ_class' + iLastIndex + '">\
  143. <div class= "td" >' + (li.Date || '').substr(0, 10) + '</div >\
  144. <div class="td center" data-i18n="' + type + '.' + li.keyName + '"></div>\
  145. <div class="td center">' + (li.keyName === "InTransit1" ? `ETA ${li.ETA}: ${li.ETADate}` : (li.Remark || '')) + '</div>\
  146. </div >');
  147. }
  148. });
  149. return saInfoHtml.reverse().join('').replace('templ_class' + iLastIndex, 'blue bold');
  150. },
  151. setFlow: function (val, type) {
  152. var o = $.parseJSON(val),
  153. saLi = fnReleaseObj(o),
  154. elDiv = $('<div>'),
  155. iActive = -1;
  156. $.each(saLi, function (idx, li) {
  157. if (li.Date !== undefined) {
  158. var sChecked = li.Checked,
  159. elLi = "";
  160. if (sLang === "en") {
  161. elLi = $('<li>', { class: '', html: '<p data-i18n="' + type + '.' + li.keyName + '"></p><div></div><span class="entab"></span>' });
  162. } else {
  163. elLi = $('<li>', { class: '', html: '<p data-i18n="' + type + '.' + li.keyName + '"></p><div></div><span></span>' });
  164. }
  165. if (o.complete && saLi.length - 1 === idx) {
  166. elLi = $('<li>', { class: 'bluePro', html: '<p><b data-i18n="' + type + '.' + li.keyName + '"></b><img src="' + (sLang === 'zh-TW' ? '' : '../') + 'images/tick.svg" width="18" height="18"></p><div></div><span></span>' });
  167. }
  168. if (sChecked) {
  169. elLi.addClass('active');
  170. //elLi.find('.print-img').attr('src', '' + (sLang === 'zh-TW' ? '' : '../') + 'images/progress_print.png');
  171. }
  172. if (!sChecked && iActive === -1) {
  173. iActive = idx;
  174. }
  175. elDiv.append(elLi);
  176. }
  177. });
  178. if (iActive > 0) {
  179. elDiv.find('li').eq(iActive - 1).addClass('bluePro');
  180. }
  181. return elDiv.html() + '<p class="clear"></p>';
  182. },
  183. setBillLadNOSub: function (val) {
  184. return val.replaceAll('/', '<br>').replaceAll(',', '<br>').replaceAll(',', '<br>').replaceAll(';', '<br>').replaceAll(';', '<br>').replace('|', '<br>').replace('|', '<br>').replace('|', '<br>').replace('|', '<br>');
  185. },
  186. setSupplierName: function (cnname, enname) {
  187. var sName = cnname;
  188. if (!cnname) {
  189. sName = enname || '';
  190. }
  191. return sName;
  192. }
  193. };
  194. $.views.helpers(myHelpers);
  195. sHtmlInfo = $('#temp_queryinfo').render(oCurData);
  196. $('#right').html(sHtmlInfo);
  197. $(".sidebar-1,.btnquery-next").click(function (e) {
  198. fnInitQueryBox();
  199. $('#change_validcode').click();
  200. });
  201. $(".btnprint").click(function (e) {
  202. //window.print();
  203. $('#right').jqprint({ operaSupport: false });
  204. });
  205. if ($(".signaturefile").length > 0) {
  206. $('.signaturefile').click(function (e) {
  207. var sPath = $(this).attr('data-path'),
  208. sFileName = num + '_' + this.id.replace('btn-', '');
  209. DownLoadFile(sPath, sFileName);
  210. });
  211. }
  212. transLang();
  213. fnSetName();
  214. }
  215. },
  216. /*
  217. * 初始化 function
  218. * @param
  219. * @return
  220. * 起始作者John
  221. * 起始日期2016/05/21
  222. * 最新修改人John
  223. * 最新修日期2016/11/03
  224. */
  225. init = function () {
  226. fnInitQueryBox();
  227. if (sRefNumber) {
  228. $('#trackingno').val(sRefNumber);
  229. }
  230. $.ajax({
  231. type: 'get',
  232. //jsonpCallback: "ipCallback",//callback的function名称
  233. //url: 'https://www.taobao.com/help/getip.php',
  234. //dataType: 'jsonp',
  235. url: 'https://api.ipify.org?format=json&callback=?',
  236. dataType: 'json',
  237. success: function (res) {
  238. sIp = res.ip;
  239. g_api.ConnectLite(Service.apiappcom, 'GetIPInfo', {
  240. ip: sIp
  241. }, function (res1) {
  242. if (res1.RESULT) {
  243. var oIpInfo = JSON.parse(res1.DATA.rel);
  244. if (oIpInfo.code === 0) {
  245. sIPInfo = Tostr(oIpInfo.data);
  246. }
  247. }
  248. });
  249. }
  250. });
  251. if ($(window).width() < 800) {
  252. $(".target").scroll(function () {
  253. if ($(".target").scrollLeft() > 140) {
  254. //alert("dsfsdf");
  255. $(this).parent().removeClass("tWarpper");
  256. } else {
  257. $(this).parent().addClass("tWarpper");
  258. }
  259. });
  260. }
  261. $(document).on('keydown', function (e) {
  262. if (e.keyCode === 13) {
  263. $(".btnquery").click();
  264. }
  265. });
  266. setLang(sLang);
  267. };
  268. init();
  269. });