hios-miniprogram/pages/index/index.js
shengliang 65f37e00b6 1、修复一个群友Solver提出的关于体验性改善的问题
2、详情页增加加载动画效果
3、去除一些console.log
2020-03-07 20:21:04 +08:00

138 lines
4.1 KiB
JavaScript

const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');
//获取应用实例
const app = getApp()
Page({
data: {
floorGoods: [],
openAttr: false,
showChannel: 0,
showBanner: 0,
showBannerImg: 0,
goodsCount: 0,
banner: [],
index_banner_img:0,
userInfo: {},
imgurl: '',
sysHeight:0,
loading: 0,
},
goSearch:function(){
wx.navigateTo({
url: '/pages/search/search',
})
},
goCategory: function(e) {
let id = e.currentTarget.dataset.cateid;
wx.setStorageSync('categoryId', id);
wx.switchTab({
url: '/pages/category/index',
})
},
getCatalog: function () {
let that = this;
util.request(api.GoodsCount).then(function (res) {
that.setData({
goodsCount: res.data.goodsCount
});
});
},
handleTap: function(event) {
//阻止冒泡
},
onShareAppMessage: function() {
let info = wx.getStorageSync('userInfo');
return {
title: '海风小店',
desc: '开源微信小程序商城',
path: '/pages/index/index?id=' + info.id
}
},
toDetailsTap: function() {
wx.navigateTo({
url: '/pages/goods-details/index',
});
},
getIndexData: function() {
let that = this;
util.request(api.IndexUrl).then(function(res) {
if (res.errno === 0) {
that.setData({
floorGoods: res.data.categoryList,
banner: res.data.banner,
channel: res.data.channel,
notice: res.data.notice,
loading: 1,
});
}
});
},
onLoad: function(options) {
let systemInfo = wx.getStorageSync('systemInfo');
var scene = decodeURIComponent(options.scene);
this.getCatalog();
},
onShow: function() {
this.getCartNum();
this.getChannelShowInfo();
this.getIndexData();
var that = this;
let userInfo = wx.getStorageSync('userInfo');
if (userInfo != '') {
that.setData({
userInfo: userInfo,
});
};
let info = wx.getSystemInfoSync();
let sysHeight = info.windowHeight - 100;
this.setData({
sysHeight: sysHeight
});
wx.removeStorageSync('categoryId');
},
getCartNum: function() {
util.request(api.CartGoodsCount).then(function(res) {
if (res.errno === 0) {
let cartGoodsCount = '';
if (res.data.cartTotal.goodsCount == 0) {
wx.removeTabBarBadge({
index: 2,
})
} else {
cartGoodsCount = res.data.cartTotal.goodsCount + '';
wx.setTabBarBadge({
index: 2,
text: cartGoodsCount
})
}
}
});
},
getChannelShowInfo: function(e) {
let that = this;
util.request(api.ShowSettings).then(function(res) {
if (res.errno === 0) {
let show_channel = res.data.channel;
let show_banner = res.data.banner;
let show_notice = res.data.notice;
let index_banner_img = res.data.index_banner_img;
that.setData({
show_channel: show_channel,
show_banner: show_banner,
show_notice: show_notice,
index_banner_img: index_banner_img
});
}
});
},
onPullDownRefresh: function() {
wx.showNavigationBarLoading()
this.getIndexData();
this.getChannelShowInfo();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
})