123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- import * as compnt from "../../../../public/js/compnt.js";
- import * as unicom from "../../../../public/js/unicom.js";
- import "../scss/main.scss";
- $(function () {
- var isPageHide = false;
- window.addEventListener('pageshow', function () {
- if (isPageHide) {
- window.location.reload();
- }
- });
- window.addEventListener('pagehide', function () {
- isPageHide = true;
- });
- if (window.location.href.indexOf('draw.html') >=0) {
- var user = JSON.parse(localStorage.getItem('user'));
- if (user != null) {
- $('.usermob').val(user.usermob);
- }
- }
- })
- init();
- function init() {
- var message = localStorage.getItem('message');
- if (message != null && message != '') {
- compnt.showAlert(message);
- localStorage.removeItem('message');
- }
- compnt.showLoading();
- unicom.init().then(function(response) {
- compnt.hideLoading();
- unicom.product = response.product[0];
- unicom.fesname = response.festival;
- unicom.loadUserInfo();
- if (location.href.indexOf("/index") >= 0) {
- showOrderPage();
- } else {
- openPage();
- }
- 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
- }
- })
- }
- function openPage(pageName) {
- switch (pageName) {
- case "active":
- showActivePage();
- break;
- case "cancel":
- showCancelPage();
- break;
- case "draw":
- showDrawPage();
- break;
- case "flow":
- showFlowPage();
- break;
- default:
- showOrderPage();
- break;
- }
- }
- $('#btn-cancel').unbind('click').on('click', function () {
- showCancelPage();
- })
- $('#btn-active').unbind('click').on('click', function () {
- showActivePage();
- })
- $('#gotoDrawPage').unbind('click').on('click', function () {
- showDrawPage(window.location.href.substring(window.location.href.lastIndexOf('/')+1,window.location.href.lastIndexOf('.')))
- })
- function showDrawPage(back) {
- if (location.href.indexOf("draw.html") < 0) {
- window.location.href = "draw.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou + '&back=' + (back == null ? '' : back);
- return;
- }
- var $container = $('.section-login').find('.form-group');
- $container.find('.sendcode').unbind('click').on('click', function () {
- unicom.sendSms($container, 'drawlogin');
- })
- $container.find('.login').unbind('click').on('click', function() {
- var usermob = $container.find('.usermob').val();
- var account = $container.find('.account').val();
- var smscode = $container.find('.smscode').val();
- if (usermob == null || usermob == "") {
- compnt.showAlert('请输入联通手机号');
- return;
- }
- if (account == null || account == "") {
- compnt.showAlert('请输入抖音短视频账号');
- return;
- }
- if (smscode == null || smscode == "") {
- compnt.showAlert('请输入验证码');
- return;
- }
- var $comfirm = showConfirmDialog(account);
- $comfirm.find('.cancel').on('click', function() {
- compnt.hideLoading();
- });
- $comfirm.find('.okay').on('click', function() {
- unicom.checkCode($container, true).done(function() {
- /*unicom.canDrawCoin(account).then(function (response) {
- if (response.resultCode != "0000") {
- compnt.hideLoading();
- compnt.showAlert(response.errorInfo);
- return;
- }
-
- drawCoin(account)
- })*/
- drawCoin(account);
- }).fail(function(data) {
- compnt.hideLoading();
- })
- });
- })
- }
- function drawCoin(account) {
- compnt.showLoading();
- unicom.drawCoin(account, '').done(function(response) {
- compnt.hideLoading();
- switch (response.resultCode) {
- case "0000":
- var $container = $('.section-login').find('.form-group');
- $container.find('.usermob').val('');
- $container.find('.smscode').val('');
- $container.find('.account').val('');
-
- compnt.showAlert('抖币充值中,详情结果以短信形式告知').then(function() {
- if (unicom.query.back != null && unicom.query.back != '') {
- showOrderPage(unicom.query.back + ".html");
- }
- });
- break;
- case "7605":
- compnt.showAlert(response.errorInfo);
- break;
- default:
- var prefix = '';
- if (response.errorInfo.indexOf('领取失败') < 0) {
- prefix = '领取失败,';
- }
- compnt.showAlert(prefix + response.errorInfo);
- break;
- }
- }).fail(function(data) {
- compnt.hideLoading();
- })
- }
- function showOrderPage(backPage) {
- if (location.href.indexOf('/index') < 0) {
- if (backPage == null || backPage == '') {
- backPage = 'order.html';
- }
- window.location.href = backPage + "?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
- return;
- }
- $('#btn-order').unbind('click').on('click', function (event) {
- if (!compnt.lockClick()) {
- return;
- }
- unicom.showCapPage(null, null, false, false, true).then(function (data) {
- compnt.unlockClick();
- order(data.userid, data.token, data.usermob);
- }).fail(function(response) {
- compnt.unlockClick();
- })
- })
- }
- function showFlowPage() {
- if (location.href.indexOf("flow.html") < 0) {
- window.location.href = "flow.html?fes="
- + unicom.query.fes + "&sou=" + unicom.query.sou
- + "&userid=" + unicom.user.userid + "&usermob=" + unicom.user.usermob
- + "&usertime=" + (unicom.user.usertime||(new Date().getTime()));
- return;
- }
- var $container = $('.section-flow');
- var usermob = unicom.user.usermob;
- $container.find('.phone').html(usermob.substring(0,3) + 'xxxx' + usermob.substring(7,11));
- $container.find('.btn').unbind('click').on('click', function() {
- queryFlow().then(function(message) {
- compnt.unlockClick()
- if (message != null && message != "") {
- compnt.showAlert(message);
- }
- }).fail(function() {
- compnt.unlockClick();
- });
- })
- queryFlow();
- }
- function showActivePage() {
- if (location.href.indexOf("active.html") < 0) {
- window.location.href = "active.html?fes=" + unicom.query.fes + "&sou="
- + unicom.query.sou;
- return;
- }
- var $container = $('.section-login').find('.form-group');
- $container.find('.sendcode').unbind('click').on('click', function () {
- if (!checkEquip()) return;
- unicom.sendSms($container, 'activelogin');
- })
- $container.find('.login').unbind('click').on('click', function (event) {
- if (!checkEquip()) return;
- if (!compnt.lockClick()) {
- return;
- }
- unicom.checkCode($container).then(function() {
- compnt.unlockClick()
- active()
- }).fail(function() {
- compnt.unlockClick();
- });
- })
- window.scrollTo(0, 0)
- }
- function showCancelPage() {
- if (location.href.indexOf("cancel.html") < 0) {
- window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
- return;
- }
- var $container = $('.section-login').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).done(function() {
- unicom.cancel().done(function(response) {
- compnt.hideLoading();
-
- switch (response.resultCode) {
- case "0000":
- compnt.showAlert('退订成功');
- break;
- case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
- compnt.showAlert(response.errorInfo);
- 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 checkEquip() {
- /*if (!baidu.app.baidu) {
- compnt.showAlert('请到百度产品客户端中激活免流~')
- return false;
- }
- if (!baidu.checkWeiboVersion()) {
- compnt.showAlert('请到升级到最新版百度产品客户端后激活免流~')
- return false;
- }*/
- return true;
- }
- /**
- * 订购
- */
- function order(userid, token, usermob) {
- compnt.showLoading('处理中,请稍后...');
- unicom.order(userid, token, usermob).done(function(response) {
- compnt.hideLoading();
- switch (response.resultCode) {
- case "0000": //订购成功!跳转到领取会员页面
- unicom.saveUserInfo();
- compnt.showAlert('订购成功');
- return;
- case "0013":
- compnt.showAlert('该号码归属省分2/3G暂未开通此产品!');
- break;
- case "6611":
- compnt.showAlert('错误代码(6611),订购失败,请重试!');
- break;
- case "6615":
- compnt.showAlert('订购失败,请确定用户套餐!');
- break;
- case "6622": // 用户已订购过此产品!跳转到流量查页面
- compnt.showAlert('您已经订购了本产品~')
- unicom.saveUserInfo();
- break;
- default:
- compnt.showAlert(response.errorInfo + ',订购失败,请确定用户套餐!');
- break;
- }
- }).fail(function (error) {
- compnt.hideLoading();
- console.log(error);
- });
- }
- function showAlertDialog(action, message) {
- var className = '';
- switch (action) {
- case 'orderSuccess':
- className = 'dialog-message-order-success';
- break;
- case 'orderFailure':
- className = 'dialog-message-order-failure';
- break;
- case 'activeSuccess':
- className = 'dialog-message-active-success';
- break;
- case 'activeFailure':
- className = 'dialog-message-active-failure';
- break;
- case 'cancelSuccess':
- className = 'dialog-message-cancel-success';
- break;
- case 'cancelFailure':
- className = 'dialog-message-cancel-failure';
- break;
- default:
- break;
- }
- var $overlay = $('<div class="overlay"></div>');
- var $dialog = $(
- '<div class="dialog dialog-message ' + className + '">' +
- ' <div class="title"></div>' +
- ' <div class="content">' + message + '</div>' +
- ' <div class="actions">' +
- ' <div class="btn">确定</div>' +
- ' </div>' +
- '</div>');
- $overlay.appendTo($(document.body))
- $dialog.appendTo($(document.body))
- $dialog.find('.btn').unbind('click').on('click', function () {
- $dialog.close()
- })
- $dialog.close = function () {
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- }
- return $dialog;
- }
- /**
- * 查询用户剩余流量
- */
- function queryFlow() {
- var $container = $('.section-flow');
- //return new Promise(function(resolve, reject) {
- var def = $.Deferred();
- unicom.queryFlow().then(function(response) {
- // var response = JSON.parse(responseText);
- // console.log("流量剩余情况:" + response.data)
- switch (response.resultCode) {
- case "0000":
- //compnt.showAlert(JSON.stringify(response.data));
- //console.log(response.data)
- //console.log(JSON.parse(response.data).surplusFlow)
- var surplus = compnt.returnFloat(JSON.parse(response.data).surplusFlow/1024/1024);
- $container.find('.surplus').html(surplus + 'GB');
- var usedFlowKb = parseInt(JSON.parse(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('本月剩余<br>8.00GB');
- break;
- default:
- def.resolve("剩余流量更新成功~")
- break;
- }
- })
- return def;
- //})
- }
- function active() {
- baidu.active().then(function() {
- //checkActiveResult();
- compnt.showAlert('激活成功').then(function() {
- unicom.saveUserInfo()
- // showFlowPage();
- });
- })
- }
- $('.section-agr').find('.footer').on('click',function() {
- if ($($('.section-agr .scope').find('li')[2]).hasClass('hidden')) {
- $('.section-agr .scope').find('li').each(function(i, ele) {
- $(ele).removeClass('hidden');
- })
- $('.section-agr').find('.footer').html('隐藏<span class="arrow">>');
- } else {
- $('.section-agr .scope').find('li').each(function(i, ele) {
- if (i >= 1) {
- $(ele).addClass('hidden');
- }
- })
- $('.section-agr').find('.footer').html('查看更多专属流量适用范围<span class="arrow">>');
- }
- });
- function showConfirmDialog(account) {
- var $overlay = $('<div class="overlay"></div>')
- var $dialog = $(
- '<div class="dialog dialog-confirm">' +
- ' <div class="content">请确认是否领取抖音币到' + account + '账号?</div>' +
- ' <div class="actions">' +
- ' <div class="btn cancel">取消</div>' +
- ' <div class="btn okay">确认</div>' +
- ' </div>' +
- '</div>');
- $overlay.appendTo($(document.body))
- $dialog.appendTo($(document.body))
- $dialog.find('.btn').on('click', function () {
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- })
- $dialog.close = function () {
- $overlay.remove();
- $dialog.remove();
- $dialog = null;
- }
- return $dialog;
- }
|