/**
* 初始化加载
*/
$(function(){
postini();
ncode = false;
getDeviceId(function (device_id) {
$("#useraccount_tt").attr("value",device_id);
})
});
/**
* 页面统一工具
*/
var derice = "";
var pattern = /^1[34578]\d{9}$/; //判断联通号码正则表达式
var ncode = false;//用于页面判断验证码超时
//------------------获取页面数据----------------------------
/**
* 获取当前url中参数信息
* @param urlprm url中参数名称
* @returns
*/
function getUrlParam(urlprm) {
var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return r[2];
} else {//当获取链接中必须要参数未获取到时标示链接错误直接跳转至统一404页面
if(urlprm=="con"){
return "1";
//获取强制页面跳转标示,不跳转至404.
}else {
var url = getRootPath()+"/404.html";
$(location).attr('href', url);
}
}
}
/**
* 获取项目根目录
* @returns
*/
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);
return(localhostPath + projectName);
}
/**
* 获取对应标签中value
* @param memoid
* @param type
* @returns
*/
function getMemoValbyId(product,type){
var val = "";
switch (type) {
case "phone":
val = $("#input_100_"+product).val();
break;
case "code":
val = $("#input_50_"+product).val();
break;
case "fog":
val = $("#fog_"+product).val();
break;
case "useraccount":
val = $("#useraccount_"+product).val();
break;
case "sendsmsorder":
val = $("#sendsms_order_"+product).val();
break;
case "sendsmscancel":
val = $("#sendsms_cancel_"+product).val();
break;
case "sendsmsyuyue":
val = $("#sendsms_yuyue_"+product).val();
break;
case "sendsmsacti":
val = $("#sendsms_acti_"+product).val();
break;
}
if(val==null){
return "";
}else {
return val;
}
}
//------------------修改页面样式----------------------------
/**
* 根据页面加载函数初始化页面图标,页面主题
* 页面中必须有对应标签ID
* @param iniJson 后台获取到的页面加载函数
*/
function theme(title,icon){
//加载页面主题文字
$("title").text(title);
//加载页面图标
$("#icon").attr("href", icon+".ico");
}
/**
* 页面中样式提醒
* @param inc 事件名称
* @param product 对应产品
* @param message
*/
function hint(inc,product,message){
$("#warning_"+inc+"_"+product).removeAttr("style");
$("#warning_"+inc+"_"+product).text(message);
}
/**
* 跳转至404页面
*/
function goto404(){
var url = getRootPath()+"/404.html";
$(location).attr('href', url);
}
/**
* 页面弹框提示
*/
function pro_bounced(headmg,textmg,buttonmg,state){
emptyM();
$(".layer").removeAttr("style");
$(".head").append("
"+headmg+"
");
$(".coupon").append(""+textmg+"
");
if(state){
$(".coupon").append("");
}else{
$(".coupon").append("");
}
}
/**
* 去往成功页面
*/
function gotosucc(){
var url = getRootPath()+"/tt/orderSucc.html" +
"?fes="+getUrlParam("fes")+"&sou="+getUrlParam("sou")+
"&phone="+getMemoValbyId('tt', 'phone')+"&fog="+getMemoValbyId('tt', 'fog');
$(location).attr('href', url);
}
/**
* 为查询到订购关系时强制跳转至订购页面
*/
function gotorder(){
var url = getRootPath()+"/tt/order.html" +
"?fes="+getUrlParam("fes")+"&sou="+getUrlParam("sou")+
"&con=0";
$(location).attr('href', url);
}
/**
* 跳转至对应页面
*/
function gotoUrl(html){
var url = getRootPath()+"/"+html+".html?fes="+getUrlParam("fes")+"&sou="+getUrlParam("sou");
$(location).attr('href', url);
}
//刷新弹层文本框
function emptyM() {
$(".head").empty();
$(".coupon").empty();
}
// 关闭所有弹层
function closeSe() {
$(".warning").attr("style", "display:none;");
$(".layer").attr("style", "display:none;");
}
/**
* 百度统计组件
*/
// var _hmt = _hmt || [];
// (function() {
// var hm = document.createElement("script");
// hm.src = "https://hm.baidu.com/hm.js?0ece85510b3306c074204023de4e49dc";
// var s = document.getElementsByTagName("script")[0];
// s.parentNode.insertBefore(hm, s);
// })();
//------------------请求----------------------------
/*--页面初始化加载--*/
/**
* 消息发送获取Josn数据
* @param method 方法名称
* @param data 发送数据
* @returns 返回的json数据
* 此方法需加载页面头信息与页面显示图标:
* 页面必须有 title 标签
* id = "icon" 链接地址
*
* 加载页面基本信息:
* XX 为活动对应产品表中配置标示
*
*/
function postini(){
$.ajax({
url : getRootPath() + "-s1api" + '/ini/getstyle',
type : "POST", // 用POST方式传输
contentType : "application/json; charset=utf-8",
dataType : "Json",
data: JSON.stringify(postiniDate()),
success:
function(msg) {
var resCode = msg["resultCode"];
if(resCode == "0000"){
var festival = msg["festival"];
theme(festival["title"], festival["icon"]);//加载页面信息头,图标
var productlist = msg["product"];
for(var i=0,l=productlist.length;i= 0) {
burypointLogId('110002');// 退订页面pv, pv去重得到uv
} else if (location.href.indexOf('/draw') >= 0) {
burypointLogId('110003');// 领取页面pv, pv去重得到uv
} else if (location.href.indexOf('/flow') >= 0) {
burypointLogId('110004');// 流量查询pv, pv去重得到uv
} else if (location.href.indexOf('/active') >= 0) {
burypointLogId('110005');// 激活页面pv, pv去重得到uv
} else {
// location.href.indexOf('/index') >= 0
// location.href.indexOf('/order') >= 0
burypointLogId('110001');// 订购页面pv, pv去重得到uv
}
},
error:
function(XMLHttpRequest, textStatus,errorThrown){//加载请求失败
goto404();
},
});
}
/**
* 验证码发送
* @param product
*/
function sendSms(product,mode) {
if(getMemoValbyId("tt", "phone")!=""){//判断号码是否输入
if(pattern.test(getMemoValbyId("tt", "phone"))){//判断号码格式
$.ajax({
type : "POST",
contentType : "application/json; charset=utf-8",
dataType : "Json",
url : getRootPath() + "-s1api" + '/sms',//目标地址
data : JSON.stringify(sendSmsDate(product,mode)),
success : function(msg) {
var resCode = eval(msg["resultCode"]);
if (resCode == "0000") {
ncode = true;
coderun("");
} else {
hint("code", product, msg["errorInfo"]);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
hint("code", product, "数据提交失败");
},
});
}else {
hint("phone", product, "请输入正确的中国联通手机号码");
}
} else {
hint("phone", product, "手机号码未输入");
}
}
/**
* 数据加载发送信息包装.
*/
function postiniDate() {
var data = {
fes : getUrlParam("fes"),
sou : getUrlParam("sou"),
};
return data;
}
/**
* 短信发送信息包装.
*/
function sendSmsDate(product,mode){
var data = {
"fog" : getMemoValbyId(product, "fog"),
"usermob" : getMemoValbyId(product, "phone"),
"smstype" : getMemoValbyId(product, "sendsms"+mode),
"sou" : getUrlParam("sou"),
};
return data;
}
/**
* 订购发送信息包装
* @param product
* @returns {___anonymous5356_5582}
*/
function GetMasData(product) {
var data = {
"code" : getMemoValbyId(product, "code"),
"fog" : getMemoValbyId(product, "fog"),
"usermob" : getMemoValbyId(product, "phone"),
"useraccount" : getMemoValbyId(product, "useraccount"),
"fes" : getUrlParam("fes"),
"sou" : getUrlParam("sou"),
};
return data;
}
/**
* 获取流量
*/
function GetFlowJsonData(product){
var data = {
"fog" : fog,
"usermob" : phone,
};
return data;
}
/**
* 订购发送信息包装
* @param product
* @returns {___anonymous5356_5582}
*/
function GetDevData(device) {
var data = {
"device_id" : device,
};
return data;
}
function getDecice(){
getDeviceId(function (device_id) {
return device_id;
})
}
function getDeviceId(cb) {
var client_id = '7376a4d6da8df222';
window.ToutiaoJSBridge.call('config', {
client_id: client_id,
}, function () {
toutiao.appInfo({
success: function (res) {
if (cb) {
cb(res.device_id || '')
}
},
fail: function (res) {
return "4001";
},
error: function (res) {
return "4001";
},
});
});
}
/**
* 获取激活号码手机号
* @param device
*/
function devToPhone(device) {
$.ajax({
type : "POST",
contentType : "application/json; charset=utf-8",
dataType : "Json",
url : getRootPath() + "-s1api" + '/com/dev',
data : JSON.stringify(GetDevData(device)),
success : function(msg) {
var resCode = eval(msg["err_no"]);
if(resCode=="0"){
var data = eval(msg["data"]);
var usermob = data["mobile"];
//说明当前用户已激活跳转至流量查询页面
var url = getRootPath() + "/tt/orderSucc.html" +
"?fes="+getUrlParam("fes")+"&sou="+getUrlParam("sou")+
"&phone="+usermob+"&fog="+getMemoValbyId('tt', 'fog');
$(location).attr('href', url);
}else {
}
},
error : function(XMLHttpRequest, textStatus,
errorThrown) {
//获取号码超时.
},
});
}
(function () {
Date.prototype.from = function (dateString) {
var pattern2 = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
var str = dateString.replace(/-/g, '/');
str = str.replace(pattern2, '$1/$2/$3 $4:$5:$6')
return new Date(str)
}
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
})();
function getTodaySurplusMillis() {
var time1 = new Date();
var time2 = time1.from(time1.getFullYear() + '-' + (time1.getMonth() + 1) + '-' + time1.getDate() + ' 23:59:59');
console.log(time2.getTime() - time1)
return time2.getTime() - time1.getTime();
}
function burypointLogId(operid, remark, url) {
var uuid = getCookie('uuid');// uv
var vvid = getCookie('vvid');// vv
if (uuid == null || uuid.trim() == '') {
uuid = guid();
setCookie('uuid', uuid, compnt.getTodaySurplusMillis());
}
if (vvid == null || vvid.trim() == '') {
vvid = guid();
setCookie('vvid', vvid, -1);
}
if (operid == null || operid == '') {
// 页面的埋点不通过/burypoint/logid接口实现,通过文件日志入库方式
return;
}
var param = {
operid: operid,
uuid: uuid,
vvid: vvid,
fog: getMemoValbyId('tt', 'fog'),
userid: '',
fes: getUrlParam("fes"),
sou: getUrlParam("sou"),
url: encodeURIComponent(url||window.location.href),
remark: encodeURIComponent(remark||'')
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "Json",
url: getRootPath() + "-s1api" + '/burypoint/logid',//目标地址
data: JSON.stringify(param),
success: function () {},
error: function () {},
});
}
function getCookie(name) {
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
/**
* 如果没有设置时间
*/
function setCookie(name, value, millis) {
millis = (millis == undefined ? 0 : millis);
var exp = new Date();
if (millis < 0) {
document.cookie = name + "=" + escape(value);
} else {
exp.setTime(exp.getTime() + millis);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
}
function guid() {
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}