shopProds.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // pages/allGoods/allGoods.js
  2. var http = require('../../utils/http.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. topFlag: false,
  9. shopInfo: {},
  10. shopProdList: [],
  11. shopId: 0,
  12. sort: 0,
  13. current: 1, // 当前页
  14. pages: 0, // 总页码
  15. isAll: false,
  16. currentTab: true
  17. },
  18. /**
  19. * tab栏切换
  20. */
  21. onStsTap: function (e) {
  22. var sort = e.currentTarget.dataset.sort;
  23. this.setData({
  24. sort: sort,
  25. currentTab: false,
  26. current: 1,
  27. isAll: false
  28. });
  29. this.getShopProds()
  30. },
  31. /**
  32. * 跳转搜索页
  33. */
  34. toShopSearchPage: function (e) {
  35. const shopId = e.currentTarget.dataset.shopid
  36. wx.navigateTo({
  37. url: '/pages/shopSearch/shopSearch?shopId=' + shopId,
  38. })
  39. },
  40. // 获取店铺商品
  41. getShopProds () {
  42. wx.showLoading()
  43. var params = {
  44. url: '/search/searchProdPage',
  45. method: 'GET',
  46. data: {
  47. shopId: this.data.shopInfo.shopId,
  48. sort: this.data.sort,
  49. current: this.data.current,
  50. isAllProdType: true,
  51. channelId:wx.getStorageSync('channelId'),
  52. platform:1
  53. },
  54. callBack: (res) => {
  55. wx.hideLoading()
  56. var shopProdList = []
  57. if (this.data.current == 1) {
  58. this.setData({
  59. shopProdList: res.records,
  60. pages: res.pages,
  61. current: res.current
  62. })
  63. } else {
  64. shopProdList = this.data.shopProdList
  65. shopProdList.push(...res.records)
  66. this.setData({
  67. shopProdList
  68. })
  69. }
  70. }
  71. }
  72. http.request(params)
  73. },
  74. // 触底加载下一页
  75. getNextPage () {
  76. if (this.data.pages > this.data.current) {
  77. this.setData({
  78. current: this.data.current + 1
  79. })
  80. this.getShopProds()
  81. } else {
  82. this.setData({
  83. isAll: true
  84. })
  85. }
  86. },
  87. // 跳转商品详情
  88. toProdPage: function (e) {
  89. var prodid = e.currentTarget.dataset.prodid;
  90. if (prodid) {
  91. wx.navigateTo({
  92. url: '/pages/prod/prod?prodid=' + prodid,
  93. })
  94. }
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. onLoad: function (options) {
  100. if (options.shopId) {
  101. this.setData({
  102. shopId: options.shopId
  103. })
  104. } else {
  105. this.setData({
  106. shopId: this.data.shopInfo.shopId
  107. })
  108. }
  109. this.setData({
  110. shopInfo: wx.getStorageSync("shopInfo")
  111. })
  112. this.getShopProds()
  113. },
  114. /**
  115. * 跳转店铺详情
  116. */
  117. toShopInfo() {
  118. wx.navigateTo({
  119. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopInfo.shopId,
  120. })
  121. },
  122. /**
  123. * 生命周期函数--监听页面初次渲染完成
  124. */
  125. onReady: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面显示
  129. */
  130. onShow: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面隐藏
  134. */
  135. onHide: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面卸载
  139. */
  140. onUnload: function () {
  141. },
  142. /**
  143. * 页面相关事件处理函数--监听用户下拉动作
  144. */
  145. onPullDownRefresh: function () {
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. onReachBottom: function () {
  151. this.getNextPage()
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage: function () {
  157. },
  158. /**
  159. * 页面滚动事件
  160. */
  161. onPageScroll: function (e) {
  162. var _this = this
  163. if (e.scrollTop > 80) {
  164. _this.setData({
  165. topFlag: true
  166. })
  167. } else {
  168. _this.setData({
  169. topFlag: false
  170. })
  171. }
  172. }
  173. })