index.js 5.6 KB

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