// pages/list/sale/index.js import commonApi from "../../../utils/https/common"; import util from "../../../utils/util"; let timer; Page({ /** * 页面的初始数据 */ data: { type:0, service:["act/fast_sale_now","act/fast_next_sale_now","act/fast_next_days_sale_now"], list:[], moreFlag:true, t:0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, getList:function(){ if(!this.data.moreFlag) return; if(this.data.type==1){ commonApi._post('product/get_product_by_tag',{ limit:10, offset:this.data.list.length, tag_id:91 }).then(res=>{ this.setData({ list:this.data.list.concat(res.data.list), moreFlag:res.data.list.length>=10 }) }) return } commonApi._post(this.data.service[this.data.type],{ limit:10, offset:this.data.list.length }).then(res=>{ if(res.data.length<10){ this.setData({ moreFlag:false }) } res.data.map(item=>{ item.start_time_text = item.start_time?item.start_time.split(" ")[1]:''; }) this.setData({ list:this.data.list.concat(res.data) }) if(this.data.list.length==0 && this.data.t==0){ this.setData({ type:1, moreFlag:true, list:[], t:1 }) this.getList() } else { this.daojishi() } }) }, daojishi:function(){ // 只有正在疯抢的才需要倒计时 if(this.data.type!=0) return; let list = this.data.list,now = new Date().getTime(); list.map(item=>{ let end_time = new Date(item.end_time.replace(/-/g,'/')).getTime(),times = end_time - now; // 活动结束了 if(times<=0) { item.is_end = 1; } else { // let day = Math.floor(times / (1000 * 60 * 60 * 24)),times = times - day * 1000 * 60 * 60 *24; let hour = Math.floor(times / (1000 * 60 * 60)),minute = Math.floor((times - hour * 1000 * 60 * 60) / (60 * 1000)); let second=Math.round((times - hour * 1000 * 60 * 60 - minute * 60 * 1000) / 1000); item.day = Math.floor(hour/24); hour = hour%24; item.hour = hour>=10?hour:("0"+hour); item.minute = minute>=10?minute:("0"+minute); item.second = second>=10?second:("0"+second); } }) this.setData({ list:list }) timer = setTimeout(()=>{ this.daojishi() },1000) }, gotoDetail:function(e){ // if(this.data.type!=0) return; let item = e.currentTarget.dataset.item; if(item.sku.product){ util.gotoDetail(item.sku.product) } console.log(item); }, changeType:function(e){ this.setData({ type:e.currentTarget.dataset.type, list:[], moreFlag:true }) clearTimeout(timer); timer = null; this.getList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getList() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { clearTimeout(timer); timer = null; }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })