var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); const user = require('../../../utils/user.js'); const area = require('../../../utils/area.js'); //获取应用实例 const app = getApp(); Page({ data: { categoryList: [], currentCategory: {}, currentSubCategoryList: {}, scrollLeft: 0, scrollTop: 0, goodsList:[], goodsCount: 0, scrollHeight: 0, hasLogin: true, city:'',//当前业务城市 citys:[], cityIndex:0, addressInfo:{}, }, onLoad: function (options) { this.getCatalog(); }, onPullDownRefresh() { wx.showNavigationBarLoading() //在标题栏中显示加载 this.getCatalog(); wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 }, listenerCitySelected(e){ this.setData({ cityIndex:e.detail.value, city:this.data.citys[e.detail.value] }) app.globalData.city=this.data.city; }, getCatalog: function () { //CatalogList let that = this; wx.showLoading({ title: '加载中...', }); util.request(api.CatalogList).then(function (res) { //1036763 写死值 如果地址为上海 隐藏活动专享 //console.info(res.data.categoryList) var list=res.data.categoryList; if(that.data.addressInfo.city&&that.data.addressInfo.city=="上海市"){ var categorys=[]; res.data.categoryList.forEach(item=>{ if(item.id!=1036763) categorys.push(item); }); list=categorys; } that.setData({ categoryList:list, currentCategory: res.data.currentCategory, currentSubCategoryList: res.data.currentSubCategory }); that.getCategoryGoods(); wx.hideLoading(); }); util.request(api.GoodsCount).then(function (res) { that.setData({ goodsCount: res.data }); }); }, getCategoryGoods(){//获取一级类目下所有商品 let that=this; util.request(api.GoodsL1Category,{ id:that.data.currentCategory.name=='热销商品'?'-1':that.data.currentCategory.id, shopId:that.data.addressInfo.shopId, isHot:that.data.currentCategory.name=='热销商品'?true:false }).then(res=>{ console.info(res.data) that.setData({ goodsList:res.data }) }) }, getCurrentCategory: function (id) { let that = this; util.request(api.CatalogCurrent, { id:id, }) .then(function (res) { that.setData({ currentCategory: res.data.currentCategory, currentSubCategoryList: res.data.currentSubCategory, }); that.getCategoryGoods(); }); }, onReady: function () { // 页面渲染完成 if (app.globalData.hasLogin) { this.setData({ hasLogin: true }); } }, onShow: function () { // 页面显示 //显示购物车角标 //user.cartshow(); //确定业务城市 var addressInfo=wx.getStorageSync('addressInfo'); if(addressInfo){ this.setData({ addressInfo:addressInfo }) } }, goLogin: function (e) { if (e.detail.userInfo == null) { app.globalData.hasLogin = false; util.showErrorToast('微信授权失败'); return; } app.globalData.hasLogin = false; wx.setStorageSync('userInfo', null); user.loginByWeixin(e.detail.userInfo).then(res => { //跳转注册页 wx.navigateTo({ url: "/pages/auth/register/register" }); }).catch((err) => { app.globalData.hasLogin = false; }); }, onHide: function () { // 页面隐藏 }, onUnload: function () { // 页面关闭 }, switchCate: function (event) { var that = this; var currentTarget = event.currentTarget; if (this.data.currentCategory.id == event.currentTarget.dataset.id) { return false; } this.getCurrentCategory(event.currentTarget.dataset.id); }, goinviteFriends(e) { console.log(app.globalData.hasLogin); //跳转到邀请页面 if (app.globalData.hasLogin) { wx.navigateTo({ url: '/pages/activity/invitefriends/inviteFriends' }) } else { wx.navigateTo({ url: "/pages/auth/login/login" }); }; }, })