
$(function () {
    // IOS 微信浏览器开启点击事件
    $("body>*").bind("click",function(){});
    //修复移动端 date 不支持placeholder
    $('#scan-integral input[type="date"]').focus(function () {
        $(this).addClass('full')
    });
     
    /*--------------------签到弹出框初始化-------------------------------------*/
    $('.popup-modal').magnificPopup({
        type:'inline',
        midClick: true
    });
 
})


 

/*-------------------校验表单提示错误框------------------------------------*/
function messageModal(message) {
    setTimeout(() => { 
    $.magnificPopup.open({
        items: {
            src: '<div id="popup" class="white-popup"><h1></h1><div class="message--wrap"><p>' + message + '</p></div><div class="confirm-button btn">确认</div> </div>', // can be a HTML string, jQuery object, or CSS selector
            type: 'inline'
        }
     }); 
    }, 20);
    $(document).on('click', '#popup .confirm-button', function () { 
        $.magnificPopup.close();
    })
}

function messageCheckModal(message,icon,callback,button) {
    var title="";
    if(icon=="check-success") title="有缘分"
    else if(icon=="check-fail") title="很遗憾"
    // if(icon=="check-un") title="无法识别" 
    var nocoverUrl="";
    if(icon=="check-fail") nocoverUrl="<a style='color: #CBCBCB;font-size: 24px;text-decoration-line: underline;' href='nocover.html'>点击进入定制专区</a>"

    setTimeout(() => { 
    $.magnificPopup.open({
        items: {
            src: '<div id="popup" class="white-popup"><h2 class="'+icon+'"></h2><h3>'+title+'</h3>'
            +'<div class="message--wrap"><p>' + message + '</p></div>'
            +'<div class="confirm-button btn">'+button+'</div><div style="text-align:center;margin-top:5px">'+nocoverUrl+'</div></div>', // can be a HTML string, jQuery object, or CSS selector
            type: 'inline'
        }
     }); 
    }, 20);
    $(document).on('click', '#popup .confirm-button', function () { 
        $.magnificPopup.close();
        if(callback!=null) callback();
    })
}

function messageCheckFailModal(message,callback,address) {
  
    var nocoverUrl ="<img src='../auto/img/icon/edit.png'/><a style='color: #CBCBCB;font-size: 24px;text-decoration-line: underline;' href='nocover.html?address="+address+"'>点击进入定制专区</a>"

    setTimeout(() => { 
    $.magnificPopup.open({
        items: {
            src: '<div id="popup" class="white-popup"><h2 class="check-fail"></h2><h3>很遗憾</h3>'
            +'<div class="message--wrap"><p>' + message + '</p></div>'
            +'<div class="confirm-button btn">更换地址</div><div style="text-align:center;margin-top:5px">'+nocoverUrl+'</div></div>', // can be a HTML string, jQuery object, or CSS selector
            type: 'inline'
        }
     }); 
    }, 20);
    $(document).on('click', '#popup .confirm-button', function () { 
        $.magnificPopup.close();
        if(callback!=null) callback();
    })
}

function messageNoCoverModal(message,callback) { 

    setTimeout(() => { 
    $.magnificPopup.open({
        items: {
            src: '<div id="popup" class="white-popup"><h2 class="nocover"></h2><h3>提交成功</h3><div class="message--wrap" style="text-align: center"><p>' + message + '</p>'+
            '<img src="../auto/img/icon/qr.png" style="width:160px"/>'+'</div><div class="confirm-button btn">确定</div> </div>', // can be a HTML string, jQuery object, or CSS selector
            type: 'inline'
        }
     }); 
    }, 20);
    $(document).on('click', '#popup .confirm-button', function () { 
        $.magnificPopup.close();
        if(callback!=null) callback();
    })
}

function confirmCancel(message, callbackOK,callbackCancel) {
    setTimeout(() => { 
    $.magnificPopup.open({
        items: {
            src: '<div id="popup" class="white-popup"><h1></h1><div class="message--wrap"><p>' + message + '</p></div><div class="confirm-button-box"><div class="confirm-button btn btnOK">下一步</div> <div class="confirm-button btn btnCancel">暂不购买</div></div></div>', // can be a HTML string, jQuery object, or CSS selector
            type: 'inline'
        }
    });
   }, 20);

    $(document).on('click', '#popup .btnOK', function () { 
            $.magnificPopup.close(); callbackOK();
               $(document).off('click', '#popup .confirm-button')
    });
    $(document).on('click', '#popup .btnCancel', function () { 
        $.magnificPopup.close();
        callbackCancel();
        $(document).off('click', '#popup .confirm-button')
    })
}
 

/*----------------------获取今天日期-----------------------------------------*/
function getCurrenTime() {
    var date = new Date();
    var getMonth=date.getMonth()+1
    if(date.getMonth()<10){
        getMonth='0'+getMonth
    }
    var dateString = date.getFullYear()+"-"+getMonth+"-"+date.getDate();
    return dateString
}

/*--------------------发送短信验证码--------------------------------*/
var countdown=60;
function sendEmail(obj) {

    setTime(obj)
}
function setTime(obj) { //发送验证码倒计时
    if (countdown == 0) {
        obj.attr('disabled',false);
        obj.removeClass('gray');
        obj.val("点击获取");
        countdown = 60;
        return;
    } else {
        obj.attr('disabled',true);
        obj.addClass('gray')
        obj.val("重新发送(" + countdown + ")");
        countdown--;
    }
    setTimeout(function(){setTime(obj)},1000);
}



