123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import { getCategoryList} from '../../api/store.js';
- const app = getApp();
- Page({
-
- data: {
- navlist: [],
- productList: [],
- navActive: 0,
- parameter: {
- 'navbar': '1',
- 'return': '0',
- 'title':'产品分类'
- },
- navH:"",
- number:""
- },
-
- onLoad: function (res) {
- this.getAllCategory();
- },
- infoScroll:function(){
- let that = this;
- let len = that.data.productList.length;
- that.setData({
- navH: app.globalData.navHeight,
- number: that.data.productList[len - 1].children.length
- })
-
- wx.getSystemInfo({
- success: function (res) {
- that.setData({
- height: (res.windowHeight) * ( 750/res.windowWidth) - 98 - app.globalData.navHeight
-
- })
- },
- });
- var height = 0;
- var hightArr = [];
- for (var i = 0; i < len; i++) {
-
- var query = wx.createSelectorQuery().in(this);
- var idView = "#b" + i;
- query.select(idView).boundingClientRect();
- query.exec(function (res) {
- var top = res[0].top;
- hightArr.push(top);
- that.setData({
- hightArr: hightArr
- });
- });
- };
- },
- tap: function (e) {
- var id = e.currentTarget.dataset.id;
- var index = e.currentTarget.dataset.index;
- this.setData({
- toView: id,
- navActive: index
- });
- },
- getAllCategory:function(){
- var that = this;
- getCategoryList().then(res=>{
- that.setData({
- productList: res.data
- });
- that.infoScroll();
- })
- },
- scroll: function (e) {
- var scrollTop = e.detail.scrollTop;
- var scrollArr = this.data.hightArr;
- for (var i = 0; i < scrollArr.length; i++) {
- if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
- this.setData({
- navActive: 0,
- lastActive: 0
- })
- } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
- this.setData({
- navActive: i
- })
- } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
- this.setData({
- navActive: scrollArr.length - 1
- })
- }
- }
- },
- searchSubmitValue: function (e) {
- if (e.detail.value.length > 0)
- wx.navigateTo({ url: '/pages/goods_list/goods_list?searchValue=' + e.detail.value})
- else
- return app.Tips({ title:'请填写要搜索的产品信息'});
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- }
- })
|