hios-miniprogram/pages/index/index.js
shengliang 972d64dd0c U 将网络图标改成本地图标
U 更新支付方式的UI
F 修复轮播图的bug
F 修复没有商品时的错误显示问题
F 修复share.js的一个bug
A 增加发货时的订阅消息
2020-03-26 10:14:33 +08:00

145 lines
4.2 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,
autoplay:true
},
onHide:function(){
this.setData({
autoplay:false
})
},
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,
autoplay:true
});
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() //停止下拉刷新
},
})