momo.js 3.5 KB

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