index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // pages/match/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. appAssetsUrl2: app.appAssetsUrl2,
  9. matchList: [],
  10. statusBarHeightTop: 0,
  11. statusBarHeight: 0,
  12. // 分页相关数据
  13. pageNum: 1,
  14. pageSize: 10,
  15. total: 0,
  16. hasMore: true,
  17. isLoading: false,
  18. imglist: [],
  19. current: 0,
  20. activeTitle: false,
  21. },
  22. /**
  23. * 赛事项目点击事件
  24. */
  25. onMatchItemTap(e) {
  26. const index = e.currentTarget.dataset.index;
  27. const matchItem = this.data.matchList[index];
  28. console.log('点击赛事项目:', matchItem);
  29. // 跳转到详情页面
  30. wx.navigateTo({
  31. url: `/pages/match/details/index?id=${matchItem.id}`
  32. });
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad(options) {
  38. this.height();
  39. this.loadImg();
  40. // 加载赛事数据
  41. this.loadMatchData();
  42. },
  43. changeSwiper(e) {
  44. let {
  45. current,
  46. source
  47. } = e.detail;
  48. if (source === "autoplay" || source === "touch") {
  49. this.setData({
  50. current: current,
  51. });
  52. }
  53. // this.setData({
  54. // current: e.detail.current
  55. // })
  56. },
  57. //banner跳转
  58. imgJump(v) {
  59. // console.log(v);
  60. // console.log(v.currentTarget.dataset.item.jumpAddressType);
  61. if (v.currentTarget.dataset.item.jumpAddressType == 0) {
  62. //内部跳转
  63. wx.navigateTo({
  64. url: v.currentTarget.dataset.item.linkUrl,
  65. });
  66. } else if (v.currentTarget.dataset.item.jumpAddressType == 1) {
  67. //公众号跳转 'https://www.kujiale.cn/design/3FO4EQWQJF0M/show'
  68. wx.setStorageSync("gzurl", v.currentTarget.dataset.item.linkUrl);
  69. wx.navigateTo({
  70. url: "./gz/gz",
  71. });
  72. }
  73. },
  74. // 首页banner
  75. loadImg: function () {
  76. let _this = this;
  77. let params = {
  78. type: "03",
  79. area: "",
  80. };
  81. app._post_form("img/mylist", "application/json", params, function (res) {
  82. if (res.code == 0) {
  83. _this.setData({
  84. imglist: res.data,
  85. });
  86. }
  87. });
  88. },
  89. /**
  90. * 加载赛事数据
  91. */
  92. loadMatchData() {
  93. // 如果正在加载或没有更多数据,则不执行
  94. if (this.data.isLoading || !this.data.hasMore) {
  95. return;
  96. }
  97. this.setData({
  98. isLoading: true
  99. });
  100. wx.showLoading({
  101. title: this.data.pageNum === 1 ? '加载中...' : '加载更多...'
  102. });
  103. // 调用API获取赛事数据
  104. const params = {
  105. pageNum: this.data.pageNum,
  106. pageSize: this.data.pageSize
  107. };
  108. // 使用项目中已有的请求方法
  109. app._get('news/page', params, (res) => {
  110. wx.hideLoading();
  111. this.setData({
  112. isLoading: false
  113. });
  114. if (res.code === 0) {
  115. // 处理返回的数据
  116. const newList = res.page.list || [];
  117. const total = res.page.totalPage || 0;
  118. // 如果是第一页,直接设置数据;否则追加数据
  119. const matchList = this.data.pageNum === 1 ? newList : [...this.data.matchList, ...newList];
  120. this.setData({
  121. matchList: matchList,
  122. total: total,
  123. hasMore: matchList.length < total
  124. });
  125. } else {
  126. wx.showToast({
  127. title: '数据加载失败',
  128. icon: 'none'
  129. });
  130. }
  131. }, (fail) => {
  132. wx.hideLoading();
  133. this.setData({
  134. isLoading: false
  135. });
  136. wx.showToast({
  137. title: '请求失败',
  138. icon: 'none'
  139. });
  140. });
  141. },
  142. /**
  143. * 重置并重新加载数据
  144. */
  145. reloadMatchData() {
  146. this.setData({
  147. pageNum: 1,
  148. matchList: [],
  149. hasMore: true
  150. });
  151. this.loadMatchData();
  152. },
  153. height() {
  154. const {
  155. platform,
  156. statusBarHeight
  157. } = wx.getSystemInfoSync();
  158. let statusBarHeightTop = statusBarHeight;
  159. let height = statusBarHeight + 4; //ios 24px
  160. let mH = statusBarHeight + 4;
  161. if (platform.toLowerCase() == "android") {
  162. height += 4; //android 28px
  163. mH += 4;
  164. }
  165. height = height + 60;
  166. // height = height + 38 + 118;
  167. // 胶囊高度 32px 下边框6px height 状态栏高度
  168. this.setData({
  169. statusBarHeightTop: statusBarHeightTop + "px",
  170. statusBarHeight: height + "px",
  171. statusBarMH: mH + "px",
  172. });
  173. },
  174. /**
  175. * 生命周期函数--监听页面初次渲染完成
  176. */
  177. onReady() {
  178. // 页面渲染完成
  179. },
  180. /**
  181. * 生命周期函数--监听页面显示
  182. */
  183. onShow() {
  184. // 页面显示时刷新数据
  185. },
  186. /**
  187. * 生命周期函数--监听页面隐藏
  188. */
  189. onHide() {
  190. // 页面隐藏
  191. },
  192. /**
  193. * 生命周期函数--监听页面卸载
  194. */
  195. onUnload() {
  196. // 页面卸载
  197. },
  198. /**
  199. * 页面相关事件处理函数--监听用户下拉动作
  200. */
  201. onPullDownRefresh() {
  202. this.loadImg();
  203. // 下拉刷新
  204. this.reloadMatchData();
  205. wx.stopPullDownRefresh();
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom() {
  211. // 上拉加载更多
  212. console.log('加载更多赛事数据');
  213. if (this.data.hasMore && !this.data.isLoading) {
  214. this.setData({
  215. pageNum: this.data.pageNum + 1
  216. });
  217. this.loadMatchData();
  218. }
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage() {
  224. },
  225. onPageScroll: function (e) {
  226. if (
  227. e.scrollTop >= 10 &&
  228. this.data.activeTitle == false
  229. ) {
  230. this.setData({
  231. activeTitle: true,
  232. });
  233. }
  234. if (
  235. e.scrollTop < 10 &&
  236. this.data.activeTitle == true
  237. ) {
  238. this.setData({
  239. activeTitle: false,
  240. });
  241. }
  242. },
  243. });