123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- const app = getApp()
- Page({
- data: {
- frameStyle: { useTop: true, name: '首页', leftArrow: false, useBar: true },
- lingdang: '/image/lingdang.png',
- user: {},
- list: [],
- page: 0,
- skip: 0,
- limit: 5,
- total: 0,
- },
- // 跳转菜单
- tabPath(e) {
- let { route } = e.detail.detail;
- if (route) wx.redirectTo({ url: `/${route}` })
- },
- toView: function (e) {
- const { item } = e.currentTarget.dataset;
- wx.navigateTo({ url: `/pages/match/info?id=${item._id}` })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) { },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () { },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const that = this;
- // 监听用户是否登录
- that.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- let info = { skip: that.data.skip, limit: that.data.limit };
- const arr = await app.$get(`/newCourt/api/match`, { ...info });
- if (arr.errcode == '0') {
- let arr1 = that.data.list;
- let arr2 = arr.data;
- arr1 = arr1.concat(arr2);
- that.setData({ list: arr1 })
- }
- const aee = await app.$get(`/newCourt/api/match`);
- if (aee.errcode == '0') {
- that.setData({ total: aee.data.length })
- }
- else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const that = this;
- if (that.data.total > that.data.list.length) {
- wx.showLoading({ title: '加载中', mask: true })
- let page = that.data.page + 1; //获取当前页数并+1
- that.setData({ page: page })//更新当前页数
- let limit = that.data.limit;
- let skip = page * limit;
- that.setData({ skip: skip })
- that.watchLogin();
- wx.hideLoading()
- } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|