var $body = $('.yjk-body');
var d = dialog({contentType:'load', skin:'bk-popup'});
var userAgent = JSON.parse(window.localStorage.getItem(agentName));
var cache = window.localStorage.getItem("twoStep"+userAgent.uid);
var Request = GetRequest();
var going = Request["isContinue"];
//定义弹窗
function toast(msg){
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
}
$(function(){
//先判断是否有缓存
if(cache && going){
var cacheObj = JSON.parse(cache)
showPage(cacheObj)
}else if(cache){
dialog({
content: '
',
okValue: '继续',
cancelValue: '清空',
cancel: function () {
window.localStorage.removeItem("twoStep"+userAgent.uid)
showPage({})
},
ok: function() {
var cacheObj = JSON.parse(cache)
showPage(cacheObj)
}
}).showModal()
}else{
showPage({})
}
//显示页面
function showPage(data){
var html = template('msg_tmp',{data:data})
$body.html(html)
baseInfoInit()
}
})
//初始化
function baseInfoInit() {
var opt = {
preset: 'date',
theme: 'ios',
lang: 'zh',
minDate: new Date(1900, 01, 01)
}
$('#weddingDate').mobiscroll(opt);
$('#spouseBirthday').mobiscroll(opt);
//点击
$('#page2_next').bind('tap',function(){
commit(function(){
window.location.href = "yjk-step3.html"
})
})
$('#page2_submit').bind('tap',function(){
commit(function(){
window.location.href = "yjk-preview.html"
})
})
}
//保存数据到缓存
function commit(fun){
var params={}
params.weddingDate = $("#weddingDate").val();
params.spouseName = $("#spouseName").val();
params.spouseBirthday = $("#spouseBirthday").val();
params.spouseMobile = $("#spouseMobile").val();
if(validate(params)){
window.localStorage.setItem("twoStep"+userAgent.uid,JSON.stringify(params))
fun&&fun.call(this)
}
}
/*判断输入是否为合法的手机号码*/
function isphone(inputString){
var partten = /^[1][3578][0-9]{9}$/;
if(partten.test(inputString)){
return true;
}else{
return false;
}
}
//验证信息
function validate(data) {
if(data.spouseMobile){
if (!isphone(data.spouseMobile)) {
toast('手机号码格式不对')
return false;
}
}
return true;
}