function fillreturnmsg(o, t, msg) { var tip = $("span.formcolumn-item-tipstxt", $(o).parent()); if ($("span.formcolumn-item-errtipstxt", $(o).parent()).length > 0) { tip = $("span.formcolumn-item-errtipstxt", $(o).parent()); } tip.html(msg); if (t == 1) { $(o).removeclass("needfill"); tip.css("color", "green"); } else if (t == 0) { $(o).addclass("needfill"); tip.css("color", "red"); } else if (t == 2) { $(o).removeclass("needfill"); tip.css("color", "#999999"); } } var initexrequiredspanfunc = {}; var formverifyfunc = { email: { reg: /^([a-za-z0-9_\.\-])+\@(([a-za-z0-9\-])+\.)+([a-za-z0-9]{2,4})+$/ } }; function initformverify(cfg) { if (typeof (initextcountry) == "function") { initextcountry(); } if (initexrequiredspanfunc[cfg.el] != null) { initexrequiredspanfunc[cfg.el]($("input[exrequired='true'],select[exrequired='true'],span[addresstype][exrequired='true'],textarea[exrequired='true']", cfg.el)); } else { $("input[exrequired='true'],textarea[exrequired='true']", cfg.el).after(" *"); } $("input[exrequired='true'],textarea[exrequired='true']", cfg.el).each(function () { if ($(this).attr("onblur") == undefined) { $(this).on("blur", function () { var v = $(this).val(); if (v != "") { var suc = true; if ($(this).attr("validtype") != undefined && $(this).attr("validtype") != "") { var vtype = $(this).attr("validtype"); if (formverifyfunc[vtype] != null) { var reg = formverifyfunc[vtype].reg; if (!reg.test(v)) { suc = false; $(this).val(""); fillreturnmsg(this, 0, " "); } } else { console.log("verifytype=" + vtype + " not exist"); } } if (suc) { fillreturnmsg(this, 1, " "); } } else { if ($(this).attr("title")) { fillreturnmsg(this, 0, getlangtxt(rclng.itemrequired, [{ title: "title", text: $(this).attr("title") }])); } else { fillreturnmsg(this, 0, ""); } } }); } }); $(".formcom-verifybox", cfg.el).each(function () { var _box = this; var btn = $(".formcom-verifycode-btn", this); btn.click(function () { var o = this; var relel = $(this).attr("relinput"); var verifynum = $("#" + relel).val(); var verifytype = $(this).attr("verifytype"); if (verifytype == "email") { if (!web960.verify.email(verifynum)) { alert(rclng.erroremailformat); $("#" + relel).focus(); return; } } else { if (!web960.verify.mobile(verifynum)) { alert(rclng.errorphonenum); $("#" + relel).focus(); return; } } $(o).prop("disabled", true); var downcountsecond = 120; var downcount = function () { if (downcountsecond == 0 || ($(o).attr("stopdowncount") != null && $(o).attr("stopdowncount") == "1")) { $(o).prop("disabled", false).html(rclng.sendsmsverify); $(o).removeattr("stopdowncount"); } else { $(o).prop("disabled", true).html(downcountsecond); settimeout(function () { downcountsecond--; downcount(); }, 1000); } }; var html = '
\
\
'; if ($(".smsverifydialog", _box).length > 0) { $(".smsverifydialog", _box).remove(); } $(".verifycodeviewbox", _box).html(html); web960initgeetest({ el: $(".smsverifycaptchdiv", _box), width: "100%", success: function (capresult) { var data = { geetest_challenge: capresult.geetest_challenge, geetest_validate: capresult.geetest_validate, geetest_seccode: capresult.geetest_seccode, phonenum: verifynum }; var url = "/index.aspx?a=sendmobileverifycode_common"; if (verifytype == "email") { url = "/index.aspx?a=sendemailverifycode_common"; data = { geetest_challenge: capresult.geetest_challenge, geetest_validate: capresult.geetest_validate, geetest_seccode: capresult.geetest_seccode, email: verifynum }; } $.post(url, data, function (ret) { if (ret.result == "1") { $(".formcom-verifycode", _box).attr("verifyid", ret.verifyid); $(".geetest_success_radar_tip_content").html("验证码发送成功,请注意查收"); downcount(); } else { $(".smsverifycaptchdiv", _box).css({ "color": "red", "height": "44px", "line-height": "44px", "border": "1px solid #ec8888", "background-color": "#ffeaea", "text-indent": "20px", "border-radius": "3px" }).html("无法发送:" + ret.message); $(".formcom-verifycode", _box).attr("verifyid", ""); $(o).prop("disabled", false); } }, "json") } }); }); }); } function initformverify_v2(cfg) { if (typeof (initextcountry) == "function") { initextcountry(); } // $("input[exrequired='true'],textarea[exrequired='true']", cfg.el).after(" *"); $("input[exrequired='true'],textarea[exrequired='true']", cfg.el).each(function () { if ($(this).attr("onblur") == undefined) { $(this).on("blur", function () { $(".help-block", $(this).parents(".form-group")).remove(); var v = $(this).val(); if (v != "") { $(this).parents(".form-group").removeclass("has-error"); } else { $(this).parents(".form-group").addclass("has-error"); if ($(this).attr("title") && $(this).attr("show-help") == "true") { $(this).parents(".form-group").append('' + getlangtxt(rclng.itemrequired, [{ title: "title", text: $(this).attr("title") }]) + ''); } } }); } }); } function ajaxreturn(ret, callback) { var rc = ret.value; if (rc) { callback(); } else { alert(ret.error.message); } } function opendialog(cfg) { if ($.fn.dialog != undefined) { $(cfg.el).dialog({ title: cfg.title, autoopen: true, modal: true, width: cfg.width, height: cfg.height, resizable: false, close: function () { $("body").css("overflow", "auto"); nowopendialogel = ''; }, open: function () { $("body").css("overflow", "hidden"); if (cfg.opencallback != undefined) { cfg.opencallback(); } } }); } else { try { var modalel = cfg.el + "_modal"; var modalelstr = modalel.replace("#", "").replace(".", ""); if ($(modalel).length == 0) { var html = ''; $("body").append(html); $(cfg.el).show(); $(".modal-body", modalel).append($(cfg.el)); $(modalel).modal({ backdrop: false, keyboard: false, show: true }); $(modalel).on('shown.bs.modal', function (e) { if (cfg.opencallback != undefined) { cfg.opencallback(); } }); $(modalel).on('hidden.bs.modal', function (e) { if (cfg.onclose != undefined) { cfg.onclose(); } }); } else { $(".modal-body", modalel).append($(cfg.el)); $(".modal-title", modalel).html(cfg.title); $(modalel).modal("show"); } } catch(e){ } } } function alert(msg, title, width) { if (title == undefined) { title = "" + rclng.sysalert; } if (width == undefined) { width = 400; } if ($("#alertdialog").length == 0) { $("body").append('
'); } opendialog({ el: "#alertdialog", width: width, title: title, buttons: [ { text: "" + rclng.sysok, icons: { primary: "ui-icon-heart" }, click: function () { $(this).dialog("close"); } } ], opencallback: function () { $("#alertmsgbox").html(msg); } }); } function closedialog(el) { if ($.fn.dialog != undefined) { $(el).dialog("close"); } else { try { var modalel = el + "_modal"; $(modalel).modal("hide"); } catch (e) { } } } function autocenterdialog(el) { if ($.fn.dialog != undefined) { $(el).dialog("option", "position", "center"); } } function initclosebtn(o) { if (o != undefined) { $("input[closebtn='true']", o).bind("click", function () { var el = $(this).attr("reel"); closedialog("#" + el); }) } else { $("input[closebtn='true']").bind("click", function () { var el = $(this).attr("reel"); closedialog("#" + el); }) } } function getextattrvalues(cfg) { var extv = {}; $("input[dataref='true'],textarea[dataref='true'],select[dataref='true'],span[addresstype],span[countrytype]", $(cfg.el)).each(function () { if (extv[$(this).attr("classname")] == undefined) { extv[$(this).attr("classname")] = {}; } if ($(this).hasclass("address_extipt")) { var vxv = ""; if ($(this).attr("areacode") != "") { vxv = $(this).attr("areacode") + "|" + $(this).attr("areatitle"); } extv[$(this).attr("classname")][$(this).attr("relkey")] = vxv; } else if ($(this).hasclass("country_extipt")) { var vxv = ""; if ($(this).attr("countrycode") != "") { vxv = $(this).attr("countrytitle") + "|" + $(this).attr("countrycode"); } extv[$(this).attr("classname")][$(this).attr("relkey")] = vxv; } else { extv[$(this).attr("classname")][$(this).attr("relkey")] = $(this).val(); } }); var r = {}; r.str = json2.stringify(extv); r.json = extv; return r; } function clearformdata(cfg, callback) { var nodename = ""; var isform = false; if ($(cfg.el).length > 0) { if ($(cfg.el).prop("tagname") != undefined) { nodename = $(cfg.el).prop("tagname"); } else if ($(cfg.el).prop("nodename") != undefined) { nodename = $(cfg.el).prop("nodename"); } if (nodename == "form") { isform = true; } } if (isform) { $(cfg.el)[0].reset(); } else { $("input[dataref='true'][type!='checkbox'],textarea[dataref='true'],input[data-ref][type!='checkbox'],textarea[data-ref]", $(cfg.el)).val(""); } $(".smsverifycaptchdiv", $(cfg.el)).html(""); $("input[verifyid]", $(cfg.el)).removeattr("verifyid"); $("button.formcom-verifycode-btn", $(cfg.el)).each(function () { if ($(this).attr("stopdowncount") == null) { $(this).attr("stopdowncount", "1"); } }); if (callback != undefined) { callback(); } } var verifyformdatafunc = {}; function verifyformdata(cfg, callback) { var checkallfield = false; if (cfg["checkallfield"] != undefined) { checkallfield = cfg["checkallfield"]; } var success = true; var postdata = {}; var needverifycode = false; var verifycodes = []; $("input[dataref='true'],textarea[dataref='true'],select[dataref='true'],input[data-ref],textarea[data-ref],span[addresstype],span[countrytype]", $(cfg.el)).each(function () { fillreturnmsg(this, 1, " "); var v = ""; if ($(this).attr("addresstype") != undefined && $(this).attr("areacode") != undefined) { v = $(this).attr("areacode"); } else if ($(this).attr("countrytype") != undefined && $(this).attr("countrycode") != undefined) { v = $(this).attr("countrycode"); } else { v = $(this).val(); } if ($(this).attr("exrequired") == "true" && v == "") { success = false; if (!checkallfield) { alert(getlangtxt(rclng.itemrequired, [{ title: "title", text: $(this).attr("title") }])); $(this).focus(); return false; } else { fillreturnmsg(this, 0, " "); } } var validtype = $(this).attr("validtype"); if (validtype != null && v != "") { if (validtype == "mobile") { if (!web960.verify.mobile(v)) { alert(rclng.errorphonenum); success = false; $(this).focus(); return false; } } else if (validtype == "email") { if (!web960.verify.email(v)) { alert(rclng.erroremailformat); success = false; $(this).focus(); return false; } } } if ($(this).hasclass("formcom-verifycode")) { var verifyid = $(this).attr("verifyid"); if (verifyid == null) { alert(getlangtxt(rclng.itemrequired, [{ title: "title", text: $(this).attr("title") }])); success = false; $(this).focus(); return false; } else { verifycodes.push({ verifyid: verifyid, code: v }); needverifycode = true; } } if ($(this).attr("data-ref") != undefined) { if ($(this).attr("type") != undefined) { if ($(this).attr("type") == "checkbox") { if ($(this).is(":checked")) { postdata[$(this).attr("data-ref")] = v; } else { postdata[$(this).attr("data-ref")] = ""; } } else if ($(this).attr("type") == "radio") { if ($(this).is(":checked")) { postdata[$(this).attr("data-ref")] = v; } } else { postdata[$(this).attr("data-ref")] = v; } } else { postdata[$(this).attr("data-ref")] = v; } } }); if (success) { if (needverifycode) { $.post("/index.aspx?a=verifycodes", { verifycodes: json.stringify(verifycodes) }, function (data) { if (data.result != "1") { alert(data.message); } else { var extdata = getextattrvalues(cfg); if (verifyformdatafunc[cfg.el] != null) { verifyformdatafunc[cfg.el](postdata, extdata, function (_postdata, _extdata) { callback(_postdata, _extdata.str, _extdata.json); }); } else { callback(postdata, extdata.str, extdata.json); } } }, "json"); } else { var extdata = getextattrvalues(cfg); if (verifyformdatafunc[cfg.el] != null) { verifyformdatafunc[cfg.el](postdata, extdata, function (_postdata, _extdata) { callback(_postdata, _extdata.str, _extdata.json); }); } else { callback(postdata, extdata.str, extdata.json); } } } else if (checkallfield) { alert(rclng.please_fix_below_errors); } } function jsontodict(data) { var dict = new ajax.web.dictionary("dictionary"); for (var jd in data) { dict.add(jd, data[jd]); } return dict; } function inituserloginstatus(cfg) { $.get("/index.aspx?a=checkuserlogin&mfrsh=" + math.random(), {}, function (data) { if (cfg.callback == undefined) { if (data.result == "1") { $(cfg.el).html(rclng.hello + '!' + data.username + ' ' + rclng.membercenter + ' ' + rclng.loginout + ' '); } else if (data.result == "-1") { $(cfg.el).html('' + rclng.login + ' ' + rclng.register + ' '); } if (cfg.ondone != undefined) { cfg.ondone(data); } } else { cfg.callback(data); } }, "json"); } function viewverifyimage(cfg) { $(cfg.el).html(''); } function refreashverifyimg(o) { var verifytype = $(o).attr("verifytype"); var veid = $(o).attr("vref"); $(o).attr("src", "/index.aspx?a=verifycode&verifytype=" + verifytype + "&r=" + math.random()); $(veid).val(""); } function verifycodecheck(o) { var v = $(o).val(); web960.web.index.verifyregcode(v, "userlogin", function (res) { ajaxreturn(res, function () { var rv = res.value; if (rv.status == "1") { } else { // rv.clientmsg } }); }); } function initdatamapping() { $.get("/index.aspx?a=getuserinfo", {}, function (data) { if (data.intresult == 1) { //logined; var comment = eval("(" + data.objresult.comment + ");"); $("input[data-mapping],textarea[data-mapping],select[data-mapping]").each(function () { var mapping = $.trim($(this).attr("data-mapping")); if (mapping != "") { try { var v = eval("(comment." + mapping + ");"); $(this).val(v); } catch (e) { } } }) } }, "json"); } function getguestextsettings(callback) { $.get("/index.aspx?a=g&getmethod=getsettings", {}, function (data) { if (data.intresult == 1) { var json = eval('(' + data.strresult + ')'); callback(json); } }, "json"); } function getextforms(formid, callback) { $.get("/index.aspx?a=g&getmethod=getextforms&formid=" + formid, {}, function (data) { if (data.intresult == 1) { callback(data.strresult); } }, "json"); } function guid(callback) { $.get("/index.aspx?a=guid&rnd=" + math.random(1), {}, function (data) { callback(data.guid); }, "json"); } function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.tostring(16); }); } function gotopage(o) { var v = $.trim($(o).val()); var patrn = /^[1-9]*[1-9][0-9]*$/; if (patrn.exec(v)) { var page = parseint(v); var url = $(o).attr("pageurl"); var pagecount = parseint($(o).attr("pagecount")); if (page <= 1) { url = url.replace("-{0}", "").replace("_{0}", ""); } else if (page > pagecount) { page = pagecount; url = url.replace("{0}", page); } else { url = url.replace("{0}", page); } location.href = url; } } function jumppropage(o) { var v = $.trim($(o).val()); var url = $("#wpagenavgotuipt").attr("pageurl"); var pagecount = parseint($(o).attr("pagecount")); url = url.replace("-{0}", "").replace("_{0}", "").replace("page={0}", "page=").replace("&psize", "&apsizeq").replace("?psize", "?apsizeq"); if (url.indexof("?") == -1) { location.href = url + "?psize=" + v; } else { location.href = url + "&psize=" + v; } } function getsimpmoneyunit(m) { switch (m) { case "cny": case "元": return "¥"; case "usd": return "$"; case "hkd": return "hk$"; case "eur": return "€"; } } function initbrowsehistorycookie(cookiename, cookievalue, savetime) { var str = cookiename + "=" + escape(cookievalue); var date = new date(); var ms = savetime * 60 * 1000; date.settime(date.gettime() + ms); str += ";expires=" + date.togmtstring(); document.cookie = str; } var nowextuploadrefid = ""; var bfcallback = null; function extupload(t, elid, callback) { bfcallback = callback; var dialoghtml = ''; if ($("#extuploaddialog").length == 0) { $("body").append(dialoghtml); extupload(t, elid); } else { $("#uploadnoticediv").html(""); nowextuploadrefid = elid; if (t == 1) { title = rclng.uploadimage; $("#extuploadform").attr("action", "/admin/filehandler.aspx?t=100&dir=image&id=0&n=0&cb=extuploadcallback"); } else if (t == 2) { title = rclng.uploadfile; $("#extuploadform").attr("action", "/admin/filehandler.aspx?t=110&dir=file&id=0&n=0&cb=extuploadcallback"); } opendialog({ el: "#extuploaddialog", width: 410, title: title }); } } function extuploadcallback(res) { if (res.error == "1") { alert(res.message); } else { var filename = res.filename; $("input[id$='" + nowextuploadrefid + "'").val(filename); if (bfcallback) { bfcallback(filename); } closedialog("#extuploaddialog"); } } function getshopchatcountfornowuser(cfg) { $.get("/index.aspx?a=ajax&plu=goodsmanage&ajaxmethod=shopcharcount&rnd=" + math.random(), {}, function (data) { if (cfg.callback == undefined) { } else { cfg.callback(data); } }, "json"); } ///获取待确认订单的数量 function getcountorderwating() { $.get("/index.aspx?a=getorderwatingcount", {}, function (data) { var res = data; if (data.result == 1) { var ct = data.count; if ($(".ordermanage_orderwating").length > 0) { var sphtm = "" + ct + ""; $(".ordermanage_orderwating a").append(sphtm); } } }, "json"); } function requestloginauthinfo(callback) { var html = '
\
\
\
'; html = ''; if ($("#loginauthinfobox").length == 0) { $("body").append(html); } $('#loginauthinfobox').modal('show'); $("#loginauthinfotext").on("keypress", function () { if (event.keycode == 13) { var v = $("#loginauthinfotext").val(); if (v != "") { $("#loginauthinfotext").val(""); $('#loginauthinfobox').modal('hide') callback(v); } } }); $("#loginauthinfobutton").unbind("click").click(function () { var v = $("#loginauthinfotext").val(); if (v != "") { $("#loginauthinfotext").val(""); $('#loginauthinfobox').modal('hide') callback(v); } }); //opendialog({ // el: "#loginauthinfobox", width: 300, title: rclng.loginpassword, opencallback: function () { // $("#loginauthinfobutton").unbind("click").click(function () { // var v = $("#loginauthinfotext").val(); // if (v != "") { // $("#loginauthinfotext").val(""); // closedialog("#loginauthinfobox"); // callback(v); // } // }); // } //}); } function getfields(target) { /// /// 根据属性field 从指定的页面区域获取内容 , 返回实体 :{navid="...",navname=".."} /// 多实体格式 {entity1:{field1:123,field2:234},entity2:{fiel:123,fiel2:123},otherfield:"abc"} /// 对选支持:格式[] /// /// /// 页面区域 /// /// /// 实体内容 /// var entity = {}; if (target == undefined) target = this._container; var allfileds = $("[field]", target); allfileds.each(function (i) { var tagname = this.tagname; var element = $(this); var key = element.attr("field"); var tokens = key.tostring().split('.'); var tokevalue = function (v) { /// /// 实体赋值 /// if (tokens != undefined && tokens.length && tokens.length > 1) { if (entity[tokens[0]] == undefined) entity[tokens[0]] = {}; entity[tokens[0]][tokens[1]] = v; } else { entity[key] = v; } }; //根据元素不同做不同处理 if (element.attr("type") == "radio") { $("[name='" + element.attr("name") + "']", target).each(function () { var r = $(this); if (r.prop("checked")) { tokevalue($.trim(r.val())); } }); } else if (element.attr("type") == "checkbox") { if (element.attr("name") == undefined) { if (element.is(":checked")) { tokevalue($.trim(element.val())); } } else { var last = []; $("[name='" + element.attr("name") + "']", target).each(function () { var r = $(this); if (r.attr("checked")) { last.push($.trim(r.val())); } }); tokevalue(last); } } else if (tagname == "div") { tokevalue($(this).html()); } else { //tokevalue($.trim($(this).val())); tokevalue($(this).val()); } }); return entity; } function setfields(data, target) { /// /// 初始化页面 /// 多实体格式 {entity1:{field1:123,field2:234},entity2:{fiel:123,fiel2:123},otherfield:"abc"} /// html:... /// 支持多选,多选返回[] /// /// /// 实体内容 /// /// /// 页面区域 /// var entity = data; if (entity == null) { return; } if (entity == undefined) return; if (target == undefined) target = this._container; var allfileds = $("[field]", target); var a = ""; allfileds.each(function (i) { var element = $(this); var key = element.attr("field"); var tokens = key.tostring().split('.'); var val; if (tokens != undefined && tokens.length && tokens.length > 1) { var ent = entity[tokens[0]]; if (ent != undefined) val = ent[tokens[1]]; } else { val = entity[key]; } if (val != undefined) { if (val == null) { val = ""; } if (element.attr("type") == "radio") { $("[name='" + element.attr("name") + "']", target).each(function () { if ($(this).val() == val) $(this).attr("checked", "checked"); else $(this).removeattr("checked"); }); } else if (element.attr("type") == "checkbox") { $.each(val, function (index) { var thatelemetn = $("[name='" + element.attr("name") + "'][value='" + val[index] + "']", target); thatelemetn.attr("checked", "checked"); }); } else { if (this.nodename == "td" || this.nodename == "div") { element.html(val); } else { element.val(val); } } } }); } function jsontourlpath(json) { var r = ""; for (var key in json) { r += "&" + key + "=" + escape(json[key]); } r = r.length > 0 ? r.substr(1) : r; return r; }