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.query.ringid = ''; 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 showAlertDialog(message) { var $overlay = $('
'); var $dialog = $( '
' + '
' + '
' + '
' + ' ' + '
' + '
' + '
确定
' + '
' + '
'); $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; $('body').css('overflow', 'auto') } $('body').css('overflow', 'hidden') return $dialog; } function showPlayerDialog(src, poster) { var $dialog = $( '
' + '
' + '
' + ' ' + '
' + '
'); $dialog.appendTo($(document.body)) $dialog.find('.close').unbind('click').on('click', function () { $dialog.close() }) $dialog.close = function () { $dialog.remove(); $dialog = null; $('body').css('overflow', 'auto') } $('body').css('overflow', 'hidden') var video = document.getElementById("video1"); video.play(); return $dialog; } 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("draw.html") >= 0) pageName = "draw"; 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": showDrawPage(); break; case "flow": showFlowPage(); break; default: showOrderPage(); break; } } $('#btn-cancel').unbind('click').on('click', function () { showCancelPage(); }) function showOrderPage(backPage) { if (location.href.indexOf('/index') < 0) { if (backPage == null || backPage == '') { backPage = 'index.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().then(function (data) { compnt.unlockClick(); order(data.userid, data.token, data.usermob, unicom.query.ringid); }).fail(function(response) { compnt.unlockClick(); }) }) $('.rbt-item').find('.status').on('click', function(obj) { if (unicom.query.ringid == $(obj.currentTarget).attr('ringid')) { return; } $('.rbt-item').find('.status').each(function(i, item) { if ($(item).hasClass('status-checked')) { $(item).removeClass('status-checked').addClass('status-unchecked') } else { $(item).removeClass('status-unchecked').addClass('status-checked') unicom.query.ringid = $(item).attr('ringid') } }); }) $('.rbt-item').find('.rbt-cover').each(function(i, item) { $(item).on('click', function(obj) { var src = $(obj.currentTarget).attr('src'); var poster = $(obj.currentTarget).attr('poster'); showPlayerDialog(src, poster); }) }) } 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 = $('.sms-form'); $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('退订成功');//.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 order(userid, token, usermob, ringid) { 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": // 用户已订购过此产品!跳转到流量查页面 // localStorage.setItem('message', '您已经订购了本产品~'); compnt.showAlert('您已经订购了本产品~') unicom.saveUserInfo(); break; default: compnt.showAlert(response.errorInfo + ',订购失败,请确定用户套餐!'); break; } }).fail(function (error) { compnt.hideLoading(); console.log(error); }); }