123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- // pages/match/index.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- appAssetsUrl2: app.appAssetsUrl2,
- matchList: [],
- statusBarHeightTop: 0,
- statusBarHeight: 0,
- // 分页相关数据
- pageNum: 1,
- pageSize: 10,
- total: 0,
- hasMore: true,
- isLoading: false,
- imglist: [],
- current: 0,
- activeTitle: false,
- },
- /**
- * 赛事项目点击事件
- */
- onMatchItemTap(e) {
- const index = e.currentTarget.dataset.index;
- const matchItem = this.data.matchList[index];
- console.log('点击赛事项目:', matchItem);
- // 跳转到详情页面
- wx.navigateTo({
- url: `/pages/match/details/index?id=${matchItem.id}`
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.height();
- this.loadImg();
- // 加载赛事数据
- this.loadMatchData();
- },
- changeSwiper(e) {
- let {
- current,
- source
- } = e.detail;
- if (source === "autoplay" || source === "touch") {
- this.setData({
- current: current,
- });
- }
- // this.setData({
- // current: e.detail.current
- // })
- },
- //banner跳转
- imgJump(v) {
- // console.log(v);
- // console.log(v.currentTarget.dataset.item.jumpAddressType);
- if (v.currentTarget.dataset.item.jumpAddressType == 0) {
- //内部跳转
- wx.navigateTo({
- url: v.currentTarget.dataset.item.linkUrl,
- });
- } else if (v.currentTarget.dataset.item.jumpAddressType == 1) {
- //公众号跳转 'https://www.kujiale.cn/design/3FO4EQWQJF0M/show'
- wx.setStorageSync("gzurl", v.currentTarget.dataset.item.linkUrl);
- wx.navigateTo({
- url: "./gz/gz",
- });
- }
- },
- // 首页banner
- loadImg: function () {
- let _this = this;
- let params = {
- type: "03",
- area: "",
- };
- app._post_form("img/mylist", "application/json", params, function (res) {
- if (res.code == 0) {
- _this.setData({
- imglist: res.data,
- });
- }
- });
- },
- /**
- * 加载赛事数据
- */
- loadMatchData() {
- // 如果正在加载或没有更多数据,则不执行
- if (this.data.isLoading || !this.data.hasMore) {
- return;
- }
-
- this.setData({
- isLoading: true
- });
-
- wx.showLoading({
- title: this.data.pageNum === 1 ? '加载中...' : '加载更多...'
- });
- // 调用API获取赛事数据
- const params = {
- pageNum: this.data.pageNum,
- pageSize: this.data.pageSize
- };
-
- // 使用项目中已有的请求方法
- app._get('news/page', params, (res) => {
- wx.hideLoading();
- this.setData({
- isLoading: false
- });
-
- if (res.code === 0) {
- // 处理返回的数据
- const newList = res.page.list || [];
- const total = res.page.totalPage || 0;
-
- // 如果是第一页,直接设置数据;否则追加数据
- const matchList = this.data.pageNum === 1 ? newList : [...this.data.matchList, ...newList];
-
- this.setData({
- matchList: matchList,
- total: total,
- hasMore: matchList.length < total
- });
- } else {
- wx.showToast({
- title: '数据加载失败',
- icon: 'none'
- });
- }
- }, (fail) => {
- wx.hideLoading();
- this.setData({
- isLoading: false
- });
- wx.showToast({
- title: '请求失败',
- icon: 'none'
- });
- });
- },
-
- /**
- * 重置并重新加载数据
- */
- reloadMatchData() {
- this.setData({
- pageNum: 1,
- matchList: [],
- hasMore: true
- });
- this.loadMatchData();
- },
-
- height() {
- const {
- platform,
- statusBarHeight
- } = wx.getSystemInfoSync();
- let statusBarHeightTop = statusBarHeight;
- let height = statusBarHeight + 4; //ios 24px
- let mH = statusBarHeight + 4;
- if (platform.toLowerCase() == "android") {
- height += 4; //android 28px
- mH += 4;
- }
- height = height + 60;
- // height = height + 38 + 118;
- // 胶囊高度 32px 下边框6px height 状态栏高度
- this.setData({
- statusBarHeightTop: statusBarHeightTop + "px",
- statusBarHeight: height + "px",
- statusBarMH: mH + "px",
- });
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- // 页面渲染完成
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- // 页面显示时刷新数据
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- // 页面隐藏
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- // 页面卸载
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- this.loadImg();
- // 下拉刷新
- this.reloadMatchData();
- wx.stopPullDownRefresh();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- // 上拉加载更多
- console.log('加载更多赛事数据');
- if (this.data.hasMore && !this.data.isLoading) {
- this.setData({
- pageNum: this.data.pageNum + 1
- });
- this.loadMatchData();
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- },
- onPageScroll: function (e) {
- if (
- e.scrollTop >= 10 &&
- this.data.activeTitle == false
- ) {
- this.setData({
- activeTitle: true,
- });
- }
- if (
- e.scrollTop < 10 &&
- this.data.activeTitle == true
- ) {
- this.setData({
- activeTitle: false,
- });
- }
- },
- });
|