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.
 

315 lines
7.0 KiB

// 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,
nextList:[],
menuList:[],
menuIndex:-1,
list:[],
mineList:[],
showMoreFlag:false,
mineAllList:[],
nextPage:1,
page:1,
nextTotal:1,
total:1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getMine();
productApi.user_post("activity.haggle/get_act_list",{limit:100,page:1}).then(res=>{
this.setData({
menuList:res.data.data,
menuIndex:0
})
this.getList()
})
},
changeType:function(e){
let type = e.currentTarget.dataset.type;
if(this.data.type==type) return;
this.setData({
type:type,
nextPage:1,
page:1,
nextTotal:1,
total:1,
list:[],
nextList:[]
})
this.onReachBottom()
},
changeMenu:function(e){
let index = e.currentTarget.dataset.index;
if(this.data.menuIndex==index) return;
this.setData({
menuIndex:index,
page:1,
total:1,
list:[]
})
this.getList()
},
gotoDetail:function(e){
let data = e.currentTarget.dataset,that = this;
if(data.index || data.index==0){
let item = this.data.list[data.index];
console.log(item)
// 已砍成已下单
if(item.buy_status=='end'){
wx.showModal({
title:"提示",
content:"单个商品单账户只可参与一次,是否原价购买",
confirmColor:"#e14135",
success:function(res){
if(res.confirm){
that.gotoProduct(item.goods_id)
}
}
})
return;
}
// 已砍成未下单
if(item.buy_status=='over'){
app.globalData.kjId = item.buy_id;
// todo
util.goKjOrder(item).then(product=>{
app.globalData.couponInfo = null;
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;
wx.navigateTo({
url: '/pages/order/scene/index',
})
}
})
return;
}
// 已售罄
if(item.act_stock<=0){
wx.showModal({
title:"提示",
content:"此商品已售罄,是否原价购买",
confirmColor:"#e14135",
success:function(res){
if(res.confirm){
that.gotoProduct(item.goods_id)
}
}
})
return;
}
}
wx.navigateTo({
url:"info/index?id="+data.id+"&sid="+data.sid+"&aid="+data.aid
})
},
gotoProduct:function(id){
productApi._post("product/get_product_detail",{
id:id
}).then(res=>{
util.gotoDetail(res.data)
})
},
getMine:function(){
productApi.user_post("order/my_haggle_list?status=1&limit=100&page=1",{
}).then(res=>{
this.setData({
mineList:this.data.showMoreFlag?res.data.data:res.data.data.slice(0,2),
mineAllList:res.data.data
})
this.setTime();
if(timer){
clearInterval(timer);
}
timer = setInterval(()=>{
this.setTime()
},1000)
})
},
getNext:function(){
if(this.data.nextTotal==this.data.nextList.length) return;
productApi.user_post("activity.haggle/get_warm_up",{
limit:100,
page:this.data.nextPage
}).then(res=>{
res.data.data.map(item=>{
item.showMoreFlag = false;
item.showList = item.product.slice(0,2);
})
this.setData({
nextList:this.data.nextList.concat(res.data.data),
nextPage:this.data.nextPage+1,
nextTotal:res.data.total
})
})
},
getList:function(){
if(this.data.total==this.data.list.length) return;
let dataStr = this.getStrParams({
act_id:this.data.menuList[this.data.menuIndex].id,
limit:100,
page:this.data.page
})
productApi.user_post("activity.haggle/get_act_products"+dataStr,{
}).then(res=>{
this.setData({
list:this.data.list.concat(res.data.data),
page:this.data.page+1,
total:res.data.total
})
})
},
showMore:function(e){
let index = e.currentTarget.dataset.index,nextList=this.data.nextList;
nextList[index].showMoreFlag = !nextList[index].showMoreFlag;
if(nextList[index].showMoreFlag){
item.showList = item.product;
}
else {
item.showList = item.product.slice(0,2);
}
this.setData({
nextList:nextList
})
},
showMineMore:function(){
this.setData({
showMoreFlag:!this.data.showMoreFlag
})
let mineList = this.data.mineAllList;
if(!this.data.showMoreFlag){
mineList= mineList.slice(0,2);
}
this.setData({
mineList:mineList
})
},
// 倒计时
setTime:function(){
let mineList = this.data.mineList,now = new Date().getTime();
mineList.map(item=>{
let overTime = new Date(item.over_time.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({
mineList:mineList
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(this.data.mineList.length>0){
this.setTime();
timer = setInterval(()=>{
this.setTime()
},1000)
}
if(this.data.menuIndex>-1){
this.getMine();
this.getList();
}
},
nextShowInfo:function(){
wx.showModal({
title:"提示",
content:"活动暂未开始",
confirmText:"我知道了",
confirmColor:"#E14135",
showCancel:false
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
if(timer){
clearInterval(timer)
timer = null;
}
},
getStrParams:function(data){
let dataStr = [];
for(let i in data){
dataStr.push(i+'='+data[i]);
}
return ("?"+dataStr.join("&"));
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if(this.data.type==1){
this.getList()
}
else {
this.getNext()
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})