123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- // pages/shopPage/shopPage.js
- var http = require('../../utils/http.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- shopId: 0,
- shopInfo: {},
- indicatorDots: true,
- indicatorColor: '#d1e5fb',
- indicatorActiveColor: '#1b7dec',
- autoplay: true,
- interval: 2000,
- duration: 1000,
- indexImgs: [],
- topFlag: false,
- isCollection: false,
- shopProdList: [],
- },
- //加载轮播图
- getIndexImgs() {
- var shopId = this.data.shopId
- //加载轮播图
- var params = {
- url: `/indexImgs/${shopId}`,
- method: "GET",
- data: {},
- callBack: (res) => {
- this.setData({
- indexImgs: res,
- // seq: res
- });
- wx.hideLoading();
- }
- };
- http.request(params);
- },
- // 跳转店铺详情页
- toShopInfo(e) {
- const shopId = e.currentTarget.dataset.shopid
- wx.navigateTo({
- url: '/pages/shopInfo/shopInfo?shopId=' + shopId,
- })
- },
- // 跳转店内搜索页
- toShopSearchPage: function(e) {
- wx.navigateTo({
- url: '/pages/shopSearch/shopSearch?shopId=' + e.currentTarget.dataset.shopid,
- })
- },
- // 跳转所有商品页
- toShopProds(e) {
- wx.navigateTo({
- url: '/pages/shopProds/shopProds?shopId=' + e.currentTarget.dataset.shopid,
- })
- },
- // 收藏/取消收藏
- addOrCannelCollection() {
- this.setData({
- isCollection: !this.data.isCollection
- })
- },
- // 跳转商品详情页
- toProdPage: function(e) {
- var prodid = e.currentTarget.dataset.prodid;
- if (prodid) {
- wx.navigateTo({
- url: '/pages/prod/prod?prodid=' + prodid,
- })
- }
- },
- // 获取店铺信息
- getShopInfo: function() {
- var ths = this;
- //热门搜索
- var params = {
- url: "/shop/headInfo",
- method: "GET",
- data: {
- shopId: ths.data.shopId
- },
- callBack: function(res) {
- wx.hideLoading()
- ths.setData({
- shopInfo: res,
- })
- wx.setStorageSync("shopInfo", res)
- ths.setNavTitle()
- ths.getIndexImgs()
- ths.getShopProds()
- },
- };
- http.request(params);
- },
- // 获取店铺商品
- getShopProds() {
- var params = {
- url: '/search/searchProdPage',
- method: 'GET',
- data: {
- shopId: this.data.shopId,
- isAllProdType: true
- },
- callBack: (res) => {
- wx.hideLoading()
- this.setData({
- shopProdList: res.records
- })
- }
- }
- http.request(params)
- },
- // 设置页面标题
- setNavTitle() {
- wx.setNavigationBarTitle({
- title: this.data.shopInfo.shopName
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- wx.showLoading({
- title: '',
- mask: true,
- })
- if (options.shopId) {
- this.setData({
- shopId: options.shopId
- })
- wx.setStorageSync("currShopId", options.shopId);
- } else {
- this.setData({
- shopId: wx.getStorageSync("currShopId")
- })
- }
- this.getShopInfo()
- },
- /**
- * 跳转店铺详情
- */
- toShopInfo() {
- wx.navigateTo({
- url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopId,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- },
- // 页面滚动事件
- onPageScroll: function(e) {
- var _this = this
- if (e.scrollTop > 80) {
- _this.setData({
- topFlag: true
- })
- } else {
- _this.setData({
- topFlag: false
- })
- }
- }
- })
|