momo.js 3.5 KB

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