import * as compnt from "../../public/js/compnt.js"; import * as unicom from "../../public/js/unicom.js"; import * as baidu from "../../sina/wb/js/weibo.js"; import "../scss/main.scss"; compnt.unlockClick(); $(function () { var isPageHide = false; window.addEventListener('pageshow', function () { if (isPageHide) { window.location.reload(); } }); window.addEventListener('pagehide', function () { isPageHide = true; }); }) init(); function init() { try { var message = localStorage.getItem('message'); if (message != null && message != '') { if (message.indexOf("您已经订购") >= 0) { showAlertDialog('orderFailure', message); } else { compnt.showAlert(message); } localStorage.removeItem('message'); } } catch (e) { // alert('na ni ?') } 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.html") >= 0) { if (unicom.user.userid) { openPage("flow"); } else { 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) { if (pageName == null) { if (location.href.indexOf("index.html") >= 0) pageName = "order"; if (location.href.indexOf("cancel.html") >= 0) pageName = "cancel"; if (location.href.indexOf("active.html") >= 0) pageName = "active"; if (location.href.indexOf("flow.html") >= 0) pageName = "flow"; } switch (pageName) { case "active": showActivePage(); break; case "cancel": showCancelPage(); break; case "draw": alert('参数错误') break; case "flow": showFlowPage(); break; default: showOrderPage(); break; } } $('#btn-cancel').unbind('click').on('click', function () { showCancelPage(); }) $('#btn-active').unbind('click').on('click', function () { // if (!checkEquip('active')) return; // showActivePage(); }) function showOrderPage() { if ($('.section-order').css('display') == 'none') { bindOrderBtn(); } else { $('.btn-order').unbind('click').on('click', function (event) { bindOrderBtn(); }) } function bindOrderBtn() { if (!compnt.lockClick()) { return; } unicom.showCapPage(null, null, 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() { //if (!compnt.lockClick()) { // return; //} 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 + "&F=" + unicom.query.F + "&page=active"; 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": showAlertDialog('cancelSuccess','您已成功退订该商品,退订次月生效', function() { showFlowPage(); }); //compnt.showAlert('退订成功').then(function(message) { // showFlowPage(); //}); break; case "7605": //应该是已经退订了吧,因此不需要在重复退订啦 //compnt.showAlert(response.errorInfo).then(function(message) { // showFlowPage(); //}); showAlertDialog('cancelFailure', response.errorInfo, function() { showFlowPage(); }); break; default: var prefix = ''; if (response.errorInfo.indexOf('退订失败') < 0) { prefix = '退订失败,'; } //compnt.showAlert(prefix + response.errorInfo); showAlertDialog('cancelFailure', 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).then(function(response) { compnt.hideLoading(); switch (response.resultCode) { case "0000": //订购成功!跳转到页面 unicom.saveUserInfo(); showFlowPage(); //compnt.showAlert('订购成功!').then(function() { // showFlowPage(); //}) //showAlertDialog('orderSuccess', '订购成功!', function() { // showFlowPage(); //}); return; case "0013": showAlertDialog('orderFailure','该号码归属省分2/3G暂未开通此产品!'); break; case "6611": showAlertDialog('orderFailure','错误代码(6611),' + '订购失败,请重试!'); break; case "6615": showAlertDialog('orderFailure', '订购失败,请确定用户套餐!'); break; case "6622": // 用户已订购过此产品!跳转到流量查页面 localStorage.setItem('message', '您已经订购了本产品~'); unicom.saveUserInfo(); showFlowPage(); break; default: showAlertDialog('orderFailure', response.errorInfo + ',订购失败,请确定用户套餐!'); break; } }).fail(function (error) { console.log(error); }); } function showAlertDialog(action, message, callback) { 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 = $('
'); var $dialog = $( '
' + '
' + '
' + message + '
' + '
' + '
确定
' + '
' + '
'); $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; callback && callback() } return $dialog; } /** * 查询用户剩余流量 */ function queryFlow() { var $container = $('.section-flow'); compnt.showLoading('处理中,请稍后...'); //return new Promise(function(resolve, reject) { var def = $.Deferred(); unicom.queryFlow().then(function(response) { compnt.hideLoading(); 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('本月剩余
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('隐藏>'); } else { $('.section-agr .scope').find('li').each(function(i, ele) { if (i >= 0) { $(ele).addClass('hidden'); } }) // $('.section-agr').find('.footer').html('更多适用范围>'); } });