This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop-wechat/pages/category/index.js

109 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-25 22:59:04 +08:00
const App = getApp();
Page({
data: {
// 搜索框样式
searchColor: "rgba(0,0,0,0.4)",
searchSize: "15",
searchName: "搜索商品",
// 列表高度
scrollHeight: 0,
// 一级分类:指针
curNav: true,
curIndex: 0,
// 分类列表
list: [],
// show
notcont: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
let _this = this;
// 设置分类列表高度
_this.setListHeight();
// 获取分类列表
_this.getCategoryList();
},
2021-07-16 16:36:54 +08:00
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 更新购物车角标
App.setCartTabBadge()
},
2020-04-25 22:59:04 +08:00
/**
* 设置分类列表高度
*/
setListHeight() {
let _this = this;
wx.getSystemInfo({
success: function(res) {
_this.setData({
scrollHeight: res.windowHeight - 47,
});
}
});
},
/**
* 获取分类列表
*/
getCategoryList() {
let _this = this;
App._get('category/index', {}, result => {
let data = result.data;
_this.setData({
list: data.list,
templet: data.templet,
curNav: data.list.length > 0 ? data.list[0].category_id : true,
notcont: !data.list.length
});
});
},
/**
* 一级分类选中分类
*/
selectNav(e) {
let _this = this;
_this.setData({
curNav: e.target.dataset.id,
curIndex: parseInt(e.target.dataset.index),
scrollTop: 0
});
},
/**
* 设置分享内容
*/
onShareAppMessage() {
2020-08-28 10:50:12 +08:00
const _this = this;
return {
title: _this.data.templet.share_title,
path: '/pages/category/index?' + App.getShareUrlParams()
};
},
/**
* 分享到朋友圈
* 本接口为 Beta 版本暂只在 Android 平台支持详见分享到朋友圈 (Beta)
* https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
*/
onShareTimeline() {
const _this = this;
2020-04-25 22:59:04 +08:00
return {
title: _this.data.templet.share_title,
path: '/pages/category/index?' + App.getShareUrlParams()
};
2020-08-28 10:50:12 +08:00
},
2020-04-25 22:59:04 +08:00
});