shopProds.js 3.4 KB

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