blob: 524b8c418c0a1bea9807d0728d12d6587373757c [file] [log] [blame]
var db = null;
var canCheck = false;
var wait = 5;
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
canCheck = false;
wait=5;
},
onDeviceReady: function() {
$.showLoading("加载中");
V1Bxy(function(ok, ret, err) {
if (ok) {
$.hideLoading();
if (ret.code == 200) {
$("#content").html(ret.page);
if (isEmpty(ret.signed) || ret.signed != 'yes') {
//$("#btn").show();
//app.checkTime();
//$("#content").css("bottom", "135px");
} else {
$("#unbtn").show();
$("#content").css("bottom", "10px");
}
} else {
if (ret.code == -1) {
$.alert(ret.msg, "提示", function() {
window.location = 'bindcard.html'
});
} else {
$.alert(ret.msg, "错误");
}
}
} else {
$.hideLoading();
$.alert("加载失败了:" + ret.status, "错误");
}
})
},
unAgreeXY: function(){
var cum = new auiDialog({});
var confirm = cum.alert({
title: "提示",
msg: '确定解除代扣协议吗?',
buttons: ['取消', '解除']
}, function(ret) {
if (ret.buttonIndex == 2) {
$.showLoading("正在请求");
var param = {}
V1UnSignbxy(param, function(ok, ret, err) {
if (ok) {
$.hideLoading();
if (ret.code == 200) {
window.localStorage.setItem("signed", ret.signed);
$.alert('解除成功', "提示", function() {
window.location = 'main.html'
});
} else {
$.alert(ret.msg, "错误");
}
} else {
$.hideLoading();
$.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
}
})
}
})
},
agreeXY: function() {
if(!canCheck){
return;
}
var agree = $("input[type=checkbox]:checked").val();
if (isEmpty(agree)) {
$.alert("请同意签约代扣协议", "提示");
return;
}
$.showLoading("正在请求");
var param = {
"agree": agree
}
V1Signbxy(param, function(ok, ret, err) {
if (ok) {
$.hideLoading();
if (ret.code == 200) {
window.localStorage.setItem("signed", ret.signed);
window.location = "main.html";
} else {
$.alert(ret.msg, "错误");
}
} else {
$.hideLoading();
$.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
}
})
},
checkTime: function(){
if (wait == 0) {
$("#signBtn").text("签约代扣协议");
$("#signBtn").addClass("aui-btn-info");
canCheck = true;
}else{
$("#signBtn").text(wait+"s 签约代扣协议");
wait--;
setTimeout(function() {
app.checkTime();
},1000)
}
}
};
app.initialize();