稍后删除


import util from '../../../utils/util.js'
import {
request,
toWebview
} from '../../../utils/request.js'
import api from '../../../api/api.js'
import apis from '../../api/api.js'
const app = getApp()

Page({
/**
* 页面的初始数据
*/
data: {
fixed: false,
navTop: '',
onPageFun: true,
activeIndex: 0,
productList: [], //店铺的楼层数据
mid: "", //从商品列表传过来的商家店铺的ID
shopType: "", //一进页返回的商家店铺的类型
Title: [],
bannerImg: "", //店铺的背景图片
logoImg: "", //店铺的小logo
chantName:null,//店铺名字
columnone: [],//店铺首页部分一行显示一张的图片
columnTwo: [],//一行显示两张的图片
columnthree: [],//一行显示三张的图片
hotGoods: [], //热销商品的数组
merchantActivity: [], //店铺活动数组,
navType: "home",
hotflag: "",
activeflag:false,
classifyType: [],//店铺首页导航的数据
brandId: "",
orderBy: "",
prolist: null,
isHavepro:false,
scrollTop: "340rpx",
swiperHeight: "",
brandList: [],
mid: "",
from: 0,
isup: true,
activeIndexs: "",
number: 20,
spec: "510X510",
flag: false,
merchantflag:true,
upstate: 0,
classifyType: [
{
type: "首页"
},
{
type: "全部商品"
},
{
type: "热销商品"
},
{
type: "店铺活动"
}

],
coupons:[],
keywords:[],
footerImg:null,
merchantname:"", //店铺名称
collect:"",
hasFavorite:false,
homeType:"",
istabBar:false,
lottery:[]
},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(8569,options)
var that = this;
that.setData({
// 无品牌和店铺
// mid: "m_3290001",
// merchantname: "AUSTGO海外集合店"

// 有店铺和品牌时
mid: "m_3690000",
// mid:"m_3540001",
merchantname: "武商网购全球线下体验店"

// mid: options.mid,
// merchantname: options.merchantname
})
// 获取该商家是否是收藏的
that.favoriteMerchantCheck()
that.gettype();
 
console.log("onload")
 
},


pagelower:function(e){
console.log("e",e)
},

// touchStart:function (e){
// console.log('滚起来', e);
// this.setData({
// scrollStop: false
// })
// },
// touchEnd(e) {
// console.log('停下来', e);
// this.setData({
// scrollStop: true
// })
// },
/***
* 得到多张优惠券
*/
getCoupons: function (e) {
// 如果没有登陆就去登陆页面
if (!app.globalData.isLogin) {
wx.navigateTo({
url: '/pages/login/wxLogin/wxLogin',
})
return
}

var aids = e.currentTarget.dataset.item.linkTo,
desc = e.currentTarget.dataset.item.description;
if (aids == "" && desc == "") {
return

}
if (aids && aids != "" || desc && desc!= "") {
if (aids.indexOf("cd_") != -1 || desc.indexOf("cd_") != -1) {
let data = {
aids: aids ? aids : desc,
device: "mobile"
}
request(api.MultiplefreeGetCoupon, data, "POST")
.then(data => {
var msg = data.data.msg
wx.showToast({
title: msg,
icon: "none",
duration: 2000
})
})
} else if (aids.indexOf("https://") != -1 || desc.indexOf("https://") != -1) {
toWebview(e.currentTarget.dataset.item)
} else {
return
}
}
},

/***
* 得到商品店铺的类型
*/
gettype: function () {
let that = this;
let data = {
type: "json",
m: that.data.mid
}
request(apis.getType, data, "POST")
.then(data => {
if (data.statusCode === 200) {
var shopType = data.data.pageData.pageID.content;
if (shopType != "") {
that.setData({
shopType: shopType,
homeType: shopType
})
 
that.getPro("home")
} else {
that.setData({
flag: true
})
}
}
})
},

/***
* 商家首页更多的数据
*/
merchantHomeMore:function(e){
let moreData = e.currentTarget.dataset.item
toWebview(moreData)
},
/**
* 点击店铺分类的时候
*/
tapshopClassify:function(){
 
},
/***
* 商家店铺的数据
*/
getPro: function (navType) {
wx.showLoading({
title: '加载中',
})
var that = this;
let data = {
m: that.data.mid,
rappId: "mobileMerchant2017",
pageId: that.data.shopType
}
request(api.getCrossClassify, data, "POST")
.then(data => {
wx.hideLoading()
if (navType == "home") {
var pageDate = data.data.pageData;
that.setData({
bannerImg: pageDate.merchantTopBg ? pageDate.merchantTopBg : "",
logoImg: pageDate.merchantLogo?pageDate.merchantLogo : "",
chantName: pageDate.merchantName ? pageDate.merchantName : "",
coupons: pageDate.merchantCoupons ? pageDate.merchantCoupons:"",
keywords: pageDate.merchantKeyWords ? pageDate.merchantKeyWords:"",
lottery: pageDate.lottery ? pageDate.lottery:"",
columnone: pageDate.merchantColumnOne ? pageDate.merchantColumnOne : "",
columnTwo: pageDate.merchantColumnTwo ? pageDate.merchantColumnTwo : "",
columnthree: pageDate.merchantColumnThree ? pageDate.merchantColumnThree : "",
footerImg: pageDate.merchantFooterImg ? pageDate.merchantFooterImg:"",

istabBar:true,
})
// 处理楼层
that.handHomeFloor(data)
}
if (navType == "hotGoods") {
var hotGoods = data.data.pageData.merchantHotGoods;
that.setData({
hotGoods: hotGoods ? hotGoods : [],
})
that.setData({
hotflag: hotGoods.length > 0 ? false : true
})
 
}
if (navType == "activity") {
var pageData = data.data.pageData;
that.setData({
merchantActivity: pageData.merchantActivityList ? pageData.merchantActivityList : [],
})
that.setData({
activeflag: that.data.merchantActivity.length > 0 ? false : true
})
}
 
})
},
/**
* 一进页面判断该商家是否收藏
*/
favoriteMerchantCheck:function(){
let merchantCheckParam = {
id: this.data.mid
}
request(api.favoriteMerchantCheck, merchantCheckParam, 'POST')
.then(res => {
this.setData({
hasFavorite: res.data.hasFavorite
})

})
},
/** 点击收藏按钮时*/
favoriteMerchant:function(){
let favoriteMerchantParam = {
id: this.data.mid,
type: this.data.hasFavorite ? 'cancel' : 'add'
}
request(api.favoriteMerchant, favoriteMerchantParam, 'POST')
.then(res => {
let code = res.data.code
if (code == "0") { //成功
if (favoriteMerchantParam.type == "cancel") {
wx.showToast({ title: '取消成功', icon: 'none', duration: 2000 })
this.setData({
hasFavorite: false
})
} else {
wx.showToast({ title: '收藏成功', icon: 'none', duration: 2000 })
this.setData({
hasFavorite: true
})
}
} else {
wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 })
}
})
},
/***
* swiper发生改变时触发的事件
*/
changeSwiper: function (e) {
var that = this,
activeIndex = e.detail.current;
that.setData({
activeIndex: activeIndex
});
if (activeIndex == 0) {
that.setData({
shopType: that.data.homeType,
})
that.getPro("home")
 
}
if (activeIndex == 1) {
that.getList(0)
}
if (activeIndex == 2) {
that.setData({
shopType: "merchantHotGoods",
})
that.getPro("hotGoods")
}
if (activeIndex == 3) {
that.setData({
shopType: "merchantShopActivity",
})
that.getPro("activity")
}
},


/***
* 点击切换店铺导航
*/
tabSwitch: function (e) {
let that = this;
that.setData({
activeIndex: e.currentTarget.dataset.index
})
let activeIndex = e.currentTarget.dataset.index;
if (activeIndex == 0) {
that.setData({
shopType: that.data.homeType,
})
that.getPro("home")
}
if (activeIndex == 1) {
that.getList(0)
}
if (activeIndex == 2) {
that.setData({
shopType: "merchantHotGoods",
})
that.getPro("hotGoods")
}
if (activeIndex == 3) {
that.setData({
shopType: "merchantShopActivity",
})
that.getPro("activity")
}
},

/***
* 全部商品加载数据时的函数
*/
/***
* 点击全部商品的分类的时候
*/
getProList: function (e) {
wx.clearStorageSync("activeIndexs")
var that = this;
if (e.currentTarget.dataset.index != 3) {
that.setData({
activeIndexs: e.currentTarget.dataset.index,
});
}
wx.setStorageSync("activeIndexs", e.currentTarget.dataset.index);
var selectType = e.currentTarget.dataset.index
if (selectType == 0) {
if (that.data.isup == true) {
that.setData({
isup: false
});
} else {
that.setData({
isup: true
});
}
that.setData({
orderBy: "",
from: 0
});
that.getList(1)
}
if (selectType == 1) {
if (this.data.isup == true) {
that.setData({
upstate: 0,
isup: false,
from: 0,
orderBy: "priceLow"
});

} else {
that.setData({
upstate: 1,
isup: true,
orderBy: "priceHigh",
from: 0

});
}
that.getList(1)
}
if (selectType == 2) {
if (that.data.isup == true) {
that.setData({
isup: false
});
} else {
that.setData({
isup: true
});
}
that.setData({
orderBy: "saleCount",
from: 0
});
that.getList(1)
}


//点击筛选的时候
if (selectType == 3) {
that.setData({
isup: true,
isShow: true,
isTrans: true,
isBack: false,
brandId: that.data.brandId,
from: 0
});
}
},

//点击遮罩层
toBack: function () {
var that = this;
that.setData({
isShow: false

});
},
//点击筛选的列表的数据
filterFn: function (e) {
var that = this;
that.setData({
filterIndex: e.currentTarget.dataset.index,
brandId: e.currentTarget.dataset.filterid,
isShow: false
});
that.getList(1)
},
/***
* 点击
*全部商品时触**/
getList: function (type) {
var that = this;
wx.showLoading({
title: '加载中'
})
let data = {
columnId: "",
keyword: "",
from: 0,
number: that.data.number,
spec: that.data.spec,
mid: that.data.mid,
orderBy: that.data.orderBy,
brandId: that.data.brandId
}
request(api.searchHotKeys, data, "POST")
.then(data => {
wx.hideLoading();
if (data.data.products.length<=0){
that.setData({
isHavepro:true
})
}
// 得到品牌
if (type == 0) {
that.setData({
brandList: data.data.brandList,
prolist: data.data.products,
total: data.data.total
});
}
// 页面数据的调用
if (type == 1) {
that.setData({
prolist: data.data.products,
total: data.data.total
});
}
//更多数据的时候

if (type == 2) {
if (that.data.from < that.data.total) {
var arr = that.data.prolist
if (arr2 != 0) {
var arr2 = data.data.products
}
var arrMore = arr.concat(arr2)
that.setData({
prolist: arrMore
})
wx.hideLoading();
} else {
wx.showLoading({
title: '玩命加载中',
mask: true
})
setTimeout(function () {
wx.hideLoading();
}, 1000)

}
}

})
},
/***
* 全部商品结束
*/





/**
* 处理商家导航 首页楼层部分
*/
handHomeFloor: function (data) {
var that = this,
pageData = data.data.pageData,
levelArr = pageData.config.levelNum.value.split(","),
floors = [];
for (var i = 0, num; num = levelArr[i++];) {
var flooritem = {}
flooritem.Goods = pageData['merchantFloorGoods' + num]
flooritem.Title = pageData['merchantFloorTitle' + num]
flooritem.Num = num
floors.push(flooritem)
}
that.setData({
productList: floors,
})
},

/***
* 点击继续逛按钮
*/
continueShop: function () {
wx.navigateBack({
delta: 1
})
},

 
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
var that = this;
// 获取屏幕的高度
// wx.getSystemInfo({
// success: function (res) {
// let windowHeight = (res.windowHeight * (750 / res.windowWidth))
// that.setData({
// swiperHeight: windowHeight - 340
// })
// }
// })
// wx.createSelectorQuery().select('#nav-list').boundingClientRect(function (rect) {
// console.log(rect)
 
// }).exec()



// wx.createSelectorQuery().select('.nav-list').boundingClientRect(function (rect) {
// console.log(502, rect)
// if (rect) {
// that.setData({
// top: rect.top
// })
// }

// }).exec()
// wx.createSelectorQuery().select('.nav-list').boundingClientRect(function (rect) {
// console.log(rect)
// }).exec()
var that = this;
setTimeout(function(){
console.log('延迟启动')
if (that.data.onPageFun) {
const queryy = wx.createSelectorQuery().in(that)
queryy.select('.nav-list').boundingClientRect(function (rect) {
console.log(rect)
console.log('获取dome高度')
that.setData({ navTop: rect.top })
}).exec()
that.setData({
onPageFun: false
})
}
}, 2000)
},


/**
* 监听页面滚动时
*/
onPageScroll: function (e) {
var that = this;
if (e.scrollTop >= that.data.navTop) {
that.setData({
fixed: true
})
console.log('执行打开')
console.log(that.data.fixed)
}else {
that.setData({
fixed: false
})
console.log('执行关闭')
console.log(that.data.fixed)
}
},
/**
* 生命周期函数--监听页面显示
*
*/
onShow: function () {
console.log("onshow")
},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
console.log("触底了")
var that=this;
 
if (that.data.prolist){
if (that.data.prolist.length < that.data.total) {
that.setData({
from: that.data.from + 20
})
that.getList(2)
}
}

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

}
})

猜你喜欢

转载自www.cnblogs.com/ralapgao/p/11326109.html