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.

367 lines
16 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. materialForm = function () {
  10. return $('.material-field').focus(function () {
  11. $('.errormsg').text('').hide();
  12. return $(this).closest('.form-group-material').addClass('focused has-value');
  13. }).focusout(function () {
  14. $('.errormsg').text('').hide();
  15. return $(this).closest('.form-group-material').removeClass('focused');
  16. }).blur(function () {
  17. if (!this.value) {
  18. $(this).closest('.form-group-material').removeClass('has-value');
  19. }
  20. return $(this).closest('.form-group-material').removeClass('focused');
  21. });
  22. },
  23. /*
  24. * 目的生成一个随机数
  25. * @param minint最小值
  26. * @param maxint最大值
  27. * @return
  28. * 作者John
  29. *********************************************/
  30. randomNum = function (min, max) {
  31. return Math.floor(Math.random() * (max - min) + min);
  32. },
  33. /*
  34. * 目的生成一个随机色
  35. * @param minint最小值
  36. * @param maxint最大值
  37. * @return
  38. * 作者John
  39. *********************************************/
  40. randomColor = function (min, max) {
  41. var r = randomNum(min, max);
  42. var g = randomNum(min, max);
  43. var b = randomNum(min, max);
  44. return "rgb(" + r + "," + g + "," + b + ")";
  45. },
  46. /*
  47. * 目的绘制验证码图片
  48. * @param minint最小值
  49. * @param maxint最大值
  50. * @return
  51. * 作者John
  52. *********************************************/
  53. fnDrawPic = function () {
  54. var canvas = document.getElementById("canvas");
  55. var width = canvas.width;
  56. var height = canvas.height;
  57. var ctx = canvas.getContext('2d');
  58. ctx.textBaseline = 'bottom';
  59. /**绘制背景色**/
  60. ctx.fillStyle = randomColor(180, 240); //颜色若太深可能导致看不清
  61. ctx.fillRect(0, 0, width, height);
  62. /**绘制文字**/
  63. //var str = 'ABCEFGHJKLMNPQRSTWXY123456789';
  64. var str = '123456789';
  65. sRandomCode = '';
  66. for (var i = 0; i < 4; i++) {
  67. var txt = str[randomNum(0, str.length)];
  68. sRandomCode += txt;
  69. ctx.fillStyle = randomColor(50, 60); //随机生成字体颜色
  70. ctx.font = randomNum(35, 40) + 'px SimHei'; //随机生成字体大小
  71. var x = 10 + i * 25;
  72. var y = randomNum(40, 40);
  73. var deg = randomNum(-45, 45);
  74. //修改坐标原点和旋转角度
  75. ctx.translate(x, y);
  76. ctx.rotate(deg * Math.PI / 270);
  77. ctx.fillText(txt, 0, 0);
  78. //恢复坐标原点和旋转角度
  79. ctx.rotate(-deg * Math.PI / 270);
  80. ctx.translate(-x, -y);
  81. }
  82. /**绘制干扰线**/
  83. //for (var i = 0; i < 8; i++) {
  84. // ctx.strokeStyle = randomColor(40, 180);
  85. // ctx.beginPath();
  86. // ctx.moveTo(randomNum(0, width), randomNum(0, height));
  87. // ctx.lineTo(randomNum(0, width), randomNum(0, height));
  88. // ctx.stroke();
  89. //}
  90. /**绘制干扰点**/
  91. for (var i = 0; i < 100; i++) {
  92. ctx.fillStyle = randomColor(0, 255);
  93. ctx.beginPath();
  94. ctx.arc(randomNum(0, width), randomNum(0, height), 1, 0, 2 * Math.PI);
  95. ctx.fill();
  96. }
  97. },
  98. /*
  99. * 目的设置名称
  100. * @return
  101. * 作者John
  102. *********************************************/
  103. fnSetName = function () {
  104. var oSupplierName = $('#SupplierName'),
  105. sTranName = !oCurData.SupplierName ? oCurData.SupplierEName : oCurData.SupplierName;
  106. if (sLang == 'zh-TW') {
  107. oSupplierName.text(sTranName);
  108. }
  109. else if (sLang == 'zh') {
  110. oSupplierName.text(sTranName);
  111. }
  112. },
  113. /**
  114. * 獲取資料
  115. * @param sQueryNum{String}查詢號碼
  116. * @return
  117. * 起始作者John
  118. * 起始日期2017/01/05
  119. * 最新修改人John
  120. * 最新修日期2017/01/05
  121. */
  122. fnGetData = function (sQueryNum) {
  123. g_api.ConnectLite(Service.apite, 'GetTrackingProgress', {
  124. QueryNum: sQueryNum,
  125. IP: sIp,
  126. IPInfo: sIPInfo
  127. }, function (res) {
  128. if (res.RESULT) {
  129. fnReleseData(res.DATA.rel, sQueryNum);
  130. }
  131. }, null, null, i18next.t('message.Querying'));
  132. },
  133. fnReleseData = function (data, num) {
  134. if (JSON.stringify(data) !== "{}") {
  135. oCurData = data;
  136. var sType = num.substr(2, 2),
  137. sHtmlInfo = '',
  138. fnReleaseObj = function (o) {
  139. var saLi = [];
  140. for (var key in o) {
  141. if (typeof o[key] === 'object') {
  142. var nobj = o[key];
  143. nobj.keyName = key;
  144. saLi.push(nobj);
  145. }
  146. }
  147. saLi = saLi.sort(function (a, b) {
  148. return new Date(a.Date === '' ? new Date() : a.Date) > new Date(b.Date === '' ? new Date() : b.Date);
  149. });
  150. return saLi;
  151. },
  152. myHelpers = {
  153. checkFlowName: function (name) {
  154. var bRtn = false;
  155. if (name == 'IMPORT' || name.indexOf('RETURN') > -1) {
  156. bRtn = true;
  157. }
  158. return bRtn;
  159. },
  160. setJson: function (val, name) {
  161. var o = $.parseJSON(val);
  162. return getJsonVal(o, name) || '';
  163. },
  164. setBtn: function (val, btntype, path) {
  165. var o = $.parseJSON(val),
  166. oBtn = $('<input>', {
  167. type: 'button', class: 'btn btn-success signaturefile', value: '取得簽收證明', 'data-i18n': 'common.ObtainProofofDelivery', 'data-path': path, id: 'btn-' + btntype
  168. });
  169. if (!o.complete || !path) {
  170. oBtn.attr('disabled', true);
  171. }
  172. return oBtn[0].outerHTML;
  173. },
  174. setInfo: function (val, type) {
  175. var o = $.parseJSON(val),
  176. saLi = fnReleaseObj(o),
  177. saInfoHtml = [];
  178. $.each(saLi, function (idx, li) {
  179. if (li.Checked) {
  180. saInfoHtml.push('<tr><td>' + (li.Date || '').substr(0, 10) + '</td><td style="text-align:center" data-i18n="' + type + '.' + li.keyName + '"></td><td>' + (li.Remark || '') + '</td></tr>');
  181. }
  182. });
  183. return saInfoHtml.reverse().join('');
  184. },
  185. setFlow: function (val, type) {
  186. var o = $.parseJSON(val),
  187. saLi = fnReleaseObj(o),
  188. sFlowHtml = $('<div>'),
  189. bactive = false;
  190. $.each(saLi, function (idx, li) {
  191. if (li.Date !== undefined) {
  192. var sChecked = li.Checked,
  193. oLi = $('<li>', { class: 'step step-inactive', html: '<a href="#" data-i18n="' + type + '.' + li.keyName + '"></a>' }),
  194. oDiv = $('<div hidden>');
  195. if (sChecked) {
  196. oLi.addClass('step-complete');
  197. oDiv.addClass('div-complete');
  198. }
  199. else {
  200. oLi.addClass('step-incomplete');
  201. oDiv.addClass('div-incomplete');
  202. }
  203. if (!sChecked && !bactive) {
  204. sFlowHtml.find('li:last').removeClass('step-inactive').addClass('step-active');
  205. bactive = true;
  206. }
  207. sFlowHtml.append([oLi, oDiv]);
  208. }
  209. });
  210. sFlowHtml.find('div').last().remove();
  211. if (o.complete) {
  212. sFlowHtml.find('li').last().addClass('step-all-complete');
  213. }
  214. return sFlowHtml.html();
  215. },
  216. setBillLadNOSub: function (val) {
  217. return val.replaceAll('/', '<br>').replaceAll(',', '<br>').replaceAll(',', '<br>').replaceAll(';', '<br>').replaceAll(';', '<br>').replace('|', '<br>').replace('|', '<br>').replace('|', '<br>').replace('|', '<br>');
  218. },
  219. setSupplierName: function (cnname, enname) {
  220. var sName = cnname;
  221. if (!cnname) {
  222. sName = enname || '';
  223. }
  224. return sName;
  225. }
  226. };
  227. $.views.helpers(myHelpers);
  228. sHtmlInfo = $('#temp_info').render(oCurData);
  229. $('.shadow').hide();
  230. $('.panel-info').html(sHtmlInfo);
  231. $('hr').last().remove();
  232. if (oCurData.Flows.length == 1) {
  233. $('.tab-pane').css({ 'border-bottom': '0' });
  234. }
  235. if ((sType == '01' || sType == '03' || sType == '04') && oCurData.Flows.length == 1) {
  236. $('.cusbuttons :input[id=btn-IMPORT]').remove().clone(true).prependTo('.toolbar');
  237. }
  238. else if (sType == '01' && oCurData.Flows.length > 1) {
  239. $('.cusbuttons :input[id^=btn-RETURN]:last').remove().clone(true).prependTo('.toolbar');
  240. }
  241. $(".sidebar-1,.btnquery-next").click(function (e) {
  242. $('.shadow').show();
  243. $('.toolbar').hide();
  244. $('#queryNum,#randomNum').val('');
  245. $('.panel-info').html('');
  246. });
  247. $('.toolbar').show();
  248. $(".btnprint").click(function (e) {
  249. //window.print();
  250. $(".panel-info").jqprint({ operaSupport: false });
  251. });
  252. if ($(".signaturefile").length > 0) {
  253. $('.signaturefile').click(function (e) {
  254. var sPath = $(this).attr('data-path'),
  255. sFileName = $('#queryNum').val() + '_' + this.id.replace('btn-', '');
  256. showWaiting(i18next.t('common.Downloading'));
  257. DownLoadFile(sPath, sFileName);
  258. });
  259. }
  260. transLang();
  261. fnSetName();
  262. }
  263. else {
  264. $('.errormsg').text(i18next.t('common.NoDataFound')).show();
  265. }
  266. fnDrawPic();
  267. },
  268. /*
  269. * 初始化 function
  270. * @param
  271. * @return
  272. * 起始作者John
  273. * 起始日期2016/05/21
  274. * 最新修改人John
  275. * 最新修日期2016/11/03
  276. */
  277. init = function () {
  278. if (!g_db.SupportLocalStorage()) {
  279. if (sLang == 'en') {
  280. alert('The current browser does not support local storage. Please turn off private browsing settings');
  281. }
  282. else if (sLang == 'zh') {
  283. alert('当前浏览器不支持本地储存,请关闭无痕浏览模式');
  284. }
  285. else {
  286. alert('當前瀏覽器不支持本地儲存,請關閉私密瀏覽設定');
  287. }
  288. $('body').html('');
  289. return;
  290. }
  291. if (sRefNumber) {
  292. $('#queryNum').val(sRefNumber);
  293. $('.form-group-material').eq(0).addClass('has-value');
  294. }
  295. materialForm();
  296. $.ajax({
  297. type: 'get',
  298. jsonpCallback: "ipCallback",//callback的function名称
  299. url: 'https://www.taobao.com/help/getip.php',
  300. dataType: 'jsonp',
  301. success: function (res) {
  302. sIp = res.ip;
  303. g_api.ConnectLite(Service.apiappcom, 'GetIPInfo', {
  304. ip: sIp
  305. }, function (res1) {
  306. if (res1.RESULT) {
  307. var oIpInfo = JSON.parse(res1.DATA.rel);
  308. if (oIpInfo.code == 0) {
  309. sIPInfo = Tostr(oIpInfo.data);
  310. }
  311. }
  312. });
  313. }
  314. });
  315. $('[data-value=zh-TW]').parent().hide();
  316. $("#gotop").gotop({ content: 980, bottom: 60, margin: "none", position: "right", scrollTop: 100, duration: 700 });
  317. fnDrawPic();
  318. $("#changeImg").click(function (e) {
  319. e.preventDefault();
  320. fnDrawPic();
  321. });
  322. $(".btnquery").click(function () {
  323. $('.errormsg').text('').hide();
  324. var sQueryNum = $('#queryNum').val(),
  325. sRandomNum = $('#randomNum').val(),
  326. sMsg = '';
  327. if (!sQueryNum) {
  328. sMsg = i18next.t('message.QueryNO_required'); //請輸入查詢號碼;
  329. }
  330. else if (!sRandomNum) {
  331. sMsg = i18next.t('message.RandomNO_required'); //請輸入驗證碼;
  332. }
  333. else if (sRandomCode !== sRandomNum) {
  334. sMsg = i18next.t('message.RandomNO_Incorrect'); // 驗證碼不正確;
  335. }
  336. if (sMsg) {
  337. $('.errormsg').text(sMsg).show();
  338. return false;
  339. }
  340. var sWaitting = i18next.t('message.Waitting'); // 查詢中...;
  341. fnGetData(sQueryNum)
  342. });
  343. $(document).on('keydown', function (e) {
  344. if (e.keyCode === 13) {
  345. $(".btnquery").click();
  346. }
  347. });
  348. setLang(sLang);
  349. };
  350. init();
  351. });