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.
 

322 lines
7.5 KiB

// pages/user/pdd/index.js
import productApi from "../../utils/https/common"
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;
if(data.index || data.index==0){
let item = this.data.list[data.index];
console.log(item)
// 已砍成已下单
if(item.myOriginateFlag=='over' && item.isBuyed==1){
wx.showModal({
title:"提示",
content:"单个商品单账户只可参与一次,是否原价购买",
confirmColor:"#e14135",
success:function(res){
if(res.confirm){
wx.navigateTo({
url: '/pages/info/'+(item.frontShowModel=='line'?'productInfo':'skuProductInfo')+'/index?id='+item.productId
})
}
}
})
return;
}
// 已砍成未下单
if(item.myOriginateFlag=='over' && item.isBuyed!=1){
productApi._get('productfront/getProductInfo',{
productId:item.productId
}).then(res=>{
if(!res.data){
wx.showToast({
title:"该产品不存在或已下架",
icon:'none'
})
return;
}
let skuIndex = res.data.skuInfo.findIndex(skuItem=>skuItem.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.discounts = 0;
// todo
app.globalData.kjOrderId = item.originateId || null
wx.navigateTo({
url: '/pages/order/index',
})
})
return;
}
// 已售罄
if(item.stock<=0){
wx.showModal({
title:"提示",
content:"此商品已售罄,是否原价购买",
confirmColor:"#e14135",
success:function(res){
if(res.confirm){
wx.navigateTo({
url: '/pages/info/'+(item.frontShowModel=='line'?'productInfo':'skuProductInfo')+'/index?id='+item.productId
})
}
}
})
return;
}
}
wx.navigateTo({
url:"info/index?id="+data.id+"&sid="+data.sid+"&aid="+data.aid
})
},
getMine:function(){
productApi.user_post("kj/getMyKjIngProductsNeedAuth",{}).then(res=>{
this.setData({
mineList:this.data.showMoreFlag?res.data:res.data.slice(0,2),
mineAllList:res.data
})
this.setTime();
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.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({
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 () {
}
})