diff --git a/view/templates/index/wait_deliver_list.html b/view/templates/index/wait_deliver_list.html index c5e207c..e0d4b32 100644 --- a/view/templates/index/wait_deliver_list.html +++ b/view/templates/index/wait_deliver_list.html @@ -52,14 +52,8 @@ layui.use(['element', 'layer', 'util', 'table'], function(){ ,table = layui.table ,$ = layui.$; - //示例 - var endTime = new Date(2099,1,1).getTime() //假设为结束日期 - ,serverTime = new Date().getTime(); //假设为当前服务器时间,这里采用的是本地时间,实际使用一般是取服务端的 - - util.countdown(endTime, serverTime, function(date, serverTime, timer){ - var str = (date[0]*24 + date[1]) + ':' + date[2] + ':' + date[3]; - layui.$('#test').html('倒计时:'+ str); - }); + //清除翻页后上一页遗漏的定时器 + var intervalsMap = new Map(); util.event('lay-header-event', { menuLeft: function(othis){ @@ -104,7 +98,7 @@ layui.use(['element', 'layer', 'util', 'table'], function(){ ,title: '用户数据表' ,totalRow: false ,className:'deliver_remind_list_table_class' - ,limit:20 + ,limit:5 ,cols: [[ {field:'goods_name', title:'商品名称', templet: function(d){ @@ -116,7 +110,7 @@ layui.use(['element', 'layer', 'util', 'table'], function(){ }} ,{field:'pay_time', title:'销售时间/倒计时' ,templet: function(d){ - if(d.is_show_count_down == true) return ''; + if(d.is_show_count_down == true) return ''; return ''+d.pay_time+''; }} ,{field:'pay_amount', title:'支付金额(元)'} @@ -139,6 +133,12 @@ layui.use(['element', 'layer', 'util', 'table'], function(){ }; }, done: function(res, curr, count){ + //删除翻页遗漏的定时器,避免内存泄露 + for(let key of intervalsMap.keys()){ + clearInterval(intervalsMap.get(key)); + intervalsMap.delete(key) + } + var data = res.data; try { if(data == undefined || data.length<=0){ @@ -153,6 +153,13 @@ layui.use(['element', 'layer', 'util', 'table'], function(){ $('.admin-blank-table').show(); } + var countDownList = new Array(); + for(var i=0; i= countDownList.length) indexcount = 0; + if(indexcount>0 || countDownList.length == 1) firstCallBackEnd = true; + + if(indexcount>=0 && firstCallBackEnd){ + var countDownIndx = indexcount-1; + if(indexcount == 0) countDownIndx = countDownList.length-1; + var countDownId = '#count-down-time-'+countDownList[countDownIndx].order_sn; + var remainTimeStr = (date[0]*24 + date[1]) + ':' + date[2] + ':' + date[3]; + intervalsMap.set(countDownIndx, timer); + if(date[0]*24 == 0 && date[1] == 0 && date[2] == 0 && date[3] == 0) { + countDownList.splice(countDownIndx,1); + firstCallBackEnd = false; + } + layui.$(countDownId).html('倒计时:'+ remainTimeStr); + } + }); + } } } });