import * as compnt from "../../../../public/js/compnt.js"; import * as unicom from "../../../../public/js/unicom.js"; import "../scss/main.scss"; var douyinProductId = "2018072301"; var douyinPreProductId = "2020031101"; var baiduProductId = "2020021201"; var baiduPreProductId = "2020071301"; $(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 != '') { showDialogMessage(message); localStorage.removeItem('message'); } compnt.showLoading(); unicom.init().then(function(response) { compnt.hideLoading(); unicom.product = unicom.products[douyinProductId]; unicom.fesname = response.festival; unicom.loadUserInfo(); if (location.href.indexOf("index.html") >= 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) { if (pageName == null) { if (location.href.indexOf("index.html") >= 0) pageName = "order"; if (location.href.indexOf("cancel.html") >= 0) pageName = "cancel"; } switch (pageName) { case "cancel": showCancelPage(); break; default: showOrderPage(); break; } } $('#gotoCancel').unbind('click').on('click', function () { if ($douyinItem.hasClass('active')) { unicom.product = unicom.products[douyinProductId]; } else { unicom.product = unicom.products[baiduProductId]; } showCancelPage(unicom.product.productid); }) $('.more .text').unbind('click').on('click', function() { showDialogAgr() }) var $douyinItem = $($('.products').find('.item')[0]); var $baiduItem = $($('.products').find('.item')[1]); $douyinItem.unbind('click').on('click', function(e) { $douyinItem.addClass('active'); $baiduItem.removeClass('active'); unicom.product = unicom.products[douyinProductId]; // console.log(unicom.product); }) $baiduItem.unbind('click').on('click', function() { $douyinItem.removeClass('active'); $baiduItem.addClass('active'); unicom.product = unicom.products[baiduProductId]; // console.log(unicom.product); }) function showOrderPage(backPage) { if (location.href.indexOf('index.html') < 0 && location.href.indexOf('15/20200') < 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; } if ($douyinItem.hasClass('active')) { unicom.product = unicom.products[douyinProductId]; } else { unicom.product = unicom.products[baiduProductId]; } unicom.showCapPage(null, null, false, false, true, null).then(function (data) { compnt.unlockClick(); order(data.userid, data.token, data.usermob); }).fail(function(response) { compnt.unlockClick(); }) }) $('.modify').unbind('click').on('click', function (event) { if (!compnt.lockClick()) { return; } if ($douyinItem.hasClass('active')) { unicom.product = unicom.products[douyinPreProductId]; } else { unicom.product = unicom.products[baiduPreProductId]; } unicom.showCapPage(null, null, false, false, true, null).then(function (data) { compnt.unlockClick(); order(data.userid, data.token, data.usermob); }).fail(function(response) { compnt.unlockClick(); }) }) } function showCancelPage(productid) { if (location.href.indexOf("cancel.html") < 0) { window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou + "&productid=" + productid; return; } unicom.product = unicom.products[unicom.query.productid] var $container = $('.sms-form').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.choiceCancel().done(function(response) { compnt.hideLoading(); switch (response.resultCode) { case "0000": showDialogMessage('退订成功'); break; case "7605": //应该是已经退订了吧,因此不需要在重复退订啦 showDialogMessage(response.errorInfo); break; default: var prefix = ''; if (response.errorInfo.indexOf('退订失败') < 0) { prefix = '退订失败,'; } showDialogMessage(prefix + response.errorInfo); break; } }).fail(function(data) { compnt.hideLoading(); }) }).fail(function(data) { compnt.hideLoading(); }) }) window.scrollTo(0, 0) } /** * 订购 */ function order(userid, token, usermob) { compnt.showLoading('处理中,请稍后...'); unicom.choiceOrder(userid, token, usermob).done(function(response) { compnt.hideLoading(); switch (response.resultCode) { case "0000": //订购成功!跳转到领取会员页面 unicom.saveUserInfo(); showDialogMessage('订购成功'); return; case "0013": showDialogMessage('该号码归属省分2/3G暂未开通此产品!'); break; case "6611": showDialogMessage('错误代码(6611),订购失败,请重试!'); break; case "6615": showDialogMessage('订购失败,请确定用户套餐!'); break; case "6622": // 用户已订购过此产品!跳转到流量查页面 unicom.saveUserInfo(); break; //case "1078": //{"resultCode":"1078","errorInfo":"预约失败,请直接订购此产品!"} // showDialogMessage('预约变更失败,请先订购本产品!'); // showDialogMessage('预约变更失败,请先订购本产品!'); // break; //case "1077": //{"resultCode":"1077","errorInfo":"订购失败,您已订购过二选一产品,请预约订购!"} // showDialogMessage('订购失败,您已订购过二选一产品,请预约变更!'); // break; //case "1079": // {"resultCode":"1079","errorInfo":"预约失败,请先订购百度产品!"} // showDialogMessage('预约变更失败,与当前生效的专属流量流量相同!'); // break; default: showDialogMessage(response.errorInfo); break; } }).fail(function (error) { compnt.hideLoading(); console.log(error); }); } function showDialogMessage(message) { var replaceString = ''; if (unicom.product.productid == baiduPreProductId || unicom.product.productid == douyinPreProductId) { message = message.replace('订购失败', '预约变更失败') .replace('订购成功', '预约变更成功'); } var $overlay = $('
') var $dialog = $( '
' + '
' + message + '
' + '
' + '
' + '
' + '
'); $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; } function showDialogAgr() { var $overlay = $('
') var $dialog = $( '
' + '
' + '
' + '
' + '
' + ' ' + '
'); $overlay.appendTo($(document.body)) $dialog.appendTo($(document.body)) $dialog.find('.btn').on('click', function () { $overlay.remove(); $dialog.remove(); $dialog = null; }) $dialog.find('.close').on('click', function () { $overlay.remove(); $dialog.remove(); $dialog = null; }) $dialog.close = function () { $overlay.remove(); $dialog.remove(); $dialog = null; } return $dialog; }