You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
5.8 KiB
248 lines
5.8 KiB
// list//pages/group/index.js
|
|
import commonApi from "../../utils/https/common";
|
|
import util from "../../utils/util"
|
|
let timer = null,app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
showIngGroup:false,
|
|
pageNo:1,
|
|
isMore:true,
|
|
list:[],
|
|
hot:[],
|
|
ingGroup:{}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
|
|
commonApi.user_post("activity.groups/product_list",{
|
|
isHot:1,
|
|
page:1,
|
|
limit:10
|
|
}).then(res=>{
|
|
this.setData({
|
|
hot:res.data.data
|
|
})
|
|
})
|
|
this.getList()
|
|
},
|
|
getList:function(){
|
|
commonApi.user_post("activity.groups/product_list",{
|
|
isHot:0,
|
|
page:this.data.pageNo,
|
|
limit:10
|
|
}).then(res=>{
|
|
this.setData({
|
|
list:res.data.data
|
|
})
|
|
})
|
|
},
|
|
gotoDetail:function(e){
|
|
let item = e.currentTarget.dataset.item,that = this;
|
|
commonApi.user_post("activity.groups/is_join",{
|
|
id:item.id
|
|
}).then(res=>{
|
|
let isJoin = false;
|
|
if(res.data.length>0 && res.data[0].status==1){
|
|
// 已经参与了这个团购
|
|
res.data[0].gp_num = item.gp_num;
|
|
this.setData({
|
|
showIngGroup:true,
|
|
ingGroup:res.data
|
|
})
|
|
this.setTime();
|
|
}
|
|
else {
|
|
// 未参与该团购
|
|
// 售罄
|
|
if(item.left_stock_num<=0){
|
|
wx.showModal({
|
|
title:"提示",
|
|
content:"商品售罄是否进行原价购买",
|
|
success:function(res){
|
|
if(res.confirm){
|
|
// 去下单
|
|
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',
|
|
})
|
|
}
|
|
})
|
|
// that.goOrder(item)
|
|
}
|
|
}
|
|
})
|
|
return;
|
|
}
|
|
// 正常参团
|
|
else {
|
|
wx.navigateTo({
|
|
url: 'info/index?id='+item.id,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
setTime:function(){
|
|
let info = this.data.ingGroup;
|
|
if(!this.data.showIngGroup || info.length==0) {
|
|
if(timer){
|
|
clearTimeout(timer);
|
|
timer=null;
|
|
}
|
|
this.setData({
|
|
showIngGroup:false
|
|
})
|
|
return;
|
|
}
|
|
let time = info[0].over_time;
|
|
let overTime = new Date(time.replace(/-/g,'/')).getTime(),now = new Date().getTime();
|
|
if(overTime<=now){
|
|
info[0].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;
|
|
}
|
|
info[0].h=h;
|
|
info[0].m=m;
|
|
info[0].s=s;
|
|
}
|
|
this.setData({
|
|
ingGroup:info
|
|
})
|
|
timer = setTimeout(()=>{
|
|
this.setTime();
|
|
},1000)
|
|
},
|
|
goOrder:function(info){
|
|
commonApi._get('productfront/getProductInfo',{
|
|
productId:info.productId
|
|
}).then(res=>{
|
|
if(!res.data){
|
|
wx.showToast({
|
|
title:"该产品不存在或已下架",
|
|
icon:'none'
|
|
})
|
|
return;
|
|
}
|
|
let skuIndex = res.data.skuInfo.findIndex(item=>item.id==info.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.groupId = null;
|
|
app.globalData.discounts = 0;
|
|
wx.navigateTo({
|
|
url: '/pages/order/index',
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
if(this.data.ingGroup){
|
|
this.setTime();
|
|
}
|
|
},
|
|
hideGroup:function(){
|
|
this.setData({
|
|
showIngGroup:false
|
|
})
|
|
wx.navigateTo({
|
|
url: '/pages/group/info/index?id='+this.data.ingGroup[0].gp_product_id
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
if(timer){
|
|
clearTimeout(timer);
|
|
timer = null
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
this.getList()
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function (e) {
|
|
if(e.from=='button'){
|
|
return {
|
|
title: "我正在发起团购,快来参加吧", // 默认是小程序的名称(可以写slogan等)
|
|
path: "/pages/group/info/index?id="+this.data.ingGroup.gpInitiateId, // 默认是当前页面,必须是以‘/’开头的完整路径
|
|
imageUrl: this.data.ingGroup.headImg, //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
|
|
}
|
|
}
|
|
else {
|
|
return {
|
|
title: "团购专区", // 默认是小程序的名称(可以写slogan等)
|
|
path: "list/pages/group/index"
|
|
}
|
|
}
|
|
}
|
|
})
|