var e = getApp(), i = e.request, a = e.globalData.setting, os=a,ut = require("../../../utils/util.js"); var regeneratorRuntime = require('../../../utils/runtime.js'); Page({ data: { url: a.imghost, killtime: null, currentPage: 1, goodlist: null, type:1, timer:null, ismore:1, isshow:0, iurl: os.imghost, }, onShow: function(t) { wx.setNavigationBarTitle({ title: "天天拼单",}) this.data.is_timer=1; this.data.currentPage=1; this.setData({goodlist:null}); var th=this; this.requestSalelist(); //设置全局定时器 th.data.timer=setInterval(function () { th.countDown(); },1000); }, onHide:function(){ //--清理定时器-- clearInterval(this.timer); this.setData({isshow:0}); }, //---小于10的格式化函数---- timeFormat(param) { return param < 10 ? '0' + param : param; }, //----倒计时函数----- countDown() { if(!this.data.goodlist) return false; var th=this; // 获取当前时间,同时得到活动结束时间数组 var newTime = ut.gettimestamp(); var endTimeList = this.data.goodlist; // 对结束时间进行处理渲染到页面 for (var i = 0; i < endTimeList.length;i++){ var o = endTimeList[i]; var endTime = o.end_time; if(th.data.type==0) endTime = o.start_time; let obj = null; // 如果活动未结束,对时间进行处理 if (endTime - newTime > 0){ let time = (endTime - newTime); // 获取天、时、分、秒 let day = parseInt(time / (60 * 60 * 24)); let hou = parseInt(time % (60 * 60 * 24) / 3600); let min = parseInt(time % (60 * 60 * 24) % 3600 / 60); let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60); obj = { day: this.timeFormat(day), hou: this.timeFormat(hou), min: this.timeFormat(min), sec: this.timeFormat(sec),hide:1 } }else{ //活动已结束,全部设置为'00' obj = { day: '00', hou: '00', min: '00', sec: '00' } } var txt ="goodlist["+i+"].djs"; th.setData({ [txt]: obj}); } }, //读取数据 async requestSalelist(){ if(!this.data.ismore) return false; var e = this,th=e,i = "/api/weshop/teamlist/pageteam/"+th.data.type+"?page=" + e.data.currentPage; var plist=null,alllist=th.data.goodlist; if(!alllist) alllist=[]; await getApp().request.promiseGet(i, {isShowLoading:1,data:{store_id:os.stoid,is_end:0,is_show:1}} ).then(res=>{ plist=res.data.data.pageData; }); if(plist.length<=0){ getApp().showWarning("没有更多数据"); th.data.ismore=0; } //--循环读取接口--- for(var i=0;i{ if(res.data.code==0){ plist[i].status=1; if(res.data.data<=0) plist[i].status=3; } }); alllist.push(plist[i]); } e.data.currentPage++; th.setData({goodlist:alllist,isshow:1}); }, onPullDownRefresh: function() { this.reloadGoodList(); }, reloadGoodList: function() { this.data.goodlist = null, this.data.currentPage = 1, this.requestSalelist(); }, onReachBottom: function() { this.requestSalelist(); }, //点击tab事件 tip:function(e){ var a=e.currentTarget.dataset.ty,th=this; th.data.ismore=1;th.data.currentPage=1; this.setData({type:a,goodlist:null}); this.reloadGoodList(); }, //图片失败,默认图片 bind_bnerr2: function (e) { var _errImg = e.target.dataset.errorimg; var val = e.target.dataset.val; if(val!="/public/images/default_goods_image_240.gif"){ var _errObj = {}; _errObj[_errImg] = "/public/images/default_goods_image_240.gif"; this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; } } });