import * as compnt from "../../../public/js/compnt";
import * as unicom from "../../../public/js/unicom.js";
import * as weibo from "./weibo.js";
weibo.checkClientEnvironment();
compnt.showLoading();
var message = localStorage.getItem('message');
if (message != null && message != '') {
compnt.showAlert(message);
localStorage.removeItem('message');
}
if (weibo.app.weibo) {
function bridgeReady() {
if (weibo.checkWeiboVersion()) {
weibo.getUserInfo().then(function() {
init();
}).fail(function(data) {
init();
});
} else {
weibo.getUserInfo();
init();
}
}
if (window.WeiboJSBridge) {
bridgeReady();
} else {
document.addEventListener('WeiboJSBridgeReady', function () {
bridgeReady();
});
}
} else {
init();
}
function init() {
unicom.init().then(function(response) {
unicom.product = response.product[0];
unicom.fesname = response.festival;
loadUserInfo();
// compnt.showAlert(JSON.stringify(unicom.user))
// compnt.showAlert(weibo.uid)
if (location.href.indexOf("index.html") >= 0) {
if (unicom.user.userid) {
openPage("flow");
} else if (weibo.uid) {
unicom.queryMember(null, null, weibo.uid).then(function(response) {
// compnt.showAlert("queryMember:" + JSON.stringify(response.data))
if (response.resultCode != "0000") {
showOrderPage();
compnt.hideLoading();
return;
}
unicom.user.userid = response.userid;
unicom.user.usermob = response.usermob;
unicom.user.usertime = new Date().getTime();
showFlowPage(response);
compnt.hideLoading();
}).fail(function() {
compnt.showAlert("asdasd");
});
}
compnt.hideLoading();
showOrderPage();
} else {
openPage(unicom.query.page);
compnt.hideLoading();
}
/*unicom.user.userid = "18674842761";
unicom.user.usermob = '17610768237'
showFlowPage();*/
if (location.href.indexOf('/cancel') >= 0) {
unicom.burypointLogId('110002');// 退订页面pv, pv去重得到uv
} else if (location.href.indexOf('/draw') >= 0) {
unicom.burypointLogId('110003');// 领取页面pv, pv去重得到uv
} else if (location.href.indexOf('/flow') >= 0) {
unicom.burypointLogId('110004');// 流量查询pv, pv去重得到uv
} else if (location.href.indexOf('/active') >= 0) {
unicom.burypointLogId('110005');// 激活页面pv, pv去重得到uv
} else if (location.href.indexOf('/refund') >= 0) {
unicom.burypointLogId('110006');// 退款
} else {
// location.href.indexOf('/index') >= 0
// location.href.indexOf('/order') >= 0
unicom.burypointLogId('110001');// 订购页面pv, pv去重得到uv
}
}).fail(function() {
compnt.hideLoading();
})
}
function openPage(pageName) {
switch (pageName) {
case "active":
showActivePage();
break;
case "cancel":
showCancelPage();
break;
case "draw":
if (weibo.uid == null || weibo.uid == '') {
weibo.getUserInfo().then(function(response) {
showDrawPage();
})
} else {
showDrawPage();
}
break;
case "flow":
showFlowPage();
break;
default:
showOrderPage();
break;
}
}
function loadUserInfo() {
if (unicom.query.userid) {
unicom.user.userid = unicom.query.userid;
unicom.user.usermob = unicom.query.usermob;
return;
}
try {
var time = localStorage.getItem('time');
if (time) {
var curr = new Date().getTime();
if (curr <= parseFloat(time) + (1000 * 60 * 60)) {
var userString = localStorage.getItem("user");
var user = JSON.parse(userString);
unicom.user.userid = user.userid;
unicom.user.usermob = user.usermob;
if (unicom.user.usermob == "18674842761") {
setTimeout(function() {
alert(time + (1000 * 60 * 60))
}, 100);
}
} else {
localStorage.removeItem("time")
localStorage.removeItem("user")
}
}
} catch (e) {
}
}
$('#btn-cancel').unbind('click').on('click', function () {
showCancelPage();
})
$('#btn-draw').unbind('click').on('click', function () {
if (!checkEquip('draw')) return;
showDrawPage();
})
$('#btn-active').unbind('click').on('click', function () {
if (!checkEquip('active')) return;
showActivePage();
})
/**
* 显示流量查询页面
*/
function showFlowPage() {
if (location.href.indexOf("flow.html") < 0) {
window.location.href = "flow.html?fes="
+ unicom.query.fes + "&sou=" + unicom.query.sou + "&F=" + unicom.query.F
+ "&userid=" + unicom.user.userid + "&usermob=" + unicom.user.usermob
+ "&usertime=" + (unicom.user.usertime||(new Date().getTime())) + "&page=flow";
return;
}
if (localStorage.getItem('action') == 'draw') {
if (!checkEquip('draw')) return;
unicom.can(weibo.uid).then(function(response) {
if (response.resultCode == "0000") {
draw();
}
});
localStorage.removeItem('action');
}
var $container = $('#section-flow');
$container.find('.phone').html('免流号码:' + unicom.user.usermob);
queryFlow();
$container.find('.btn').unbind('click').on('click', function (event) {
if (!compnt.lockClick()) {
return;
}
queryFlow().then(function(message) {
compnt.unlockClick()
if (message != null && message != "") {
compnt.showAlert(message);
}
});
})
$container.find('.member a').unbind('click').on('click', function () {
if (!checkEquip('draw')) return;
// alert(weibo.screen_name)
// 如果有用户号码,直接打开领取会员二次确认的提示
unicom.can(weibo.uid).then(function(response) {
switch (response.resultCode) {
case "0000":
if (unicom.user.userid) {
draw();
} else {
showDrawPage();
}
break;
case "1003":
compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
break;
default:
compnt.showAlert(response.resultInfo);
break;
}
});
})
if (weibo.app.weibo && weibo.checkWeiboVersion() && (weibo.uid == null || weibo.uid == '')) {
weibo.getUserInfo().then(function() {
unicom.queryMember().then(function(response) {
showMemberInfo(response)
});
})
} else {
unicom.queryMember().then(function(response) {
showMemberInfo(response)
});
}
function showMemberInfo(response) {
// alert("showMemberInfo:" + JSON.stringify(response.data))
switch (response.resultCode) {
case "0000":
switch (response.sync_code) {
case "0": // 订购关系退订同步成功
case "2": // 订购关系订购同步成功
if (response.screen_name) {
$container.find('.member').html('微博账号:' + response.screen_name);
} else {
$container.find('.member').html('微博会员:已领取');
}
$container.find('.vflag').css({"display": "block"});
$container.find('.member a').unbind('click');
weibo.active(); // 静默激活
break;
default:
$container.find('.member a').html('请点此领取微博会员');
// 隐藏微博会员图标
$container.find('.vflag').css({"display": "none"})
break;
}
break;
case "1015": //{"resultCode":"1015","errorInfo":"用户未订购此产品!"}
compnt.showAlert("未订购此产品!").then(function(message) {
localStorage.removeItem('time');
localStorage.removeItem('user')
showOrderPage();
$container.find('.phone').html('用户未订购此产品!');
});
break;
default:
break;
}
}
}
/**
* 查询用户剩余流量
*/
function queryFlow() {
var $container = $('#section-flow');
var def = $.Deferred();
unicom.queryFlow().then(function(response) {
// console.log("流量剩余情况:" + response.data)
switch (response.resultCode) {
case "0000":
//compnt.showAlert(JSON.stringify(response.data));
var surplus = compnt.returnFloat(response.data.surplusFlow/1024/1024);
$container.find('.suplus').html('本月剩余
' + surplus + 'GB');
var usedFlowKb = parseInt(response.data.usedFlow);
if (usedFlowKb > 0 && usedFlowKb < 1024) {
def.resolve("剩余流量更新成功,为您免流了" + usedFlowKb + "KB~");
} else if (usedFlowKb > 1024) {
var useedFlow = compnt.returnFloat(usedFlowKb/1024);
def.resolve("剩余流量更新成功,为您免流了" + useedFlow + "MB~");
} else {
def.resolve("剩余流量更新成功~");
}
break;
case "9201": //{"resultCode":"9201","errorInfo":"查询失败,请检查是否有订购关系!"}
def.resolve("您未订购新浪微博畅想会员畅想包~")
$container.find('.phone').html('用户未订购此产品!');
break;
case "9203": //{"resultCode":"9203","errorInfo":"流量查询失败,没有获取到用户所使用流量信息!"}
//compnt.showAlert("没有获取到用户所使用流量信息!");
def.resolve("剩余流量更新成功~")
$container.find('.suplus').html('本月剩余
10.00GB');
break;
default:
break;
}
})
return def;
}
/**
* 打开退订页面
*/
function showCancelPage() {
if (location.href.indexOf("cancel.html") < 0) {
window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou="
+ unicom.query.sou + "&F=" + unicom.query.F + '&page=cancel';
return;
}
var $container = $('#section-cancel').find('.form-group');
$container.find('.sendcode').unbind('click').on('click', function () {
unicom.sendSms($container, 'cancellogin');
})
$container.find('.login').unbind('click').on('click', function () {
compnt.showLoading();
unicom.checkCode($container).then(function() {
unicom.cancel().then(function(response) {
compnt.hideLoading();
switch (response.resultCode) {
case "0000":
compnt.showAlert('退订成功').then(function(message) {
showFlowPage();
});
break;
case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
compnt.showAlert(response.errorInfo).then(function(message) {
showFlowPage();
});
break;
default:
var prefix = '';
if (response.errorInfo.indexOf('退订失败') < 0) {
prefix = '退订失败,';
}
compnt.showAlert(prefix + response.errorInfo);
break;
}
}).fail(function(data) {
compnt.hideLoading();
})
}).fail(function(data) {
compnt.hideLoading();
})
})
window.scrollTo(0, 0)
}
/**
* 打开领取会员的页面
* 在客户端中才能领取会员
*/
function showDrawPage() {
if (location.href.indexOf("draw.html") < 0) {
window.location.href = "draw.html?fes=" + unicom.query.fes + "&sou="
+ unicom.query.sou + "&F=" + unicom.query.F + '&page=draw';
return;
}
var $container = $('#section-draw').find('.form-group');
compnt.showLoading();
unicom.queryMember(null, null, weibo.uid).then(function(response) {
// alert("response.data:" + JSON.stringify(response.data))
if (response.resultCode == "0000") {
switch (response.sync_code) {
case "0": // 订购关系退订同步成功
case "2": // 订购关系订购同步成功
localStorage.setItem("message", "当前微博账号已经领取了会员~");
unicom.user.userid = response.userid;
unicom.user.usermob = response.usermob;
unicom.user.usertime = new Date().getTime();
showFlowPage();
break;
}
} else {
unicom.can(weibo.uid).then(function(response) {
compnt.hideLoading();
var hasMonthVip = false;
switch (response.resultCode) {
case "0000":
hasMonthVip = false;
break;
case "1003":
compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
hasMonthVip = true;
break;
default:
compnt.showAlert(response.resultInfo);
break;
}
$container.find('.sendcode').unbind('click').on('click', function () {
if (!checkEquip()) return;
if (hasMonthVip) {
compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
return;
}
unicom.sendSms($container, 'drawlogin');
})
$container.find('.login').unbind('click').on('click', function () {
if (hasMonthVip) {
compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
return;
}
unicom.checkCode($container).then(function() {
draw()
})
})
})
}
})
}
function draw() {
var $dialog = showConfirmDialog();
$dialog.find('.btn-no').on('click', function() {
compnt.showAlert('请切换登录的微博账号后,再领取会员')
})
$dialog.find('.btn-ok').on('click', function(event) {
if (!compnt.lockClick()) return;
unicom.drawMember(weibo.uid, weibo.screen_name).then(function(response) {
compnt.unlockClick();
switch (response.resultCode) {
case "0000":
weibo.active(); // 领取成功,静默激活
compnt.showAlert('微博会员领取成功!').then(function() {
showFlowPage();
});
break;
case "1020":
// 已经领取,领取的账号与当前微博账号一致,静默激活
unicom.queryMember().then(function(response) {
if (response.resultCode == "0000") {
if (response.uid == weibo.uid) {
weibo.active();
compnt.showAlert('已领取过会员~').then(function(message) {
showFlowPage();
});
} else {// 领取到了其他微博账号
compnt.showAlert('该手机号已将会员领取到其他微博账号~')
}
} else {// 查询失败
compnt.showAlert('已领取过会员~');
}
}).fail(function() {
// 查询失败
compnt.showAlert('已领取过会员~');
})
break;
default:
compnt.showAlert('领取失败,' + response.errorInfo);
break;
}
}).fail (function() {
compnt.unlockClick();
});
})
}
/**
* 打开激活免流的页面
* 客户端中才能激活
*/
function showActivePage() {
if (location.href.indexOf("active.html") < 0) {
window.location.href = "active.html?fes=" + unicom.query.fes + "&sou="
+ unicom.query.sou + "&F=" + unicom.query.F + "&page=active";
return;
}
var $container = $('#section-active').find('.form-group');
$container.find('.sendcode').unbind('click').on('click', function () {
if (!checkEquip('active')) return;
unicom.sendSms($container, 'activelogin');
})
$container.find('.login').unbind('click').on('click', function (event) {
if (!checkEquip('active')) return;
if (!compnt.lockClick()) {
return;
}
unicom.checkCode($container).then(function() {
compnt.unlockClick()
active()
}).fail(function() {
compnt.unlockClick();
});
})
window.scrollTo(0, 0)
}
function checkEquip(action) {
if (action == 'active') {
if (!weibo.app.weibo) {
compnt.showAlert('请到新浪微博客户端中激活免流~')
return false;
}
if (!weibo.checkWeiboVersion()) {
compnt.showAlert('请到升级到最新版新浪微博客户端后激活免流~')
return false;
}
} else {
if (!weibo.app.weibo) {
compnt.showAlert('请到新浪微博客户端中领取会员激活免流~')
return false;
}
if (!weibo.checkWeiboVersion()) {
compnt.showAlert('请到升级到最新版新浪微博客户端后领取会员激活免流~')
return false;
}
}
return true;
}
function active() {
unicom.queryMember().then(function(response) {
switch (response.resultCode) {
case "0000":
break;
case "0002":
compnt.showAlert('激活失败,未领取新浪微博会员~');
return;
default:
compnt.showAlert('激活失败,未领取新浪微博会员~');
return;
}
if (weibo.uid != response.uid) {
compnt.showAlert('激活失败,激活免流的微博账号与领取会员的微博账号不一致~');
return;
}
switch (response.sync_code) {
case "0": // 订购关系退订同步成功
case "2": // 订购关系订购同步成功
weibo.active().then(function() {
//checkActiveResult();
compnt.showAlert('激活成功').then(function() {
localStorage.setItem('user', JSON.stringify(unicom.user));
localStorage.setItem('time', new Date().getTime());
showFlowPage();
});
})
break;
case "1": // 订购关系退订同步失败
case "3": // 订购关系订购同步失败
compnt.showAlert("请领取会员以后再进行激活操作~");
break;
}
});
}
/**
* 打开订购页面
*/
function showOrderPage() {
$('.section-banner').removeClass('section-banner-small');
$('#btn-order').unbind('click').on('click', function (event) {
if (!compnt.lockClick()) {
//alert(1)
return;
}
unicom.showCapPage().then(function (data) {
compnt.unlockClick();
order(data.userid, data.token, data.usermob);
}).fail(function(response) {
compnt.unlockClick();
})
})
}
/**
* 订购
*/
function order(userid, token, usermob) {
unicom.order(userid, token, usermob).then(function(response) {
// console.log(response)
switch (response.resultCode) {
case "0000": //订购成功!跳转到领取会员页面
// compnt.showAlert('unicom.user.userid:' + unicom.user.userid)
// var versionFulfil = weibo.checkWeiboVersion();
// alert('checkWeiboVersion()' + versionFulfil);
localStorage.setItem('user', JSON.stringify(unicom.user));
localStorage.setItem('time', new Date().getTime());
// 客户端中进入领取页面,非客户端中,提示用户到客户端中去领取
if (weibo.app.weibo && weibo.checkWeiboVersion()) {
// 如果有用户号码,直接打开领取会员二次确认的提示
compnt.showAlert('订购成功~').then(function(message) {
localStorage.setItem('action', 'draw');
showFlowPage();
})
} else {
compnt.showAlert('订购成功,请到新浪微博客户端中领取会员开启免流~').then(function() {
showFlowPage();
})
return;
}
break;
case "0013":
showOrderDialog('该号码归属省分2/3G暂未开通此产品!');
break;
case "6611":
showOrderDialog('错误代码(6611),' + '订购失败,请重试!');
break;
case "6615":
showOrderDialog('订购失败,请确定用户套餐!');
break;
case "6622": // 用户已订购过此产品!跳转到流量查页面
localStorage.setItem('message', '您已经订购了本产品~');
localStorage.setItem('user', JSON.stringify(unicom.user));
localStorage.setItem('time', new Date().getTime());
showFlowPage();
break;
default:
showOrderDialog(response.errorInfo + ',订购失败,请确定用户套餐!');
break;
}
}).fail(function (error) {
console.log(error);
});
}
function showOrderDialog(message) {
var $overlay = $('
' + message + '
' + '' + message + '
' + '