// index.js //获取应用实例 var app = getApp(); let host = app.globalData.servsers; // 请求的url Page({ data: { host:host, classifyNavList:[], classifyNavActiveId: 2981, goodsList:[], requestState:true, //默认为true,表示还有数据 filterArray: [ { name: '1', value: '0~499元', price: [0,499] }, { name: '2', value: '500~999元', price: [500, 999]}, { name: '3', value: '1000~1999元', price: [1000, 1999]}, { name: '4', value: '2000元以上', price: [2000, "~"] }, ], filterStatic:false, banIndex:0, //ban的index page: 1, //默认第一页 maxPrice:null, //最大价格 minPrice:null, //最低价格 limit:10, //分页大小 priceSort: null, //价格排序 desc asc timeSort: null, //时间排序 desc asc loginStatic: false, //登陆状态,默认为false }, onLoad(){ }, onShow(){ let that = this; that.setData({ goodsList:[], page:1, }) that.getNavList(that); if (wx.getStorageSync('channelIdObj').channelId) { that.setData({ loginStatic: true, }) } }, onReachBottom: function () { if (this.data.requestState) { this.setData({ page: this.data.page + 1 }) this.getGoodsList(this) } console.log('到底了') }, getNavList(that){ wx.request({ url: host + '/classifyapi/classifyTwoAll', method:'get', data:{ classifyHigher:'3053', }, success(res){ console.log(res,"成功后的") that.setData({ classifyNavList:res.data.rows, classifyNavActiveId: res.data.rows[0].id }) that.getGoodsList(that) } }) }, classifyTap(e){ console.log(e,"classifyTap") let item = e.currentTarget.dataset.item,that = this; that.setData({ classifyNavActiveId:item.id, banIndex: e.currentTarget.dataset.index, requestState: true, //数据初始化 page: 1,//数据初始化 goodsList: []//数据初始化 }) that.getGoodsList(that) }, getGoodsList(that){ let data = { classId: that.data.classifyNavActiveId, limit: that.data.limit, offset:that.data.page, channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : "" } if (that.data.maxPrice) { data.maxPrice = that.data.maxPrice } if (that.data.minPrice) { data.minPrice = that.data.minPrice } if (that.data.priceSort) { data.priceSort = that.data.priceSort } if (that.data.timeSort) { data.timeSort = that.data.timeSort } wx.request({ url: host +'/commodityapi/queryCommodityByClass', method:'get', data:data, success(res){ let dataArray = that.data.goodsList; res.data.rows.forEach(el => { el.logo = el.commodity_logo.split(",") }) dataArray.push(...res.data.rows) that.setData({ goodsList: dataArray, requestState: res.data.rows.length > that.data.limit }) } }) }, filterTap(){ let that = this; that.setData({ filterStatic: !that.data.filterStatic, page:1, goodsList:[], requestState:true, }) that.getGoodsList(that) }, timeSortTap(){ let that = this; that.setData({ timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc', page:1, goodsList: [], requestState: true, }) that.getGoodsList(that) }, priceSortTap() { let that = this; that.setData({ priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc', }) }, blurPriceMin(e) { // event.detail = {value: value} let that = this; that.setData({ minPrice: e.detail.value, page: 1, goodsList: [], requestState: true, }) that.getGoodsList(that) }, blurPriceMax(e) { let that = this; that.setData({ maxPrice: e.detail.value, page: 1, goodsList: [], requestState: true, }) that.getGoodsList(that) }, close(){ this.setData({ filterStatic:false }) }, toGoodsDetail(e) { // 进入商品详情页 let that = this, id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/buy/buy?com_id=' + id, }) }, radioChange(e){ // radio切换 console.log(e.detail.value) let that = this, price = e.detail.value.split(','); that.setData({ minPrice: price[0], maxPrice: price[1] == '~' ? null : price[1] , requestState: true, //数据初始化 page: 1,//数据初始化 goodsList: []//数据初始化 }) that.getGoodsList(that) }, search(){ wx.redirectTo({ url: "/pages/searchList/searchList", }) } })