// pages/user/pdd/index.js import productApi from "../../../utils/https/common"; import util from "../../../utils/util" let timer = null,app = getApp(); Page({ /** * 页面的初始数据 */ data: { type:1, list:[], page:1, total:1 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getList() }, changeType:function(e){ let type = e.currentTarget.dataset.type; if(this.data.type==type) return; this.setData({ type:type, total:1, page:1, list:[] }) this.getList(); }, gotoDetail:function(e){ let data = e.currentTarget.dataset.item; if(this.data.type==2 && data.flag!='expired'){ if(data.flag=='end'){ this.goOrder(e); } else { this.goProduct(e) } return; } wx.navigateTo({ url:"../info/index?id="+data.act_product_id+"&userid="+data.user_id }) }, getList:function(){ if(this.data.list.length>=this.data.total) return; productApi.user_post("order/my_haggle_list?limit=10&page="+this.data.page+"&status="+this.data.type,{}).then(res=>{ this.setData({ list:this.data.list.concat(res.data.data), page:this.data.page+1, total:res.data.total }) if(this.data.type==1){ this.setTime(); if(timer){ clearInterval(timer); } timer = setInterval(()=>{ this.setTime() },1000) } }) }, setTime:function(){ let list = this.data.list,now = new Date().getTime(); list.map(item=>{ let overTime = item.over_time; overTime = new Date(overTime.replace(/-/g,'/')).getTime(); if(overTime<=now){ item.isOver=true; } else { let t = (overTime - now)/1000; let h = Math.floor(t/(60*60)); t = t - h * 60*60; let m = Math.floor(t/60),s=Math.floor(t-m*60); if(h<10) { h="0"+h; } if(m<10) { m="0"+m; } if(s<10) { s="0"+s; } item.timeText=[h,m,s].join(" : "); } }) this.setData({ list:list }) }, goProduct:function(e){ let item = e.currentTarget.dataset.item; app.globalData.kjId = item.id; app.globalData.couponInfo = null; util.goKjOrder(item).then(product=>{ if(item.type=='post'){ app.globalData.postProduct = product; wx.navigateTo({ url: '/pages/order/postOrder/index', }) } else if(item.type=='ticket' || item.type=='scene'){ app.globalData.product = product[0]; wx.navigateTo({ url: '/pages/order/scene/index', }) } }) }, goOrder:function(e){ productApi.user_post("order/query",{ order_id:e.currentTarget.dataset.item.order_id, }).then(res=>{ util.gotoOrder(res.data) }) }, gotoPdd:function(){ let page = getCurrentPages(); if(page[page.length-2] && page[page.length-2].route && page[page.length-2].route.indexOf('pages/kj/index')!=-1){ // 如果是从专题页列表来的 那么直接返回 wx.navigateBack({ delta: -1, }) } else { wx.navigateTo({ url: '/pages/kj/index', }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if(this.data.list.length>0){ this.setTime(); timer = setInterval(()=>{ this.setTime() },1000) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { if(timer){ clearInterval(timer); timer = null; } }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })