//订单记录
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);
}