var sRefNumber = getUrlParam('RefNumber'); $(function () { 'use strict'; var sRandomCode = '', sIp = '', sIPInfo = '', oCurData = {}, sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW', materialForm = function () { return $('.material-field').focus(function () { $('.errormsg').text('').hide(); return $(this).closest('.form-group-material').addClass('focused has-value'); }).focusout(function () { $('.errormsg').text('').hide(); return $(this).closest('.form-group-material').removeClass('focused'); }).blur(function () { if (!this.value) { $(this).closest('.form-group-material').removeClass('has-value'); } return $(this).closest('.form-group-material').removeClass('focused'); }); }, /* * 目的:生成一个随机数 * @param: min(int)最小值 * @param: max(int)最大值 * @return: 無 * 作者:John *********************************************/ randomNum = function (min, max) { return Math.floor(Math.random() * (max - min) + min); }, /* * 目的:生成一个随机色 * @param: min(int)最小值 * @param: max(int)最大值 * @return: 無 * 作者:John *********************************************/ randomColor = function (min, max) { var r = randomNum(min, max); var g = randomNum(min, max); var b = randomNum(min, max); return "rgb(" + r + "," + g + "," + b + ")"; }, /* * 目的:绘制验证码图片 * @param: min(int)最小值 * @param: max(int)最大值 * @return: 無 * 作者:John *********************************************/ fnDrawPic = function () { var canvas = document.getElementById("canvas"); var width = canvas.width; var height = canvas.height; var ctx = canvas.getContext('2d'); ctx.textBaseline = 'bottom'; /**绘制背景色**/ ctx.fillStyle = randomColor(180, 240); //颜色若太深可能导致看不清 ctx.fillRect(0, 0, width, height); /**绘制文字**/ //var str = 'ABCEFGHJKLMNPQRSTWXY123456789'; var str = '123456789'; sRandomCode = ''; for (var i = 0; i < 4; i++) { var txt = str[randomNum(0, str.length)]; sRandomCode += txt; ctx.fillStyle = randomColor(50, 60); //随机生成字体颜色 ctx.font = randomNum(35, 40) + 'px SimHei'; //随机生成字体大小 var x = 10 + i * 25; var y = randomNum(40, 40); var deg = randomNum(-45, 45); //修改坐标原点和旋转角度 ctx.translate(x, y); ctx.rotate(deg * Math.PI / 270); ctx.fillText(txt, 0, 0); //恢复坐标原点和旋转角度 ctx.rotate(-deg * Math.PI / 270); ctx.translate(-x, -y); } /**绘制干扰线**/ //for (var i = 0; i < 8; i++) { // ctx.strokeStyle = randomColor(40, 180); // ctx.beginPath(); // ctx.moveTo(randomNum(0, width), randomNum(0, height)); // ctx.lineTo(randomNum(0, width), randomNum(0, height)); // ctx.stroke(); //} /**绘制干扰点**/ for (var i = 0; i < 100; i++) { ctx.fillStyle = randomColor(0, 255); ctx.beginPath(); ctx.arc(randomNum(0, width), randomNum(0, height), 1, 0, 2 * Math.PI); ctx.fill(); } }, /* * 目的:设置名称 * @return: 無 * 作者:John *********************************************/ fnSetName = function () { var oSupplierName = $('#SupplierName'), sTranName = !oCurData.SupplierName ? oCurData.SupplierEName : oCurData.SupplierName; if (sLang == 'zh-TW') { oSupplierName.text(sTranName); } else if (sLang == 'zh') { oSupplierName.text(sTranName); } }, /** * 獲取資料 * @param: sQueryNum{String}查詢號碼 * @return 無 * 起始作者:John * 起始日期:2017/01/05 * 最新修改人:John * 最新修日期:2017/01/05 */ fnGetData = function (sQueryNum) { g_api.ConnectLite(Service.apite, 'GetTrackingProgress', { QueryNum: sQueryNum, IP: sIp, IPInfo: sIPInfo }, function (res) { if (res.RESULT) { fnReleseData(res.DATA.rel, sQueryNum); } }, null, null, i18next.t('message.Querying')); }, fnReleseData = function (data, num) { if (JSON.stringify(data) !== "{}") { oCurData = data; var sType = num.substr(2, 2), sHtmlInfo = '', fnReleaseObj = function (o) { var saLi = []; for (var key in o) { if (typeof o[key] === 'object') { var nobj = o[key]; nobj.keyName = key; saLi.push(nobj); } } saLi = saLi.sort(function (a, b) { return new Date(a.Date === '' ? new Date() : a.Date) > new Date(b.Date === '' ? new Date() : b.Date); }); return saLi; }, myHelpers = { checkFlowName: function (name) { var bRtn = false; if (name == 'IMPORT' || name.indexOf('RETURN') > -1) { bRtn = true; } return bRtn; }, setJson: function (val, name) { var o = $.parseJSON(val); return getJsonVal(o, name) || ''; }, setBtn: function (val, btntype, path) { var o = $.parseJSON(val), oBtn = $('', { type: 'button', class: 'btn btn-success signaturefile', value: '取得簽收證明', 'data-i18n': 'common.ObtainProofofDelivery', 'data-path': path, id: 'btn-' + btntype }); if (!o.complete || !path) { oBtn.attr('disabled', true); } return oBtn[0].outerHTML; }, setInfo: function (val, type) { var o = $.parseJSON(val), saLi = fnReleaseObj(o), saInfoHtml = []; $.each(saLi, function (idx, li) { if (li.Checked) { saInfoHtml.push('