zoukankan      html  css  js  c++  java
  • 15分XX秒后订单自动关闭(倒计时)

    //订单记录
    function get_order(){
    
    //请求订单ajax方法
    XX.send_api("method",{data},function(){
    var date = Math.round(new Date() / 1000);          //当前时间戳,单位:时间戳
    var t = 15-parseInt((date - data.ctime)/60);     //ctime为订单创建的时间戳,t为订单待支付的剩下的时间,单位:分钟
    var s = 60 - parseInt(((new Date()/1000) - data.ctime)%60) //剩余支付时间的秒数
    t为订单待支付的剩下的时间
    //ajax请求成功 if(msg.message.code == 0){ 
    //请求成功执行的方法体     
        … 
    //执行倒计时的方法 
    daojishi();
    if (s == 60) {
        s = 0;
        t = t + 1;
    }else if (t > 0) {//如果仍然有剩余的待支付时间,显示剩余时间 
    
        // $(".time").text(t);
        // $(".second").text(s);
        $(".time").text(t>=10?t:"0"+t);
        $(".second").text(s>=10?s:"0"+s);
    } else{
     $(".code").text("订单已关闭"); //置灰支付按钮 
    $(".submit").addClass("outdate");
     $(".submit").attr("disabled",true);      
     }     
    }   
    }) 
    }
    
    //定义倒计时方法
    function daojishi() {
        var djs = setInterval(function () {
            t = 14 - parseInt(((new Date() / 1000) - data.ctime) / 60);     //剩余分钟数
            var s = 60 - parseInt(((new Date() / 1000) - data.ctime) % 60); //剩余秒数
    
            if (s == 60) {
                s = 0;
                t = t + 1;
            }
    
            if (t <= 0 && s<=0) {
                clearInterval(djs);
                FFD.send_api("order/close_line_order", {order_id: data.id}, function () {
                    $(".submit").addClass("outdate");
                    $(".submit").attr("disabled", true);
                })
                return false;
            }
            $(".time").text(t>=10?t:"0"+t);
            $(".second").text(s>=10?s:"0"+s);
    
        }, 1000);
    }
    
     
  • 相关阅读:
    P1121 环状最大两段子段和
    无题
    cdoj 1485 柱爷搞子串 sam treap
    自然数幂和
    Gym 100341C AVL Trees NTT
    线性筛分解质因子
    codeforces 366 Ant Man dp
    UVALive 6914 Maze Mayhem 轮廓线dp
    hdu 5790 Prefix 字典树 主席树
    莫比乌斯反演个人小结
  • 原文地址:https://www.cnblogs.com/JaniceDong/p/9116363.html
Copyright © 2011-2022 走看看