momo.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. this.getGiftList(this)
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady: function () {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: function () {
  33. let that = this;
  34. if (wx.getStorageSync('channelIdObj').channelId) {
  35. that.setData({
  36. loginStatic: true,
  37. })
  38. }
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload: function () {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh: function () {
  54. let that = this;
  55. if (that.data.requestState) {
  56. that.setData({
  57. page: that.data.page + 1
  58. })
  59. that.getGiftList(that)
  60. }
  61. },
  62. /**
  63. * 页面上拉触底事件的处理函数
  64. */
  65. onReachBottom: function () {
  66. },
  67. /**
  68. * 用户点击右上角分享
  69. */
  70. onShareAppMessage: function () {
  71. },
  72. getGiftList(that) {
  73. let data = {
  74. limit: that.data.limit, // 一页20条数据
  75. offset: that.data.page, //当前页数
  76. channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
  77. }
  78. wx.request({
  79. url: host + '/queryAllCommodityByChannelId',
  80. method: 'get',
  81. data: data,
  82. success(res) {
  83. let dataArray = that.data.goodsList;
  84. res.data.rows.forEach(el => {
  85. el.logo = el.commodity_logo.split(",")
  86. })
  87. dataArray.push(...res.data.rows)
  88. that.setData({
  89. goodsList: dataArray,
  90. requestState: res.data.rows.length == that.data.limit
  91. })
  92. }
  93. })
  94. },
  95. toGoodsDetail(e) { // 进入商品详情页
  96. let that = this, id = e.currentTarget.dataset.id;
  97. wx.navigateTo({
  98. url: '/pages/buy/buy?com_id=' + id,
  99. })
  100. }
  101. })