momo.js 3.6 KB

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