momo.js 3.4 KB

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