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.
 

312 lines
8.1 KiB

// pages/info/groupInfo/index.js
import commonApi from "../../../utils/https/common";
let timer = null,app = getApp(),timer2=null;
import util from "../../../utils/util"
Page({
/**
* 页面的初始数据
*/
data: {
info:null,
list:[],
hot:[],
id:null,
isFollow:true,
showRuleFlag:false,
isOn:false,
myIngList:{}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id:options.id
})
commonApi.user_post('activity.groups/detail?id='+options.id+'&team_id='+options.team_id,{
id:options.id,
team_id:options.team_id
}).then(res=>{
this.setData({
info:res.data.detail,
hot:res.data.hotProductList
})
if(res.data.self_team.status==-1){
this.setData({
isOn:false
})
commonApi.user_post("activity.groups/get_teams?limit=100&id="+options.id,{
id:options.id,
limit:10
}).then(res=>{
this.setData({
list:res.data.data
})
this.setListTime();
})
}
else {
this.setData({
isOn:true,
myIngList:res.data.self_team
})
this.setTime();
}
})
},
// 我的团购结束倒计时
setTime:function(){
let myIngList = this.data.myIngList,time = myIngList.team_list[0].over_time;
if(myIngList.isOver){
if(timer2){
clearTimeout(timer2);
timer2 = null;
}
return;
}
let overTime = new Date(time.replace(/-/g,'/')).getTime(),now = new Date().getTime();
if(overTime<=now){
myIngList.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;
}
myIngList.h=h;
myIngList.m=m;
myIngList.s=s;
}
this.setData({
myIngList:myIngList
})
timer2 = setTimeout(()=>{
this.setTime()
},1000)
},
// 列表倒计时
setListTime:function(){
let list = this.data.list,now = new Date();
list.map(item=>{
let t = item.over_time;
t = new Date(t.replace(/-/g,'/')).getTime() - now;
if(t<=0) {
item.isEnd = true;
}
else {
let h = Math.floor(t / 3600000),m = Math.floor((t - h * 3600000)/60000),s = Math.floor((t - h * 3600000 - m * 60000)/1000);
item.h = h<10?('0'+h):h;
item.m = m<10?('0'+m):m;
item.s = s<10?('0'+s):s;
}
})
this.setData({
list:list
})
if(timer){
clearTimeout(timer);
}
timer = setTimeout(()=>{
this.setListTime()
},1000)
},
// 修改当前详情页id
gotoDetail:function(e){
clearTimeout(timer);
timer = null;
wx.redirectTo({
url: '/pages/info/groupInfo/index?id='+e.currentTarget.dataset.id
})
},
// 发起团购
startGroup:function(){
util.goKjOrder(this.data.info).then(product=>{
product.map(item=>{
item.productNum = this.data.info.purchase_quantity;
item.sku.event_price = this.data.info.event_price;
item.maxNum = this.data.info.purchase_quantity;
})
app.globalData.gp_id = this.data.info.id;
if(this.data.info.type=='post'){
app.globalData.postProduct = product;
wx.navigateTo({
url: '/pages/order/postOrder/index',
})
}
else if(this.data.info.type=='ticket' || this.data.info.type=='scene'){
app.globalData.product = product[0];
wx.navigateTo({
url: '/pages/order/scene/index',
})
}
})
},
// 加入拼团
join:function(e){
let item = e.currentTarget.dataset.item;
util.goKjOrder(this.data.info).then(product=>{
product.map(item=>{
item.productNum = this.data.info.purchase_quantity;
item.sku.event_price = this.data.info.event_price;
item.maxNum = this.data.info.purchase_quantity;
})
app.globalData.gp_id = this.data.info.id;
app.globalData.team_id = item.team_id;
if(this.data.info.type=='post'){
app.globalData.postProduct = product;
wx.navigateTo({
url: '/pages/order/postOrder/index',
})
}
else if(this.data.info.type=='ticket' || this.data.info.type=='scene'){
app.globalData.product = product[0];
wx.navigateTo({
url: '/pages/order/scene/index',
})
}
})
},
// 原价购买
goBuy:function(){
this.goOrder(null,1);
},
// 去下单
goOrder:function(groupId){
commonApi._get('productfront/getProductInfo',{
productId:this.data.info.productDetail.productId
}).then(res=>{
if(!res.data){
wx.showToast({
title:"该产品不存在或已下架",
icon:'none'
})
return;
}
let skuIndex = res.data.skuInfo.findIndex(item=>item.id==this.data.info.productDetail.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,
purchaseQuantity:this.data.info.productDetail.purchaseQuantity
}];
app.globalData.groupId = groupId;
app.globalData.discounts = 0;
wx.navigateTo({
url: '../../order/index',
})
})
},
// 显示或者隐藏规则
showRule:function(){
this.setData({
showRuleFlag:!this.data.showRuleFlag
})
},
// 前往列表页 如果是从列表来的直接返回 防止嵌套
backList:function(){
let page = getCurrentPages();
if(page.length>=2 && 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.setListTime()
}
if(this.data.info && this.data.info.isGroupPurchasing==1){
this.setTime()
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
if(timer){
clearTimeout(timer)
timer = null;
}
if(timer2){
clearTimeout(timer2);
timer2 = null;
}
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function (e) {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (e) {
if(e.from=='button' || this.data.myIngList.status==1){
return {
title: "我正在发起团购,快来参加吧", // 默认是小程序的名称(可以写slogan等)
path: "/pages/group/info/index?id="+this.data.info.id+'&team_id='+this.data.myIngList.team_list[0].team_id, // 默认是当前页面,必须是以‘/’开头的完整路径
imageUrl: this.data.info.headimg, //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
}
}
else {
return {
title: this.data.info.title+this.data.info.sku_name+"正在团购中~", // 默认是小程序的名称(可以写slogan等)
path: "/pages/group/info/index?id="+this.data.info.id, // 默认是当前页面,必须是以‘/’开头的完整路径
imageUrl: this.data.info.headimg, //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
}
}
}
})