// pages/user/pdd/index.js import productApi from "../../../utils/https/common"; let timer = null,app = getApp(); Page({ /** * 页面的初始数据 */ data: { type:1, list:[], over:[] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getList(); }, changeType:function(e){ let type = e.currentTarget.dataset.type; if(this.data.type==type) return; this.setData({ type:type }) }, gotoDetail:function(e){ let data = e.currentTarget.dataset.item; if(this.data.type==2){ this.goOrder(e); return; } wx.navigateTo({ url:"/pages/group/info/index?id="+data.gp_product_id }) }, getList:function(){ productApi.user_post("activity.groups/my_teams",{ limit:100, status:1, is_team:1 }).then(res=>{ this.setData({ list:{ launchList:res.data.data } }) productApi.user_post("activity.groups/my_teams",{ limit:100, status:1, is_team:0 }).then(r=>{ this.setData({ list:{ launchList:res.data.data, joinList:r.data.data } }) this.setTime(); timer = setInterval(()=>{ this.setTime() },1000) }) }) productApi.user_post("activity.groups/my_teams",{ limit:100, status:2, is_team:1 }).then(res=>{ productApi.user_post("activity.groups/my_teams",{ limit:100, status:2, is_team:0 }).then(r=>{ this.setData({ over:{ launchList:res.data.data, joinList:r.data.data } }) }) }) }, setTime:function(){ let list = this.data.list,now = new Date().getTime(); for(let i in list){ list[i].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; console.log(item); productApi._get('productfront/getProductInfo',{ productId:item.productId }).then(res=>{ if(!res.data){ wx.showToast({ title:"该产品不存在或已下架", icon:'none' }) return; } let skuIndex = res.data.skuInfo.findIndex(sku=>sku.id==item.skuId); if(skuIndex==-1) { wx.showToast({ title:"该产品规格不存在", icon:'none' }) return; } let sku = res.data.skuInfo[skuIndex]; app.globalData.shoppingCart=[{ baseInfo:res.data.baseInfo, modelInfo:sku.modelInfo, skuInfo:sku, productNum:1 }]; app.globalData.kjOrderId = item.id || null; app.globalData.discounts = 0; wx.navigateTo({ url: '/pages/order/index', }) }) }, goOrder:function(e){ wx.navigateTo({ url: '/pages/info/orderInfo/index?id='+e.currentTarget.dataset.item.gpChildOrderNo, }) }, refund(e){ wx.showModal({ title:"提示", content:"确定申请退款吗?", success:function(res){ if(res.confirm){ // todo productApi.user_post({}) } } }) }, gotoPdd:function(){ let page = getCurrentPages(); if(page[page.length-2] && page[page.length-2].route && page[page.length-2].route.indexOf('pages/group/index')!=-1){ // 如果是从专题页列表来的 那么直接返回 wx.navigateBack() } else { wx.navigateTo({ url: '/pages/group/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 () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })