123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- var root = null;
- var user = {};
- var query = {};
- var product = {};
- init();
- function init() {
- window.root = getRootPath();
- parseQueryParms();
- $("#useraccount_tt").attr("value", getUrlParam("freeflow_token"));
- var param = {
- fes: getUrlParam("fes"),
- sou: getUrlParam("sou")
- };
- var def = $.Deferred();
- $.ajax({
- url: root + "-s1api" + "/ini/getstyle",
- type: "POST",
- contentType: "application/json",
- data: JSON.stringify(param),
- timeout: 10000
- }).then(
- function (responseText) {
- var response = JSON.parse(responseText);
- if (response.resultCode != "0000") {
- // window.location.href = window.root + "/404.html";
- // def.reject();
- // return def;
- }
- add();
- if (
- response.product[0].productid == "2020010201" ||
- response.product[0].productid == "2022071807"
- ) {
- product = response.product[0];
- } else {
- product = response.product[1];
- }
- // for (i = 0; i < response.product.length; i++) {
- // products[response.product[i].productid] = response.product[i]
- // }
- // $("#fog_" + product.url).attr("value", product.fog);
- // var smslist = product.icon.split(",");
- // for (var i = 0; i < smslist.length; i++) {
- // if (i == 0) {
- // $("#sendsms_order_" + product.url).attr("value", smslist[i]);
- // }
- // if (i == 1) {
- // $("#sendsms_cancel_" + product.url).attr("value", smslist[i]);
- // }
- // if (i == 2) {
- // $("#sendsms_yuyue_" + product.url).attr("value", smslist[i]);
- // }
- // }
- // def.resolve(response);
- },
- function (jqXHR, textStatus, errorThrown) {
- if (textStatus === "timeout") {
- // window.location.href = getRootPath() + "/hot.html?cb=" + encodeURIComponent(window.location.href);
- }
- }
- );
- return def;
- }
- function add() {
- var $container = $(".sms-form").find(".form-group");
- $container
- .find(".sendcode")
- .unbind("click")
- .on("click", function () {
- sendSms($container, "login");
- });
- $container
- .find(".login")
- .unbind("click")
- .on("click", function () {
- showLoading();
- checkCode($container)
- .done(function (response) {
- var url = getQueryString("redirectUrl");
- if (
- decodeURIComponent(url).indexOf("https://800.wo.cn") >= 0 ||
- decodeURIComponent(url).indexOf("https://operation1.bol.wo.cn/") >= 0
- ) {
- console.log(1);
- window.location.href =
- decodeURIComponent(url) +
- "&userid=" +
- response.userid +
- "&usermob=" +
- response.usermob;
- }
- })
- .fail(function (data) {
- hideLoading();
- });
- });
- }
- function getQueryString(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) return unescape(r[2]);
- return null;
- }
- function hideLoading($loading) {
- if ($loading) {
- $loading.trigger("close");
- return;
- } else if (window.$loading) {
- window.$loading.trigger("close");
- return;
- }
- }
- function showLoading(message) {
- if (window.$loading) {
- window.$loading.trigger("close");
- }
- $("body").css("overflow", "hidden");
- var msg = message || "处理中,请稍后...";
- var $overlay = $('<div class="overlay overlay-loading"></div>');
- var $loading = $(
- '<div class="loading">' + ' <div class="content">' + msg + "</div>" + "</div>"
- );
- $overlay.appendTo($(document.body));
- $loading.appendTo($(document.body));
- $loading.on("close", function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $loading.remove();
- $loading = null;
- });
- window.$loading = $loading;
- return $loading;
- }
- function sendSms($container, smstype, currentProduct) {
- var def = $.Deferred();
- if ($container.attr("n") != null && $container.attr("n") > 0) {
- return;
- }
- var usermob = $container.find(".usermob").val();
- if (usermob == null || usermob.trim() == "") {
- showAlert("请输入联通手机号码");
- def.reject();
- return def;
- }
- if (!usermob.startsWith("1") || usermob.length != 11) {
- showAlert("手机号码格式不正确");
- def.reject();
- return def;
- }
- var param = {
- fes: getUrlParam("fes"),
- sou: getUrlParam("sou"),
- fog: product.fog,
- usermob: usermob,
- smstype: smstype
- };
- user.usermob = usermob;
- var count = 60;
- $container.attr("n", count);
- $.ajax({
- url: root + "-s1api" + "/sms/send",
- type: "POST",
- contentType: "application/json",
- data: JSON.stringify(param)
- }).then(function (response) {
- if (response.resultCode != "0000") {
- count = 0;
- $container.attr("n", count);
- showAlert(response.errorInfo);
- return;
- }
- var $sendcode = $container.find(".sendcode");
- var template = "{}s";
- if ($sendcode.is("input")) {
- $sendcode.val(template.replace("{}", count));
- } else {
- $sendcode.text(template.replace("{}", count));
- }
- $sendcode.addClass("sendcode-wait");
- var timer = setInterval(function () {
- count -= 1;
- $container.attr("n", count);
- if ($sendcode.is("input")) {
- $sendcode.val(template.replace("{}", count));
- } else {
- $sendcode.text(template.replace("{}", count));
- }
- if (count === 0) {
- clearInterval(timer);
- if ($sendcode.is("input")) {
- $sendcode.val("获取验证码");
- } else {
- $sendcode.text("获取验证码");
- }
- $container.attr("n", count);
- $sendcode.removeClass("sendcode-wait");
- }
- }, 1000);
- try {
- window.HtmlPageVisitor && window.HtmlPageVisitor.setMp(user.usermob);
- } catch (e) {}
- });
- }
- function checkCode($container, keepUserInfo) {
- var def = $.Deferred();
- var usermob = $container.find(".usermob").val();
- var smscode = $container.find(".smscode").val();
- if (keepUserInfo == null) keepUserInfo = false;
- if (usermob == null || usermob.trim() == "") {
- showAlert("请输入联通手机号码");
- def.reject();
- return def;
- }
- if (smscode == null || smscode.trim() == "") {
- showAlert("请输入验证码");
- def.reject();
- return def;
- }
- if (smscode.length != 6) {
- showAlert("短信验证码不正确");
- def.reject();
- return def;
- }
- var param = {
- fes: getUrlParam("fes"),
- sou: getUrlParam("sou"),
- fog: product.fog,
- code: smscode,
- usermob: usermob
- };
- $.ajax({
- url: root + "-s1api" + "/checkvercode",
- type: "POST",
- contentType: "application/json",
- data: JSON.stringify(param)
- })
- .then(function (response) {
- $container.find(".smscode").val("");
- switch (response.resultCode) {
- case "0000":
- user.userid = response.userid;
- user.usermob = usermob;
- user.usertime = new Date().getTime();
- if (!keepUserInfo) {
- $container.find(".usermob").val("");
- $container.find(".usermob").val("");
- }
- def.resolve(response);
- break;
- default:
- showAlert(response.errorInfo);
- def.reject(response);
- break;
- }
- })
- .fail(function (error) {
- def.reject("服务调用异常");
- });
- return def;
- }
- function showAlert(message, hideButton, buttonLabel, hideTitle) {
- var title = "";
- if (hideTitle == undefined || hideTitle == false) {
- title = "温馨提示";
- }
- var $overlay = $('<div class="overlay overlay-alert"></div>');
- var $dialog = $(
- '<div class="dialog-alert">' +
- "<h1>" +
- title +
- "</h1>" +
- '<div class="content">' +
- message +
- "</div>" +
- '<div class="actions">' +
- ' <div class="btn btnsr">' +
- (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
- "</div>" +
- "</div>" +
- "</div>"
- );
- $("body").css("overflow", "hidden");
- $overlay.appendTo($(document.body));
- $dialog.appendTo($(document.body));
- if (hideButton == true) {
- $dialog.find(".btn").remove();
- }
- $dialog.close = function () {
- $("body").css("overflow", "auto");
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- };
- var def = $.Deferred();
- $dialog.find(".btn").on("click", function () {
- $dialog.close();
- def.resolve($dialog);
- });
- return def;
- }
- function getRootPath() {
- //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
- var curWwwPath = window.document.location.href;
- //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
- var pathName = window.document.location.pathname;
- var pos = curWwwPath.indexOf(pathName);
- //获取主机地址,如: http://localhost:8080
- var localhostPath = curWwwPath.substring(0, pos);
- //获取带"/"的项目名,如:/ems
- var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
- root = localhostPath + projectName;
- return localhostPath + projectName;
- }
- function getUrlParam(urlprm) {
- var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) {
- return r[2];
- }
- }
- function parseQueryParms() {
- var QUERY_SEPARATOR = "&",
- VALUE_SEPARATOR = "=";
- var queryStr = window.location.search.substring(1);
- var startIndex = 0,
- vIndex,
- qIndex;
- while (queryStr.length > 0) {
- vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex);
- if (vIndex == -1) {
- break;
- }
- qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1);
- if (qIndex == -1) {
- qIndex = queryStr.length;
- }
- var key = queryStr.substring(startIndex, vIndex);
- var value = queryStr.substring(vIndex + 1, qIndex);
- query[key] = decodeURIComponent(value);
- startIndex = qIndex + 1;
- }
- }
|