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

88 lines
1.6 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();
},
/**
* 设置分类列表高度
*/
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() {
let _this = this;
return {
title: _this.data.templet.share_title,
path: '/pages/category/index?' + App.getShareUrlParams()
};
}
});