(function (win, doc, UXUN, undefined) { "use strict"; UXUN.phone = function (phone) { var reg = new RegExp("^[0-9]*$"); return reg.test(phone) && (phone.length === 11); }; UXUN._id = function (id) { if (id) { return document.getElementById(id); } return null; }; UXUN.toast = function (message, callback) { var toast = $("#public_toast_alert"); if (toast.length === 0) { toast = $('
' + (message || "") + '
').show(); $("body").append(toast); } else { toast.html(message || ""); } setTimeout(function () { toast.remove(); if (typeof callback === "function") { callback(); } }, 3000); }; UXUN.hideLoading = function () { var jizai = doc.getElementById('_loading_jizai'); if (jizai) { jizai.style.display = "none"; } }; UXUN.showLoading = function (duration) { var jizai = doc.getElementById('_loading_jizai'); if (jizai && !!jizai.innerHTML) { jizai.style.display = 'block'; } else { var rootElement = doc.body; var newElement = doc.createElement("div"); newElement.id = "_loading_jizai"; newElement.innerHTML = '
'; rootElement.appendChild(newElement); } if (duration && duration !== 0) { setTimeout(function () { UXUN.hideLoading(); }, duration); } }; UXUN.isError = function (data) { if (!UXUN.isNotNull(data)) { return "响应报文为空"; } if (data && data.retcode !== '0000') { return data.retshow; } return false; }; UXUN.getBankCode = function () { return localStorage.getItem("local_bankcode") || ""; }; UXUN.isNotNull = function (obj) { if (!obj || "null" === obj || $.isEmptyObject(obj) || "{}" === obj || "undefined" === obj || "[object Object]" === obj || [] === obj || "[]" === obj) { return false; } return true; }; UXUN.isEmptyObject = function (obj) { if (UXUN.isNotNull(obj)) { for (var key in obj) { return false; } } return true; }; //清理用户信息 UXUN.clearUser = function () { _Storage.removeItem(UXUN.local_member); pageHeadObject.loginOut(); }; UXUN.updateUser = function (user) { if (user && {} !== user) { _Storage.setItem(UXUN.local_member, user); } }; UXUN.getUser = function () { return _Storage.getItem(UXUN.local_member); }; //退出登录 UXUN.loginOut = function () { var href = getApplication('loginURL'); _Storage.clear(); pageHeadObject.loginOut(); if (location.href.indexOf(href) === -1) { _PluginPage.open(UXUN.getPublicPath() + href); } }; //获取项目的根目录 UXUN.getPublicPath = function () { var localhostPaht = window.parent.location.href.substring(0, window.parent.location.href.indexOf("/view")); var bankcode = localStorage.getItem("local_bankcode") || 'public'; return localhostPaht.replace(/public/, bankcode) + "/"; }; //格式化 都放在这里 UXUN.format = { money: function (str, n) { n = n === undefined ? 2 : n; str = parseFloat((Number(str || 0) + "").replace(/[^\d\.-]/g, "")).toFixed(n) + ""; var l = str.split(".")[0].split("").reverse(); var r = str.split(".")[1]; var isMinus = l[l.length - 1] === '-'; //是否为负数 var res = ''; if (isMinus) { l.pop(); } for (var i = 0; i < l.length; i++) { res += l[i] + ((i + 1) % 3 === 0 && (i + 1) != l.length ? "," : ""); } res = res.split("").reverse().join(""); //小数 if (isMinus) { res = '-' + res; } if (r) { var zero = ""; for (var j = 0; j < n; j++) { zero += "0"; } if (r === zero) { res = res; } else { res = res + "." + r; } } if (-1 === n) { res.indexOf(0); } return res; }, moneyPC: function (str) { if (!str) str = 0; str = parseFloat(str).toFixed(2); return parseFloat(str); }, moneyAndPoint: function (price, point) { var res = ''; var hasPrice = parseFloat(price || 0) !== 0; var hasPoint = parseFloat(point || 0) !== 0; price = UXUN.format.money(price || 0); point = UXUN.format.money(point || 0, 0); if (hasPrice && hasPoint) { res = '¥ ' + price + ' + ' + point + ' 积分'; } else if (hasPrice && !hasPoint) { res = '¥ ' + price; } else if (!hasPrice && hasPoint) { res = point + ' 积分'; } else { res = '¥ 0.00'; } return res; }, //20170720163955 转 2017-07-20 date: function (dateStr, split) { split = split || '-'; var r = (dateStr + '').substr(0, 8).split(''); r.splice(4, 0, split); r.splice(7, 0, split); return r.join(''); }, //20170720163955 转 2017-07-20 16:39:55 dateTime: function (dateStr, split) { split = split || '-'; var r = (dateStr + '').split(''); r.splice(4, 0, split); r.splice(7, 0, split); r.splice(10, 0, ' '); r.splice(13, 0, ':'); r.splice(16, 0, ':'); return r.join(''); }, }; //获取url参数 UXUN.getUrlParam = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = win.location.search.substr(1).match(reg); if (r === null) { return ''; } // return unescape(r[2]); return decodeURIComponent(r[2]); }; // 会员模块表单提示框 UXUN.formTip = function () { // 短信验证码 $("body").on("focus", "#js_msgCode", function () { $("#js_msgCodeTip ").hide(); }); $("body").on("blur", " #js_msgCode", function () { var code = $(this).val(); if (code.length === 0) { $("#js_msgCodeTip").show().html('
' + getApplication("accountReviseBindMobile").msgCode.isNullTip + '
'); return false; } else if (code.length !== 6) { $("#js_msgCodeTip").show().html('
' + getApplication("accountReviseBindMobile").msgCode.isNull + '
'); return false; } else { $("#js_msgCodeTip").hide(); return true; } }); // 图形验证码 $("body").on("focus", "#regCode_mail", function () { $("#regCode_mailTip").hide(); }); $("body").on("blur", " #regCode_mail", function () { var code = $(this).val(); if (code.length === 0) { $("#regCode_mailTip").show().html('
' + getApplication("register").regCode_mailTip.isNull + '
'); return false; } else if (code.length !== 4) { $("#regCode_mailTip").show().html('
' + getApplication("register").regCode_mailTip.no_norm + '
'); return false; } else { $("#regCode_mailTip").hide(); } }); // 身份证 $("body").on("focus", "#ID-number", function () { $("#ID-numberTip").hide(); $("#ID-numberT .onError").hide(); }); $("body").on("blur", "#ID-number", function () { var code = $(this).val(); if (code.length === 0) { $("#ID-numberTip").show().html("
" + getApplication("realName").idNumbe.isNull + "
"); $("#ID-numberT .onError").show().html(getApplication("realName").idNumbe.isNull); return false; } else if (code.length !== 18) { $("#ID-numberTip").show().html("
" + getApplication("realName").idNumbe.onError + "
"); $("#ID-numberT .onError").show().html(getApplication("realName").idNumbe.onError); return false; } else { $("#ID-numberTip").hide(); $("#ID-numberT .onError").hide(); } }); // 姓名 $("body").on("focus", "#username", function () { $("#usernameTip").hide(); }); $("body").on("blur", " #username", function () { // 验证姓名 var code = $(this).val(); var nameReg = /^([a-zA-Z0-9\u4e00-\u9fa5\·]{2,25})$/; if (code.length === 0) { $("#usernameTip").show().html('
' + getApplication("accountReviseBindMobile").name.isNull + '
'); return; } else if (!nameReg.test(code)) { $("#usernameTip").show().html('
' + getApplication("accountReviseBindMobile").name.isErroTip + '
'); return; } else { $("#usernameTip").hide(); } }); // 银行卡 $("body").on("focus", "#bank-card", function () { $("#bank-cardTip").hide(); }); $("body").on("blur", " #bank-card", function () { // 验证手机号 var code = $(this).val(); if (code.length === 0) { $("#bank-cardTip").show().html('
' + getApplication("accountReviseBindMobile").bankCard.isNull + '
'); return false; } else if (code.length < 14 || code.length > 20) { $("#bank-cardTip").show().html('
' + getApplication("accountReviseBindMobile").bankCard.isErro + '
'); return false; } else { $("#bank-cardTip").hide(); } }); }; // 收货地址提示样式 UXUN.phoneVal = function () { // 手机 $("body ").on("focus", "#phone", function () { $("#phoneT .onError").css("display", "none"); }); $("body ").on("blur", "#phone", function () { // 验证手机号 var phoneNo = $.trim($(this).val()); var reg = /^[1-9]\d{10}$/; if (phoneNo.length === 0) { $("#phoneT .onError").show().html(getApplication("register").addAddress.isphoneNull); return; } if (phoneNo.indexOf("1") !== 0) { $("#phoneT .onError").show().html(getApplication("register").addAddress.phoneError); return; } else if (phoneNo.length !== 11) { $("#phoneT .onError").show().html(getApplication("register").addAddress.phoneError); return; } else if (!reg.test(phoneNo)) { $("#phoneT .onError").show().html(getApplication("register").addAddress.phoneError); return; } else { $("#phoneT .onError").css("display", "none"); } }); // 姓名 $("body").on("focus", "#username", function () { $("#usernameTip").hide(); }); $("body").on("blur", " #username", function () { // 验证姓名 var code = $(this).val(); var nameReg = /^([a-zA-Z0-9\u4e00-\u9fa5\·]{2,25})$/; if (code.length === 0) { $("#usernameTip").show().html('
' + getApplication("register").addAddress.nameIsNull + '
'); return; } else if (!nameReg.test(code)) { $("#usernameTip").show().html('
' + getApplication("register").addAddress.nameonError + '
'); return; } else { $("#usernameTip").hide(); } }); // 地址 $("body").on("focus", "#address", function () { $("#addressTip").hide(); }); $("body").on("blur", " #address", function () { // 验证姓名 var code = $(this).val(); if (code.length === 0) { $("#addressTip").show().html('
' + getApplication("register").addAddress.addAddressIsNull + '
'); return; } else { $("#addressTip").hide(); } }); $("body ").on("click", "#store-selector", function () { $("#store-selectorT .onError").hide(); }); }; // 回车enter键执行自己方法 UXUN.keyCode = function (callback, ele) { $('body').on("keydown", ele, function (ev) { var oEv = ev || window.event; if (oEv.keyCode == 13) { callback(); } }); }; // 表单可用 UXUN.formDisabled=function(ele){ if("oninput" in document){ ele.on("input", "input", function () { var inputs =ele.find("input"), _disabled; for (var i = 0; i < inputs.length; i++) { if (inputs.eq(i).val().trim() === "") { _disabled = true; break; } else { _disabled = false; } } if (_disabled) { $(".ubtn").attr("disabled", _disabled); } else { $(".ubtn").removeAttr("disabled"); } $('body').on("keyup", "input", function (ev) { var that=$(this); var oEv = ev || window.event; if (oEv.keyCode === 8) { if(that.val().length<1){ $(".ubtn").attr("disabled",true); } } return false; }); }); }else{ ele.on("textchange", "input", function () { var inputs =ele.find("input"), _disabled; for (var i = 0; i < inputs.length; i++) { if (inputs.eq(i).val().trim() === "") { _disabled = true; break; } else { _disabled = false; } } if (_disabled) { $(".ubtn").attr("disabled", _disabled); } else { $(".ubtn").removeAttr("disabled"); } $('body').on("keyup", "input", function (ev) { var that=$(this); var oEv = ev || window.event; if (oEv.keyCode === 8) { if(that.val().length<1){ $(".ubtn").attr("disabled",true); } } return false; }); }); } }; //将对象转化为url参数 UXUN.convertUrlParam = function (param, key) { var paramStr = ""; if (param instanceof String || param instanceof Number || param instanceof Boolean || typeof param === 'string' || typeof param === 'number' || typeof param === 'boolean') { paramStr += "&" + key + "=" + encodeURIComponent(param); } else { $.each(param, function (i) { var k = (key === null || key === undefined) ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i); paramStr += '&' + UXUN.convertUrlParam(this, k); }); } return paramStr.substr(1); }; //转化为数组 UXUN.convertArray = function (obj) { return obj === null || obj === undefined ? [] : Array.isArray(obj) ? obj : [obj]; }; // 密码控件提示 UXUN.pwdTip = function () { $("body ").on("focus", "#_ocx_password", function () { $(this).css("border", "1px solid #b0cdfb"); $('#ocx_pwdT .onError').hide(); $('#ocx_pwdT .onFocus').show().html(getApplication("register").pwd.no_norm); }); $("body ").on("blur", "#_ocx_password", function () { $(this).css("border", "1px solid #ddd"); $('#ocx_pwdT .onFocus').hide(); if (pgeditor.pwdLength() === "0" || pgeditor.pwdLength() === 0) { $('#ocx_pwdT .onError').show().html(getApplication("register").pwd.isNull); return; } else if (pgeditor.pwdValid() === "1" || pgeditor.pwdValid() === 1) { if (pgeditor.pwdLength() < 6) { $('#ocx_pwdT .onError').show().html(getApplication("register").pwd.norm); return; } else { $('#ocx_pwdT .onError').show().html(getApplication("register").pwd.isnumber); } return; } else { $('#ocx_pwdT .onError').hide(); } }); $("body ").on("focus", "#_ocx_password1", function () { $(this).css("border", "1px solid #b0cdfb"); $('#ocx_pwdAngT .onError').hide(); $('#ocx_pwdAngT .onFocus').show().html(getApplication("register").pwd.no_norm); }); $("body ").on("blur", "#_ocx_password1", function () { $(this).css("border", "1px solid #ddd"); $('#ocx_pwdAngT .onFocus').hide(); if (pgeditor1.pwdLength() === "0" || pgeditor1.pwdLength() === 0) { $('#ocx_pwdAngT .onError').show().html(getApplication("register").pwd.isNull1); return; } else if (pgeditor1.pwdValid() === "1" || pgeditor1.pwdValid() === 1) { if (pgeditor1.pwdLength() < 6) { $('#ocx_pwdAngT .onError').show().html(getApplication("register").pwd.norm); return; } else { $('#ocx_pwdAngT .onError').show().html(getApplication("register").pwd.isnumber); } return; } else if (pgeditor1.pwdHash() !== pgeditor.pwdHash()) { $('#ocx_pwdAngT .onError').show().html(getApplication("register").pwd.onError); } else { $('#ocx_pwdAngT .onError').hide(); } }); }; //手机显示中间加掩码157****9999 UXUN.formatPhone = function (phoneNo) { return (phoneNo + '').replace(/^(\S{3})(\S+)(\S{4})$/, function ($0, $1, $2, $3) { return $1 + $2.replace(/\S/g, '*') + $3; }); }; //验证手机号码 toast是用来判断是否弹窗,不传就弹 UXUN.checkPhoneNo = function (phoneNo, bool) { var reg = /^[1-9]\d{10}$/; if (!UXUN.isNotNull(phoneNo)) { if (!bool) UXUN.toast("手机号码不能为空"); return true; } if (phoneNo.indexOf("1") !== 0) { if (!bool) UXUN.toast("手机号码格式有误"); return true; } if (phoneNo.length !== 11) { if (!bool) UXUN.toast("手机号码只能11位"); return true; } if (!reg.test(phoneNo)) { if (!bool) UXUN.toast("手机号码格式有误"); return true; } return false; }; //验证银行卡号 UXUN.checkBankCard = function (bankCard) { var bankReg = /^([1-9]{1})(\d{15,19})$/; var re = bankCard.replace(/\s/g, ""); if (!bankReg.test(re)) { return false; } else { return true; } }; //验证短信验证码 UXUN.checkCode = function (code, toast) { var reg = /^\d{6}$/; if (!toast) { if (!UXUN.isNotNull(code)) { UXUN.toast("短信验证码不能为空"); return true; } if (6 !== code.length) { UXUN.toast("短信验证码错误"); return true; } if (!reg.test(code)) { UXUN.toast("短信验证码为6位随机数字"); return true; } return false; } else { if (!UXUN.isNotNull(code)) { return true; } if (6 !== code.length) { return true; } if (!reg.test(code)) { return true; } return false; } }; //验证姓名 UXUN.checkName = function (name) { var nameReg = /^([a-zA-Z0-9\u4e00-\u9fa5\·]{2,25})$/; if (!nameReg.test(name)) { return false; } else { return true; } }; //验证身份证号 UXUN.checkIdCard = function (idCard) { var idcardReg = /^\d{17}[\dxX]$/; if (!idcardReg.test(idCard)) { return false; } else { return true; } }; //图片路径的拼接 UXUN.imgPathJoin = function (src, size) { if (!src) return; var pointIndex = src.lastIndexOf("."), type; size = size === "" ? "200x200" : size; if (pointIndex == -1) { type = ".jpg"; } else { type = src.substring(pointIndex); } return getApplication('IMGPATH') + src + "_" + size + "c" + type; }; //确认框 UXUN.confirm = function (message, title, btnArray, callback) { var init = function () { if (typeof message === 'undefined') { return; } if (typeof title === 'function') { callback = title; type = btnArray; title = '提示'; btnArray = ['确认', '取消']; } else if (typeof btnArray === 'function') { type = callback; callback = btnArray; btnArray = ['确认', '取消']; } createPopup(); }; var createPopup = function () { var html = '
' + '
' + '
' + '

' + title + '

' + '
' + '

' + message + '

' + '

' + '' + btnArray[0] + '' + '' + btnArray[1] + '' + '

' + '
' + '
' + '
' + '
'; $("body").append(html); }; init(); var btns = $(".popBox .ubtn"); var handleEvent = function (e) { var self = e.target, value = self.innerHTML; var result = callback && callback({ value: value }); if (result === false) { return; } $(self).parents(".popBox").remove(); }; $('body .popBox').on('click', '.ubtn,.close', handleEvent); }; //url转json UXUN.urlToJson = function (url) { var hash; var myJson = {}; if(!url){ return myJson; } if (url.indexOf('?') === -1) { url = "?"+url; } var hashes = url.slice(url.indexOf('?') + 1).split('&'); for (var i = 0; hashes.length>0&&i