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 = $('
');
var $loading = $(
'"
);
$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 = $('');
var $dialog = $(
'' +
"
" +
title +
"
" +
'
' +
message +
"
" +
'
' +
'
' +
(buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
"
" +
"
" +
"
"
);
$("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;
}
}