const util = require("../../utils/util"); Component({ /** * 组件的属性列表 util.toHHmmss(res.data.endTime,); */ properties: { special:{ type: Boolean, value: false }, titleImgUrl:{ type:String, value:"", }, isShowCount:{ type: Boolean, value: false }, obj:{ type:Object, value:{} } }, /** * 组件的初始数据 */ data: { setIntervalLsit:[] }, attached: function () { let this_ =this let arr = [] let tempLsit = [] // 处理首页定时 if (this_.properties.obj.couponList!=null&&this_.properties.obj.couponList.length>0){ //限时抢购 倒计时 this_.properties.obj.couponList.map((item,index)=>{//初次渲染 if (item.targetAd==2){ let tempObj = {} let beginTime = item.beginTime;//开始时间 let endTime = item.endTime;//结束时间 let present = new Date().getTime()//当前时间 let textTime = item.beginTime >= present?"距开始":"距结束" tempObj={ value: item.beginTime >= present ? beginTime - present : endTime - present, valueText: item.beginTime >= present ? util.toHHmmss(beginTime - present) : util.toHHmmss(endTime - present), // vaFlag: tempObj.value<=0?true:false,//活动是否结束 index:index, interval:"" , beginTime: beginTime,//开始时间 endTime: endTime,//开始时间 textTime: textTime } arr.push(tempObj) this_.setData({ setIntervalLsit: arr }) } }) } tempLsit =this_.data.setIntervalLsit tempLsit.map((item,index)=>{//再次渲染 item.interval = setInterval(function(){ let present = new Date().getTime()//当前时间 if(item.value<=1){ clearInterval(item.interval) item.vaFlag = true,//活动是否结束 console.log(item.value, "活动已经结束") }else{ let tempTime = item.beginTime >= present ? item.beginTime - present : item.endTime - present // console.log(tempTime, "presents") item.value = tempTime, item.valueText = util.toHHmmss(tempTime - 1000) item.textTime = item.beginTime >= present ? "距开始" : "距结束", item.vaFlag= item.value <= 0 ? true : false,//活动是否结束 this_.setData({ setIntervalLsit: tempLsit }) } },1000) }) // 处理首页定时 }, detached: function () { this.data.setIntervalLsit.map(item=>{ clearInterval(item.interval) }) console.log("88888") // 在组件实例被从页面节点树移除时执行 ; }, /** * 组件的方法列表 */ methods: { lookAll(){ tt.navigateTo({ url: `/${this.properties.obj.weappPath}`, }) }, goDetail(e){ console.log(e.currentTarget.dataset) let couponChannelId = e.currentTarget.dataset.id let couponId = e.currentTarget.dataset.couponid let type = e.currentTarget.dataset.type if (type==9){ tt.navigateTo({ url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${couponChannelId}&couponId=${couponId}`, }) }else{ tt.navigateTo({ url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`, }) } }, gotoTopic(e) { let id = e.currentTarget.dataset.id tt.navigateTo({ url: `/pages/topicDetail/index?id=${id}` }) }, } })