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. {
  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. this.getGiftList(this)
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow: function () {
  65. let that = this;
  66. if (!wx.getStorageSync('channelIdObj')) { // 还没有登录过渠道
  67. wx.navigateTo({
  68. url: '/pages/login/login?url=/pages/momo/momo && type =1',
  69. })
  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, id = e.currentTarget.dataset.id;
  134. wx.navigateTo({
  135. url: '/pages/buy/buy?com_id=' + id,
  136. })
  137. }
  138. })