shopProds.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. },
  52. callBack: (res) => {
  53. wx.hideLoading()
  54. var shopProdList = []
  55. if (this.data.current == 1) {
  56. this.setData({
  57. shopProdList: res.records,
  58. pages: res.pages,
  59. current: res.current
  60. })
  61. } else {
  62. shopProdList = this.data.shopProdList
  63. shopProdList.push(...res.records)
  64. this.setData({
  65. shopProdList
  66. })
  67. }
  68. }
  69. }
  70. http.request(params)
  71. },
  72. // 触底加载下一页
  73. getNextPage () {
  74. if (this.data.pages > this.data.current) {
  75. this.setData({
  76. current: this.data.current + 1
  77. })
  78. this.getShopProds()
  79. } else {
  80. this.setData({
  81. isAll: true
  82. })
  83. }
  84. },
  85. // 跳转商品详情
  86. toProdPage: function (e) {
  87. var prodid = e.currentTarget.dataset.prodid;
  88. if (prodid) {
  89. wx.navigateTo({
  90. url: '/pages/prod/prod?prodid=' + prodid,
  91. })
  92. }
  93. },
  94. /**
  95. * 生命周期函数--监听页面加载
  96. */
  97. onLoad: function (options) {
  98. if (options.shopId) {
  99. this.setData({
  100. shopId: options.shopId
  101. })
  102. } else {
  103. this.setData({
  104. shopId: this.data.shopInfo.shopId
  105. })
  106. }
  107. this.setData({
  108. shopInfo: wx.getStorageSync("shopInfo")
  109. })
  110. this.getShopProds()
  111. },
  112. /**
  113. * 跳转店铺详情
  114. */
  115. toShopInfo() {
  116. wx.navigateTo({
  117. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopInfo.shopId,
  118. })
  119. },
  120. /**
  121. * 生命周期函数--监听页面初次渲染完成
  122. */
  123. onReady: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面显示
  127. */
  128. onShow: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面隐藏
  132. */
  133. onHide: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面卸载
  137. */
  138. onUnload: function () {
  139. },
  140. /**
  141. * 页面相关事件处理函数--监听用户下拉动作
  142. */
  143. onPullDownRefresh: function () {
  144. },
  145. /**
  146. * 页面上拉触底事件的处理函数
  147. */
  148. onReachBottom: function () {
  149. this.getNextPage()
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage: function () {
  155. },
  156. /**
  157. * 页面滚动事件
  158. */
  159. onPageScroll: function (e) {
  160. var _this = this
  161. if (e.scrollTop > 80) {
  162. _this.setData({
  163. topFlag: true
  164. })
  165. } else {
  166. _this.setData({
  167. topFlag: false
  168. })
  169. }
  170. }
  171. })