|
@@ -10,33 +10,11 @@ Page({
|
|
|
{ title: '羽毛球', name: '1' },
|
|
|
],
|
|
|
},
|
|
|
- list: [
|
|
|
- {
|
|
|
- _id:'1',
|
|
|
- name: '1212',
|
|
|
- home_url: [{ url: '/image/lingdang.png' }]
|
|
|
- },
|
|
|
- {
|
|
|
- name: '1212',
|
|
|
- home_url: [{ url: '/image/lingdang.png' }]
|
|
|
- },
|
|
|
- {
|
|
|
- name: '1212',
|
|
|
- home_url: [{ url: '/image/lingdang.png' }]
|
|
|
- },
|
|
|
- {
|
|
|
- name: '1212',
|
|
|
- home_url: [{ url: '/image/lingdang.png' }]
|
|
|
- },
|
|
|
- {
|
|
|
- name: '1212',
|
|
|
- home_url: [{ url: '/image/lingdang.png' }]
|
|
|
- },
|
|
|
- {
|
|
|
- name: '1212',
|
|
|
- home_url: [{ url: '/image/lingdang.png' }]
|
|
|
- },
|
|
|
- ],
|
|
|
+ list: [],
|
|
|
+ page: 0,
|
|
|
+ skip: 0,
|
|
|
+ limit: 5,
|
|
|
+ total: 0,
|
|
|
typeList: news_type,
|
|
|
},
|
|
|
|
|
@@ -48,26 +26,57 @@ Page({
|
|
|
tabsChange: function (e) {
|
|
|
const that = this;
|
|
|
that.setData({ 'tabs.active': e.detail.name });
|
|
|
+ that.setData({ skip: 0 })
|
|
|
+ that.setData({ page: 0 })
|
|
|
+ that.setData({ list: [] })
|
|
|
+ that.watchLogin()
|
|
|
},
|
|
|
|
|
|
toView: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ skip: 0 })
|
|
|
+ that.setData({ page: 0 })
|
|
|
+ that.setData({ list: [] })
|
|
|
const { item } = e.currentTarget.dataset;
|
|
|
wx.navigateTo({ url: `/pages/news/info?id=${item._id}` })
|
|
|
},
|
|
|
+
|
|
|
+ toPage: function () {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.list;
|
|
|
+ let limit = that.data.limit;
|
|
|
+ if (that.data.total > list.length) {
|
|
|
+ wx.showLoading({ title: '加载中', mask: true })
|
|
|
+ let page = that.data.page + 1;
|
|
|
+ that.setData({ page: page })
|
|
|
+ let skip = page * limit;
|
|
|
+ that.setData({ skip: skip })
|
|
|
+ that.watchLogin();
|
|
|
+ wx.hideLoading()
|
|
|
+ } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
|
|
|
+ },
|
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) { },
|
|
|
|
|
|
watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ let type = that.data.tabs.active;
|
|
|
|
|
|
wx.getStorage({
|
|
|
key: 'user',
|
|
|
success: async res => {
|
|
|
-
|
|
|
+ let info = { skip: that.data.skip, limit: that.data.limit, type: type };
|
|
|
+ const arr = await app.$get(`/newCourt/api/news`, { ...info });
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.setData({ list: [...that.data.list, ...arr.data] });
|
|
|
+ that.setData({ total: arr.total })
|
|
|
+ }
|
|
|
+ else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
|
|
|
},
|
|
|
fail: async res => {
|
|
|
-
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
}
|
|
|
})
|
|
|
},
|