const fetch = require('../../utils/fetch') Page({ /** * 页面的初始数据 */ data: { category: null, shops: [], pageIndex: 0, pageSize: 20, totalCount: 0, hasMore: true }, loadMore () { let { pageIndex, pageSize, searchText } = this.data const params = { _page: ++pageIndex, _limit: pageSize } if (searchText) params.q = searchText return fetch(`/?${this.data.category.id}`, params) .then(res => { res = '[{"id":1,"score":"c","name":"2018大梅时代歌舞节","phone":"400-8123-321","address":"光华路36号","businessHours":"8:00 - 16:00","images":["/assets/icons/basketball.png"]},{"id":2,"score":"c","name":"2018大梅时代体育节","phone":"400-8123-321","address":"光华路36号","businessHours":"8:00 - 16:00","images":["/assets/icons/basketball.png"]},{"id":3,"score":"c","name":"2018大梅时代演讲比赛","phone":"400-8123-321","address":"光华路36号","businessHours":"8:00 - 16:00","images":["/assets/icons/basketball.png"]},{"id":4,"score":"c","name":"2018大梅时代新歌声大赛","phone":"400-8123-321","address":"光华路36号","businessHours":"8:00 - 16:00","images":["/assets/icons/basketball.png"]}]'; res = JSON.parse(res); const totalCount = 4; //parseInt(res.header['X-Total-Count']) const hasMore = this.data.pageIndex * this.data.pageSize < totalCount const shops = this.data.shops.concat(res); this.setData({ shops:shops, totalCount, pageIndex, hasMore }) }) }, /** * 生命周期函数--监听页面加载 */ onLoad (options) { fetch(`/?catogories${options.cat}`) .then(res => { res = { data: {name:"球类运动"} }; this.setData({ category: res.data }) wx.setNavigationBarTitle({ title: res.data.name }) this.loadMore() }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh () { this.setData({ shops: [], pageIndex: 0, hasMore: true }) this.loadMore().then(() => wx.stopPullDownRefresh()) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom () { // TODO:节流 this.loadMore() }, searchHandle () { // console.log(this.data.searchText) this.setData({ shops: [], pageIndex: 0, hasMore: true }) this.loadMore() }, showSearchHandle () { this.setData({ searchShowed: true }) }, hideSearchHandle () { this.setData({ searchText: '', searchShowed: false }) }, clearSearchHandle () { this.setData({ searchText: '' }) }, searchChangeHandle (e) { this.setData({ searchText: e.detail.value }) } })