momo.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. })
  68. if (!wx.getStorageSync('channelIdObj')) { // 还没有登录过渠道
  69. wx.navigateTo({
  70. url: '/pages/login/login?url=/pages/momo/momo&&type=1&&back=2',
  71. })
  72. } else {
  73. that.getGiftList(that)
  74. }
  75. if (wx.getStorageSync('channelIdObj').channelId) {
  76. that.setData({
  77. loginStatic: true,
  78. })
  79. }
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. let that = this;
  96. if (that.data.requestState) {
  97. that.setData({
  98. page: that.data.page + 1
  99. })
  100. that.getGiftList(that)
  101. }
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom: function () {
  107. console.log('开始上拉')
  108. let that = this;
  109. if (that.data.reachBottomState){
  110. that.setData({
  111. page: ++that.data.page
  112. })
  113. that.getGiftList(that)
  114. } else {
  115. console.log('已经到底')
  116. }
  117. },
  118. /**
  119. * 用户点击右上角分享
  120. */
  121. onShareAppMessage: function () {
  122. },
  123. getGiftList(that) {
  124. let data = {
  125. limit: that.data.limit, // 一页20条数据
  126. offset: that.data.page, //当前页数
  127. channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
  128. }
  129. wx.request({
  130. url: host + '/queryAllCommodityByChannelId',
  131. method: 'get',
  132. data: data,
  133. success(res) {
  134. let dataArray = that.data.goodsList;
  135. if (res.data.rows.length < 20){
  136. that.setData({
  137. reachBottomState:false,
  138. })
  139. }
  140. res.data.rows.forEach(el => {
  141. el.logo = el.commodity_logo.split(",")
  142. })
  143. dataArray.push(...res.data.rows)
  144. that.setData({
  145. goodsList: dataArray,
  146. requestState: res.data.rows.length == that.data.limit
  147. })
  148. }
  149. })
  150. },
  151. toGoodsDetail(e) { // 进入商品详情页
  152. let that = this,
  153. id = e.currentTarget.dataset.id;
  154. wx.navigateTo({
  155. url: '/pages/buy/buy?com_id=' + id,
  156. })
  157. }
  158. })