momo.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // newsShop/pages/patternMenu/patternMenu.js
  2. let app = getApp();
  3. let host = app.globalData.servsers; // 请求的url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. host: host,
  10. requestState: true, //检测请求状态是否结束了
  11. filterStatic: false,
  12. goodsList: [],
  13. page: 1, //默认是第一页
  14. limit: 20, //一页20条数据
  15. requestState: true, //默认是可以向下请求的
  16. loginStatic: false, //登陆状态,默认为false
  17. reachBottomState:true,//判断是否有上拉加载状态
  18. tabBar: {
  19. "color": "#2d2d2d",
  20. "selectedColor": "#e81021",
  21. "borderStyle": "white",
  22. "backgroundColor": "#fff",
  23. "list": [{
  24. "pagePath": "/pages/index/index",
  25. "iconPath": "../../images/news/home.png",
  26. "selectedIconPath": "images/news/home_select.png",
  27. "text": "首页"
  28. },
  29. {
  30. "pagePath": "/pages/kind/index",
  31. "iconPath": "../../images/news/classify.png",
  32. "selectedIconPath": "images/news/classify_select.png",
  33. "text": "分类"
  34. },
  35. {
  36. "pagePath": "/pages/car/index",
  37. "iconPath": "../../images/news/car.png",
  38. "selectedIconPath": "images/news/car_select.png",
  39. "text": "购物车"
  40. },
  41. {
  42. "pagePath": "/pages/mine/mine",
  43. "iconPath": "../../images/news/user.png",
  44. "selectedIconPath": "images/news/user_select.png",
  45. "text": "我的"
  46. }
  47. ]
  48. },
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. let that = this;
  65. that.setData({
  66. goodsList:[],
  67. page:1,
  68. reachBottomState: true,//判断是否有上拉加载状态
  69. })
  70. if (!wx.getStorageSync('channelIdObj')) { // 还没有登录过渠道
  71. wx.navigateTo({
  72. url: '/pages/login/login?url=/pages/momo/momo&&type=1&&back=2',
  73. })
  74. } else {
  75. that.getGiftList(that)
  76. }
  77. if (wx.getStorageSync('channelIdObj').channelId) {
  78. that.setData({
  79. loginStatic: true,
  80. })
  81. }
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面卸载
  90. */
  91. onUnload: function () {
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function () {
  97. let that = this;
  98. if (that.data.requestState) {
  99. that.setData({
  100. page: that.data.page + 1
  101. })
  102. that.getGiftList(that)
  103. }
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. console.log('开始上拉')
  110. let that = this;
  111. if (that.data.reachBottomState){
  112. that.setData({
  113. page: ++that.data.page
  114. })
  115. that.getGiftList(that)
  116. } else {
  117. console.log('已经到底')
  118. }
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage: function () {
  124. },
  125. getGiftList(that) {
  126. let data = {
  127. limit: that.data.limit, // 一页20条数据
  128. offset: that.data.page, //当前页数
  129. channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
  130. }
  131. wx.request({
  132. url: host + '/queryAllCommodityByChannelId',
  133. method: 'get',
  134. data: data,
  135. success(res) {
  136. let dataArray = that.data.goodsList;
  137. if (res.data.rows.length < 20){
  138. that.setData({
  139. reachBottomState:false,
  140. })
  141. }
  142. res.data.rows.forEach(el => {
  143. el.logo = el.commodity_logo.split(",")
  144. })
  145. dataArray.push(...res.data.rows)
  146. that.setData({
  147. goodsList: dataArray,
  148. requestState: res.data.rows.length == that.data.limit
  149. })
  150. }
  151. })
  152. },
  153. toGoodsDetail(e) { // 进入商品详情页
  154. let that = this,
  155. id = e.currentTarget.dataset.id;
  156. wx.navigateTo({
  157. url: '/pages/buy/buy?com_id=' + id,
  158. })
  159. }
  160. })