var token = '';
var tid = '';
var returnUrl = '';
var cityInfo = '';
var qs = parseQueryString(window.location.href);
$().ready(function() {
if (qs.returnUrl) {
returnUrl = qs.returnUrl;
}
if (qs.token) {
token = qs.token;
} else {
showMsg('未提供token!')
}
if (qs.name && qs.code) {
$('.city-name').text(qs.name).attr('data-code', qs.code);
}
getLoginInfo();
//头部切换公积金类型
switchingType();
});
//头部切换公积金类型
function switchingType() {
var btn = $("nav p");
btn.click(function () {
console.log(cityInfo)
if(cityInfo !='' && cityInfo){
window.location.href = './typeChoice.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : '');
}else{
showMsg('获取城市信息失败');
}
})
}
/**
* [showMsg 提示各种错误信息,3s后消失]
*/
function showMsg(msg) {
var msgBox = $('.alert-info');
msgBox.children('p').text(msg);
msgBox.show();
setTimeout(function() {
msgBox.hide();
}, 3000);
}
/**
* [showDialog 弹窗提示,传不同的参数提示不同的内容以及按钮的内容和点击之后的作用]
* failed 任务失败,点击关闭弹窗
* maintain 当前城市维护中,点击关闭弹窗
* timeout token过期,点击关闭页面
*/
function showDialog(type) {
var mask = $('.mask');
mask.show();
$('.dialog-wrapper input').val('确定');
$('.dialog-wrapper div').hide();
if (type === 'failed') {
$('.dialog-failed').show();
$('.mask').addClass('bg-white').siblings().hide();
} else if (type === 'maintain') {
$('.dialog-maintain').show();
} else if (type === 'timeout') {
$('.dialog-timeout').show();
$('.dialog-wrapper input').val('关闭').click(function() {
redirectToFailedReturnUrl(tid, 'failed', 1020, '无效的token, 会话不存在或已过期');
})
} else if (type === 'forget') {
var html = '如果您忘记密码,需前往' + qs.name+ '公积金官网
重置密码'
$('.dialog-forget').show();
$('.dialog-forget').find('p').html(html)
$('.dialog-wrapper input').val('立即前往').click(function() {
// redirectToFailedReturnUrl(tid, 'failed', 1020, '无效的token, 会话不存在或已过期');
})
}
}
/**
* [enableCommitButton 启用/禁用提交按钮]
* @param {Boolean} isEnableButton [是否启用提交按钮]
*/
function enableCommitButton(isEnableButton) {
var commitButton = $('#submitButton');
if (isEnableButton) {
commitButton.attr('disabled', false).removeClass('disable-commit').addClass('enable-commit');
} else {
commitButton.attr('disabled', true).removeClass('enable-commit').addClass('disable-commit');
}
}
/**
* [isInputReady 检查参数是否输入完毕]
* @return {Boolean} [参数是否输入完毕]
*/
function isInputReady() {
var isInputReady = true;
var activeID = $('.tab-tab-active').attr('data-id');
$('.tab-content [data-id="' + activeID + '"]')
.find('input')
.each(
function(index, item) {
if ($(item).val().trim() === '') {
isInputReady = false;
}
if (!$('.check').hasClass('check-active')) {
isInputReady = false;
}
})
return isInputReady;
}
/**
* [initEvent 初始化各种事件]
*/
function initEvent() {
var tabs = $('.tab-tab');
var activeID = $('.tab-tab-active').attr('data-id');
// tab页切换
tabs.click(function(event) {
var currItem = $(this);
var currId = currItem.attr('data-id');
$('.tab-tab[data-id="' + currId + '"]').addClass('tab-tab-active').siblings().removeClass('tab-tab-active');
$('.tab-content div[data-id=' + currId + ']').show().siblings().hide();
enableCommitButton(isInputReady());
})
// 监测用户输入来设置提交按钮的状态
$('.tab-content').on('keyup', function() {
enableCommitButton(isInputReady());
})
// 确定按钮点击事件
$('#closeMask').click(function(event) {
$('.mask').removeClass('bg-white').hide().siblings().show();
$('#tid').hide();
$('.alert-info').hide();
$('.loading-wrapper').hide();
})
// 解析协议checkBox选中/取消选中事件
$('.check').click(function() {
var currentItem = $(this);
if (currentItem.hasClass('check-active')) {
enableCommitButton(false);
currentItem.removeClass('check-active');
} else {
currentItem.addClass('check-active');
enableCommitButton(isInputReady());
}
})
// 提交按钮点击事件
$('#submitButton').click(function() {
if (isInputValid()) {
submitTask();
}
});
// 导航栏左上角退出H5的点击事件
$('#back').click(function() {
redirectToFailedReturnUrl(tid, 'failed', 1020, '退出公积金查询页');
})
}
/**
* [getLoginInfo 获取城市登录信息]
*/
function getLoginInfo() {
var regionCode = $('.city-name').attr('data-code');
$.ajax({
type: "GET",
url: BASEURL + 'city_list?type=fund&token=' + token + '®ionCode=' + regionCode + '&time=' + Math.round(Date.now() / 1000),
// url: '../../city_list?type=fund&token=' + token + '®ionCode=' + regionCode + '&time=' + Math.round(Date.now() / 1000),
contentType: 'application/json;charset=utf-8',
success: function(data) {
cityInfo = data;
console.log('data')
console.log(data)
return renderLoginInfo(data);
},
error: function(err) {
return showMsg('获取城市信息失败:' + JSON.stringify(err));
}
});
}
/**
* [renderLoginInfo 渲染城市登录信息]
* @param {[type]} cityInfo [城市登录信息]
*/
function renderLoginInfo(cityInfo) {
var tabWrapper = $('.tab-tab-wrapper');
var tabConWrapper = $('.tab-content');
var tabsHtmlStr = '';
var tabConHtmlStr = '';
$('.city-name').text(cityInfo.region).attr('data-code', cityInfo.regionCode);
// $('.choose-city a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
$('nav span a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
for (var index in cityInfo.loginTypes) {
var loginType = cityInfo.loginTypes[index];
if (index === '0') {
tabsHtmlStr += '
' + loginType.loginLabel + '
' + loginType.loginLabel + '
常见问题
"; var defaultTip = null; var defaultRegion = '北京'; var tipContent = tips.find(function(item, index) { if (item.region === defaultRegion) { defaultTip = item; } return item.region === region; }); if (!tipContent) { tipContent = defaultTip; // 默认北京 } tipContent = tipContent.tip; for (var list of tipContent) { tipStr += "" + list.title + "
"; if (list.content) { for (var tip of list.content) { tipStr += "" + tip + "
" } } } $('.tips').html(tipStr); } /** * [Process 任务进度显示] */ function Process(opt) { this.ele = opt.ele; this.rate = 0; this.afterStart = opt.afterStart; this.afterStop = opt.afterStop; this.timer = null; this.step = null; this._getInterval = function() { return Math.round((Math.random() * 100) + 300); }; this._getStep = function() { return Math.round(Math.random() * 3); }; } Process.prototype.start = function(rate) { this.rate = rate == undefined ? this.rate : rate; let _this = this; let interval = this._getInterval(); this.timer = setInterval(function() { interval = _this._getInterval(); _this.step = _this._getStep(); _this.afterStart && _this.afterStart.call(_this); }, interval); } Process.prototype.stop = function(rate) { this.rate = rate == undefined ? this.rate : rate; clearInterval(this.timer); this.afterStop && this.afterStop(); } var process = new Process({ ele: $('.process'), interval: 1000, afterStart: function() { this.rate += this.step; if (this.rate >= 97) { this.rate = 99; this.stop(this.rate); } this.ele.text(this.rate + '%'); window.sessionStorage.processRate = this.rate; }, afterStop: function() { this.ele.text(this.rate + '%'); window.sessionStorage.processRate = this.rate; } })